News:

;) This forum is the property of Proton software developers

Main Menu

Count 0-1024

Started by JackB, Today at 02:07 PM

Previous topic - Next topic

JackB

a simple  For To  Next

this topic is address to Les, this is a very basic function
the code reset the counter to '0' when it's not suppose to
I hope Les can find out the problem.


Device = 18F25K22             
Declare Xtal = 64

Config_Start
  FOSC = INTIO7                 
  PLLCFG = On                   
  MCLRE = INTMCLR
  LVP = OFF                     
Config_End

TRISA = %00000000               
TRISB = %11111111               
TRISC = %00000000               
TRISE = %00000000
ANSELA = 0                     
ANSELB = 0                     
ANSELC = 0                     
OSCCON  = %01110000  '$70       
OSCTUNE = %01000000  '$40       

' var setup
Dim I As Word

PORTA.0 = 1
DelayMS 10                   

For I = 0 To 1023
 SerOut PORTA.0,84,[" I    : ",Dec I,13,10]
 DelayMS 200
Next I

End





Pepe

#1
disable watchdog

;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

Device = 18F25K22

Config_Start
  FOSC = INTIO67    ;Internal oscillator block
  PLLCFG = On    ;Oscillator multiplied by 4
  PRICLKEN = On    ;Primary clock enabled
  FCMEN = OFF    ;Fail-Safe Clock Monitor disabled
  IESO = OFF    ;Oscillator Switchover mode disabled
  PWRTEN = OFF    ;Power up timer disabled
  BOREN = SBORDIS    ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
  BORV = 190    ;VBOR set to 1.90 V nominal
  WDTEN = OFF    ;Watch dog timer is always disabled. SWDTEN has no effect.
  WDTPS = 32768    ;1:32768
  CCP2MX = PORTC1    ;CCP2 input/output is multiplexed with RC1
  PBADEN = OFF    ;PORTB<5:0> pins are configured as digital I/O on Reset
  CCP3MX = PORTB5    ;P3A/CCP3 input/output is multiplexed with RB5
  HFOFST = On    ;HFINTOSC output and ready status are not delayed by the oscillator stable status
  T3CMX = PORTC0    ;T3CKI is on RC0
  P2BMX = PORTB5    ;P2B is on RB5
  MCLRE = INTMCLR    ;RE3 input pin enabled; MCLR disabled
  STVREN = OFF    ;Stack full/underflow will not cause Reset
  LVP = OFF    ;Single-Supply ICSP disabled
  XINST = OFF    ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
  Debug = OFF    ;Disabled
  Cp0 = OFF    ;Block 0 (000800-001FFFh) not code-protected
  CP1 = OFF    ;Block 1 (002000-003FFFh) not code-protected
  CP2 = OFF    ;Block 2 (004000-005FFFh) not code-protected
  CP3 = OFF    ;Block 3 (006000-007FFFh) not code-protected
  CPB = OFF    ;Boot block (000000-0007FFh) not code-protected
  CPD = OFF    ;Data EEPROM not code-protected
  WRT0 = OFF    ;Block 0 (000800-001FFFh) not write-protected
  WRT1 = OFF    ;Block 1 (002000-003FFFh) not write-protected
  WRT2 = OFF    ;Block 2 (004000-005FFFh) not write-protected
  WRT3 = OFF    ;Block 3 (006000-007FFFh) not write-protected
  WRTC = OFF    ;Configuration registers (300000-3000FFh) not write-protected
  WRTB = OFF    ;Boot Block (000000-0007FFh) not write-protected
  WRTD = OFF    ;Data EEPROM not write-protected
  EBTR0 = OFF    ;Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
  EBTR1 = OFF    ;Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
  EBTR2 = OFF    ;Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
  EBTR3 = OFF    ;Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
  EBTRB = OFF    ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------

top204

#2
Your code listing is not setting all the config fuses, and as Pepe stated, the watchdog is enabled by default on the devices.

Hence the resets, because the compiler has not been told the watchdog is enabled, so it is not issuing any extra ClrWdt mnemonics in its library routines.

Always, and I repeat... 'Always' set 'all' the config fuses for a device, because the microchip defaults are sometimes not what is expected.

If the watchdog timer has been enabled in a program, tell the compiler by using: Declare WatchDog = On

Below, is a code listing of your code, but written in my format:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Transmit a decimal ASCII value of a 16-bit Word variable, to a serial terminal.
'
' Written for the Positron8 BASIC compiler by Les Johnson.
'
    Device = 18F25K22                                                   ' Tell the compiler what device to compile for
    Declare Xtal = 64                                                   ' Tell the compiler what frequency the device is operating at (in MHz)
'
' Create any global variables, aliases, or constants here

    Dim I As Word

'--------------------------------------------------------------------------
' The main program starts here
' Transmit a decimal ASCII value of a 16-bit Word variable, to a serial terminal.
'
Main:
    Setup()                                                             ' Setup the program and any peripherals
   
    For I = 0 To 1023
        SerOut PORTC.6, 84, [" I    : ", Dec I, 13]
        DelayMS 200
    Next I

'----------------------------------------------------------------------------
' Setup the program and any peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    Osc_64MHz()                                                         ' Set the device to 64MHz operation using its internal oscillator
'
' More setup code here
'
EndProc

'---------------------------------------------------------------------------------------------
' Set the PIC18F25K22 device to 64MHz operation using its internal oscillator
' Input     : None
' Output    : None
' Notes     : None
'
Proc Osc_64MHz()
    OSCCON  = $70
    OSCCON2 = $04
    OSCTUNE = $40
    DelayMS 10                                                          ' A small delay to allow the oscillator to stabilise
EndProc

'---------------------------------------------------------------------------------------------
' Setup the config fuses to use the internal oscillator on a PIC18F25K22 device.
' OSC pins RA6 and RA7 are general purpose I/O.
'
Config_Start
    FOSC     = INTIO67                                                  ' Internal oscillator
    PRICLKEN = Off                                                      ' Primary clock disabled
    MCLRE    = EXTMCLR                                                  ' MCLR pin enabled
    WDTEN    = Off                                                      ' Watchdog Timer disabled
    PLLCFG   = Off                                                      ' Oscillator used directly
    FCMEN    = Off                                                      ' Fail-Safe Clock Monitor disabled
    IESO     = Off                                                      ' Oscillator Switchover mode disabled
    PWRTEN   = On                                                       ' Power up timer enabled
    BOREN    = Off                                                      ' Brown-out Reset disabled
    BORV     = 190                                                      ' VBOR set to 1.9 V nominal
    WDTPS    = 128                                                      ' Watchdog Timer Postscale is 1:128
    HFOFST   = Off                                                      ' The Access clock is not held Off until the HF-INTOSC is stable
    PBADEN   = Off                                                      ' PORTB<4:0> pins are configured as digital on reset
    CCP2MX   = PORTC1                                                   ' CCP2 input/output is multiplexed with RC1
    CCP3MX   = PORTB5                                                   ' P3A/CCP3 input/output is multiplexed with RB5
    T3CMX    = PORTC0                                                   ' T3CKI is on RC0
    P2BMX    = PORTB5                                                   ' P2B is on RB5
    STVREN   = On                                                       ' Stack full/underflow will cause a reset
    LVP      = Off                                                      ' Single-Supply ICSP disabled
    Debug    = Off                                                      ' Background debugger disabled. RB6 and RB7 configured as general purpose I/O pins
    XINST    = Off                                                      ' Extra mnemonics disabled
    Cp0      = Off                                                      ' Block 0 (000800-001FFF) not code protected
    CP1      = Off                                                      ' Block 1 (002000-003FFF) not code protected
    CPB      = Off                                                      ' Boot block (000000-0007FF) not code protected
    CPD      = Off                                                      ' Data EEPROM not code protected
    WRT0     = Off                                                      ' Block 0 (000800-001FFF) not write protected
    WRT1     = Off                                                      ' Block 1 (002000-003FFF) not write protected
    WRTB     = Off                                                      ' Boot block (000000-0007FF) not write protected
    WRTC     = On                                                       ' Configuration registers (300000-3000FF) write protected
    WRTD     = Off                                                      ' Data EEPROM not write protected
    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
    EBTRB    = Off                                                      ' Boot block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End

And below, is the program operating in the proteus simulator, and I have also tested it on a real device:

Screenshot_of_TX.jpg

Regards
Les

JackB

Many thanks Pepe  (sorry for FIFA) also to Les.