PDA

View Full Version : Timer Issues



Kamikaze47
- 7th September 2007, 13:10
Correct me if i'm wrong, but I should be able to set the value of TMR0L and TMR0H to whatever I like yes?

If I do this as a test:


DEFINE OSC 48

T0CON=%10010110

TMR0L=0
TMR0H=0

pause 200

result.LowByte=TMR0L
result.HighByte=TMR0H

The result varies every time i do it. As if reseting TMR0L and TMR0H is doing nothing.

However if I do this:



DEFINE OSC 48

T0CON=%10010110

result1.LowByte=TMR0L
result1.HighByte=TMR0H

pause 200

result2.LowByte=TMR0L
result2.HighByte=TMR0H

result=result2-result1

The result is correct every time.

Does anyone know why?

sayzer
- 7th September 2007, 13:32
TMR0 is 8-bit.

Which PIC is it?


-------------------------------

Kamikaze47
- 7th September 2007, 13:35
Nope. Got TMR0 set to 16-bit.

18F4550

I've updated the code in the 1st post with the TMR0 settings

Acetronics2
- 7th September 2007, 14:05
Timer config is 16 bits ...

Why not write Highbyte first ... as datasheet explains ...


" Similarly, a write to the high byte of Timer0 must also
take place through the TMR0H Buffer register. The high
byte is updated with the contents of TMR0H when a
write occurs to TMR0L. This allows all 16 bits of Timer0
to be updated at once."

Alain

Kamikaze47
- 7th September 2007, 15:05
That did the trick.

Thanks Acetronics.