Hot!PIC16F628A Timer0 doesn't seem to be working with the larger prescaler values

Author
beetwave
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2017/08/10 10:35:17
  • Location: 0
  • Status: offline
2018/10/26 15:18:58 (permalink)
0

PIC16F628A Timer0 doesn't seem to be working with the larger prescaler values

 
 __config 0x3ffc
 
TRISIO equ 0x85
GPIO equ 0x05
STATUS equ 0x03
OPTIONREG equ 0x81
INTCON equ 0x0b
TMR0 equ 0x01

     org 0x0000

setup
     clrwdt
     bsf STATUS, 5                            ;Select bank 1
     bcf TRISIO, 0                            ;Configure RA0 as output
     movlw 0xd4
     movwf OPTIONREG                          ;Select TMR0, prescaler value and clock source
     bcf STATUS, 5                            ;Select bank 0
loop
     bsf GPIO, 0                             ;Turn led on
     call delay                              ;Timer delay
     bcf GPIO, 0                             ;Turn led off
     call delay                              ;Timer delay
     goto loop

delay
     clrf TMR0                               ;Reset TMR0 register
check
     btfss INTCON, 2                         ;Check whether TMR0 overflow has occured.
     goto check
     bcf INTCON, 2                           ;Clear TMR0 overflow bit
     return
 end

I've just started to learn how to use this timer as a delay for a flashing led. It works as I expect it to until the prescaler rate is 64 or higher. With the prescaler rate that high, I found with a simple frequency counter that the output pin stops oscillating, in fact, I replaced the code where I turn the led off and found the code doesn't get out of the 'check' loop. I apologise if the code is formatted correctly, I can't quite find the option for assembly code.
#1

2 Replies Related Threads

    qhb
    Superb Member
    • Total Posts : 9621
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC16F628A Timer0 doesn't seem to be working with the larger prescaler values 2018/10/26 15:43:25 (permalink)
    +1 (1)
    I would strongly recommend you change this
    __config 0x3ffc

    to
        #include <p16F628A.inc>       ; processor specific variable definitions
        __CONFIG   _CP_OFF & _DATA_CP_OFF & _LVP_ON & _BOREN_ON & _MCLRE_ON & _WDT_ON & _PWRTE_OFF & _INTOSC_OSC_NOCLKOUT

    then you can see what you are doing.

    Then, I would change the _WDT_ON setting to _WDT_OFF as your problem is that the Watchdog Timer is triggering.
    At the same time, I would change _LVP_ON to _LVP_OFF so you can use RB4/PGM as a GPIO pin,
    and change _PWRTE_OFF to _PWRTE_ON to be sure power is stable before your code starts running.

    Also note, once you #include p16F628A.inc, you won't need these lines any more.
    TRISIO equ 0x85
    GPIO equ 0x05
    STATUS equ 0x03
    OPTIONREG equ 0x81
    INTCON equ 0x0b
    TMR0 equ 0x01

     
    #2
    qhb
    Superb Member
    • Total Posts : 9621
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC16F628A Timer0 doesn't seem to be working with the larger prescaler values 2018/10/26 15:50:29 (permalink)
    +1 (1)
    I note you had a CLRWDT instruction at the start of your code.
    That is pointless, you have to execute that instruction at regular intervals if the WDT is enabled, not just once.
    Better to just leave the WDT off until you have an actual need for it.
     
     
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5