How Do I clear Timers

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
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
 

BMorse

Joined Sep 26, 2009
2,675
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 :

When writing to TMR0, two instruction clock cycles are lost. Often you have a specific time
period you want to count, say 100 decimal. In that case you might put 156 into TMR0
(256 - 100 = 156). However, since two instruction cycles are lost when you write to TMR0
(for internal logic synchronization), you should actually write 158 to the timer.
 

eblc1388

Joined Nov 28, 2008
1,542
I like to know how to clear the three timers used in the 16F88, at any time as the program counter in running.
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.
 

Thread Starter

R!f@@

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

Rifaa
 

BMorse

Joined Sep 26, 2009
2,675
There is no difference except the first takes one extra instruction. Both will clear TMR0 and the counts inside the prescaler.

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.
 

Tahmid

Joined Jul 2, 2008
343
Hi,
For 8-bit timers, you can do like:
Assembler:
Rich (BB code):
CLRF   TMR0
CLRF   TMR2
C:
Rich (BB code):
TMR0 = 0;
TMR2 = 0;
BASIC:
Rich (BB code):
TMR0 = 0
TMR2 = 0
For 16-bit timers, you need to clear both high and low registers, like:
Assembler:
Rich (BB code):
CLRF   TMR1H
CLRF   TMR1L
C:
Rich (BB code):
TMR1H = 0;
TMR1L = 0;
BASIC:
Rich (BB code):
TMR1L = 0
TMR1L = 0
Hope this helps.
Tahmid.
 
Top