How Do I clear Timers

Discussion in 'Programmer's Corner' started by R!f@@, Feb 11, 2010.

  1. R!f@@

    Thread Starter AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    I did a bit of searching and I end up with zip.
    I like to know how to clear the three timers used in the 16F88, at any time as the program counter in running.
    Say I want to reset TMR2 before a certain function.
    I cannot seem to find a command that would do this.
    Any Ideas any one

    Rifaa
     
  2. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    You should be able to just write the value you want to the timer register

    Ex:
    MOVLW 0
    MOVWF TMR0 //assigns the value of W to TMR0

    Or:

    CLRF TMR0 //Clears timer and prescaler


    You just have to remember this when writing new values to timer registers :

     
  3. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    User can access the timer via a memory register.

    For Timer0 and 2, that's TMR0 and TMR2. To reset/clear the timer value to zero, simply use the PIC instruct CLRF TMR0 and CLRF TMR2.

    For timer1, it is a little bit tricky as it is a 16-bit timer. The timer lower 8-bit might rollover to the higher 8-bit while we carrying out the operation.

    Of course user can stop the timer first.

    If the timer is running, the correct way is to clear the lower 8-bit first and then clear the higher 8-bit.
     
  4. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    There is no difference except the first takes one extra instruction. Both will clear TMR0 and the counts inside the prescaler.
     
  5. R!f@@

    Thread Starter AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    Thanks guy.
    I did use the clrf but the watch window did no show a reset.
    I will give it a go again.

    Rifaa
     
  6. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234

    I know that, I was just showing the op a couple of ways to do it.... but with the MOVLW, the op can assign any value besides 0, to the TMR register, CLRF only clears it.
     
  7. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    Hi,
    For 8-bit timers, you can do like:
    Assembler:
    Code ( (Unknown Language)):
    1. CLRF   TMR0
    2. CLRF   TMR2
    C:
    Code ( (Unknown Language)):
    1. TMR0 = 0;
    2. TMR2 = 0;
    BASIC:
    Code ( (Unknown Language)):
    1. TMR0 = 0
    2. TMR2 = 0
    For 16-bit timers, you need to clear both high and low registers, like:
    Assembler:
    Code ( (Unknown Language)):
    1. CLRF   TMR1H
    2. CLRF   TMR1L
    C:
    Code ( (Unknown Language)):
    1. TMR1H = 0;
    2. TMR1L = 0;
    BASIC:
    Code ( (Unknown Language)):
    1. TMR1L = 0
    2. TMR1L = 0
    Hope this helps.
    Tahmid.
     
Loading...