News:

Let's find out together what makes a PIC Tick!

Main Menu

47Q10 Delayus 15 is ok but 16us not ok V4.0.1.7 - 1.1.0.8

Started by okaman, Apr 21, 2022, 01:31 PM

Previous topic - Next topic

okaman

hi guys ,
it is interseting have a problem

Positron Corrections Update 4.0.1.7 - 1.1.0.8

i am trying some codes for 47Q10 and can try proteus v14

if i write the line 151 ad 153 15us has no problem i can see pulsess

but if i write 16us and more has problem ...no pulses..

MAIN:

    PORTA = 1
    DelayUS 20
    PORTA = 0
    DelayUS 20

GoTo MAIN
End


47Q10 new for me where i am making wrong ?
can any one help me ?

Device 18F47Q10

Config_Start
    FCMEN = On              'Fail-Safe Clock Monitor Enable bit->Fail-Safe Clock Monitor enable
    CSWEN = On              'Clock Switch Enable bit->Writing To NOSC And NDIV is allowed
    CLKOUTEN = OFF          ' Clock Out Enable bit->CLKOUT function is disabled
    RSTOSC = HFINTOSC_64MHZ 'Power-up default value For COSC bits->HFINTOSC with HFFRQ = 64 MHz And CDIV = 1:1
    FEXTOSC = LP            'External Oscillator mode Selection bits->LP (crystal oscillator) optimized For 32.768 kHz; PFM set to low power
   
    BOREN = OFF            'Brown-out Reset Enable bits->Brown-out Reset disabled
    LPBOREN = OFF          'Low-power BOR Enable bit->Low power BOR is disabled
    PWRTE = OFF            'Power-up Timer Enable bit->Power up timer disabled
    MCLRE = INTMCLR        'Master Clear Enable bit->If LVP = 0, MCLR Pin (RE3) is an Input; If LVP =1, MCLR pin (RE3) is MCLR
   
    XINST = OFF            'Extended Instruction Set Enable bit->Extended Instruction Set And Indexed Addressing Mode disabled
    STVREN = On            'Stack Full/Underflow Reset Enable bit->Stack full/underflow will cause Reset
    PPS1WAY = On            'PPSLOCK Bit One-Way Set Enable bit->PPSLOCK Bit can be cleared And Set only once; PPS registers remain locked after one clear/set cycle
    ZCD = OFF              'ZCD Disable bit->ZCD disabled. ZCD can be enabled by setting the ZCDSEN Bit of ZCDCON
    BORV = VBOR_190        'Brown Out Reset Voltage selection bits->Brown-out Reset Voltage (VBOR) Set To 1.90V
   
    WDTE = OFF              'WDT operating mode->WDT Disabled
    WDTCPS = WDTCPS_31      'WDT Period Select bits->Divider ratio 1:65536; software control of WDTPS
   
    WDTCCS = SC            'WDT Input clock selector->Software Control   
    WDTCWS = WDTCWS_7      'WDT Window Select bits->window always open (100%); software control; keyed access not required

   

      WRT0 = OFF            'Write Protection Block 0->Block 0 (000800-001FFFh) not write-protected
      WRT1 = OFF            'Write Protection Block 1->Block 1 (002000-003FFFh) not write-protected
      WRT2 = OFF            'Write Protection Block 1->Block 2 (004000-005FFFh) not write-protected
      WRT3 = OFF            'Write Protection Block 1->Block 3 (006000-007FFFh) not write-protected
   
      WRTC = OFF            'Configuration Register Write Protection bit->Configuration registers (300000-30000Bh) not write-protected
      WRTB = OFF            'Boot Block Write Protection bit->Boot Block (000000-0007FFh) not write-protected
      WRTD = OFF            'Data EEPROM Write Protection bit->Data EEPROM not write-protected
      SCANE = On            'Scanner Enable bit->Scanner module is available For use, SCANMD Bit can control the module
      LVP = OFF            'Low Voltage Programming Enable bit->HV On MCLR/VPP must be used For programming
   

      Cp = OFF              'UserNVM Program Memory Code Protection bit->UserNVM Code protection disabled
      CPD = OFF            'DataNVM Memory Code Protection bit->DataNVM Code protection disabled
   
      EBTR0 = OFF          'Table Read Protection Block 0->Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
      EBTR1 = OFF          'Table Read Protection Block 1->Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
      EBTR2 = OFF          'Table Read Protection Block 1->Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
      EBTR3 = OFF          'Table Read Protection Block 1->Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
      EBTRB = OFF          'Boot Block Table Read Protection bit->Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End

Declare Xtal = 64
'**********************************************************
    'CLKRMD CLKR disabled; SYSCMD SYSCLK enabled; SCANMD SCANNER disabled; FVRMD FVR disabled; IOCMD IOC disabled; CRCMD CRC disabled; HLVDMD HLVD disabled; NVMMD NVM disabled
    PMD0 = $7F
    'TMR0MD TMR0 disabled; TMR1MD TMR1 disabled; TMR4MD TMR4 disabled; TMR5MD TMR5 disabled; TMR2MD TMR2 disabled; TMR3MD TMR3 disabled; TMR6MD TMR6 disabled;
    PMD1 = $7F
    'ZCDMD ZCD disabled; DACMD DAC disabled; CMP1MD CMP1 disabled; ADCMD ADC disabled; CMP2MD CMP2 disabled;
    PMD2 = $67
    'CCP2MD CCP2 disabled; CLC5MD CLC5 disabled; CCP1MD CCP1 disabled; CLC6MD CLC6 disabled; PWM4MD PWM4 disabled; PWM3MD PWM3 disabled; CLC7MD CLC7 disabled; CLC8MD CLC8 disabled;
    PMD3 = $FF
    'CWG1MD CWG1 disabled; UART2MD EUSART2 disabled; MSSP1MD MSSP1 disabled; UART1MD EUSART enabled; MSSP2MD MSSP2 disabled;
    PMD4 = $B1
    'DSMMD DSM disabled; CLC3MD CLC3 disabled; CLC4MD CLC4 disabled; CLC1MD CLC1 disabled; CLC2MD CLC2 disabled;
    PMD5 = $F1
'**********************************************************
    LATE = 0
    LATD = 0
    LATA = 0
    LATB = 0
    LATC = 0

    TRISE = 0
    TRISA = 0
    TRISB = 0
    TRISC = 0
    TRISD = 0

    ANSELD = 0
    ANSELC = 0
    ANSELB = 0
    ANSELE = 0
    ANSELA = 0


    WPUD = 0
    WPUE = 0
    WPUB = 0
    WPUA = 0
    WPUC = 0


    ODCONE = 0
    ODCONA = 0
    ODCONB = 0
    ODCONC = 0
    ODCOND = 0


    SLRCONA = $FF
    SLRCONB = $FF
    SLRCONC = $FF
    SLRCOND = $FF
    SLRCONE = $07

    INLVLA = 0
    INLVLB = 0
    INLVLC = 0
    INLVLD = 0
    INLVLE = 0
'    RX1PPS = $17        'RC7->EUSART1:RX1;   
'    RC6PPS = $09        'RC6->EUSART1:TX1;   
'**********************************************************
    OSCCON1 = $60
    OSCCON3 = 0
    OSCEN = $F4
    OSCFRQ = $08
    OSCTUNE = 0
'**********************************************************   

'**********************************************************
'TRISE = 0
'TRISA = 0
'TRISB = 0
'TRISC = 0
'TRISD = 0

'ANSELD = 0
'ANSELC = 0
'ANSELB = 0
'ANSELE = 0
'ANSELA = 0

'PORTA = 0
'PORTB = 0
'PORTC = 0
'PORTD = 0
'PORTE = 0
MAIN:

    PORTA = 1
    DelayUS 20
    PORTA = 0
    DelayUS 20

GoTo MAIN
End
DWIN Sale Manager TURKEY
(info@kamantek.com)
http://www.kamantek.com/shop/index.php

top204

I have also tried Proteus version 8.14 and it is riddled with anomalies. Even the simplest of code does not run on a simulated 18FxxQ10 device within it. As I always say, and always will... "Never Trust a Simulator 100%"!

I created a simple program on a "real" 18FxxQ10 device and everything works as it should. I notice by your code, you have copied and translated the initialisation code from the MPLABX to Positron. Again, be very careful because the Microchip libraries are full of anomalies and create code that is so bloated and unrequired, it is scary to look at assembler code created by their C compilers. :-)

Here is the simple code I wrote for the test, and it has all the setups required for that device. i.e. None, because the compiler sets them up for you in the device's .def file, and it uses the minimum required. :-) The Delay commands assembler codes are the same for all 18F devices, so if it works on one of them, it will work on all of them (in the real world).

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' A simple test of the DelayUs command, by toggling a pin
'
    Device = 18F47Q10
    Declare Xtal = 64

'-------------------------------------------------------------------------------------
' The main program starts here
' Toggle a pin with a small delay between the highs and lows
'
Main:
    PinLow PORTB.0                      ' Setup the pin as an output low
    Do                                  ' Create a loop
        PinSet PORTB.0                  ' Set the pin high
        DelayUS 16                      ' A tiny delay to test the DelayUs command
        PinClear PORTB.0                ' Pull the pin low
        DelayUS 16                      ' A tiny delay to test the DelayUs command
    Loop                                ' Do it forever

'-------------------------------------------------------------------------------------
' Setup the config fuses to use the internal oscillator at 64MHz on a PIC18FXXQ10 device
'
Config_Start
    FEXTOSC = Off                       ' Oscillator not enabled
    RSTOSC = HFINTOSC_64MHZ             ' HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
    MCLRE = INTMCLR                     ' If LVP = 0, MCLR pin (RE3) is an input. If LVP =1, MCLR pin (RE3) is MCLR
    WDTE = Off                          ' WDT Disabled
    CLKOUTEN = Off                      ' CLKOUT function is disabled
    CSWEN = Off                         ' The NOSC and NDIV Bits cannot be changed by user software
    FCMEN = Off                         ' Fail-Safe Clock Monitor disabled  
    PWRTE = Off                         ' Power up timer disabled
    LPBOREN = Off                       ' Low power BOR is disabled
    BOREN = Off                         ' Brown-out Reset disabled
    ZCD = Off                           ' ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
    PPS1WAY = Off                       ' PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
    STVREN = Off                        ' Stack full/underflow will not cause Reset
    XINST = Off                         ' Extended Instruction Set and Indexed Addressing Mode disabled
    WDTCCS = SC                         ' Software Control
    WRT0 = Off                          ' Block 0 (000800-001FFF) not write-protected
    WRT1 = Off                          ' Block 1 (002000-003FFF) not write-protected
    WRT2 = Off                          ' Block 2 (004000-005FFF) not write-protected
    WRT3 = Off                          ' Block 3 (006000-007FFF) not write-protected
    WRTC = Off                          ' Configuration registers (300000-30000B) not write-protected
    WRTB = Off                          ' Boot Block (000000-0007FF) not write-protected
    WRTD = Off                          ' Data EEPROM not write-protected
    SCANE = Off                         ' Scanner module is NOT available for use, SCANMD bit is ignored
    LVP = Off                           ' HV on MCLR/VPP must be used for programming
    Cp = Off                            ' User NVM code protection disabled
    CPD = Off                           ' Data NVM code protection disabled
    EBTR0 = Off                         ' Block 0 (000800-001FFF) not protected from table reads executed in other blocks
    EBTR1 = Off                         ' Block 1 (002000-003FFF) not protected from table reads executed in other blocks
    EBTR2 = Off                         ' Block 2 (004000-005FFF) not protected from table reads executed in other blocks
    EBTR3 = Off                         ' Block 3 (006000-007FFF) not protected from table reads executed in other blocks
    EBTRB = Off                         ' Boot Block (000000-0007FF) not protected from table reads executed in other blocks
Config_End

And below is an image of the pin pulsing with the 16 microsecond delays between them. You can tell it is 16us by looking at the grids in the scope that are set to 10us, and the square waves are at a position within them of 16us:

SquareWave.jpg

TimB


In case its of interest Labcenter has updated the code for the device and its better in that some interrupt issues are fixed and a fuse setting.

However there is still and issue with delays

Delayms 1000 takes 1us But Delayms 254 is about right

No idea why

Tim