Calculations for Timer1 on 18f (16 bit timer)

Status
Not open for further replies.

M3GAPL3X

Junior Member level 3
timer1 on

Hi guys,

I am thinking about using the low power, 31 kHz internal oscillator for my main oscillator in my code.

I will be using Timer1 to wake the PIC up from sleep ever x milliseconds.

The question I have is, what should the TMR1H and TMR1L values be so that an interrupt occurs every , say 10 ms?

Any hints would be appreciated.

Kurenai_ryu

18fxxx tmr1

dude! first you must check the exact timer oscillator period... also check if the timer clock with this internal oscillator would be working while the device is sleeping... then...

T_timer = 4 / F_osc
say: its 31000Hz (as far as I remeber... must check this...)
T_timer = 129,0322 us

TIMER_COUNT = T_req/T_timer
T_req = 10ms as you pleased
TIMER_COUNT = 77.5
as your timer could not count with decimals...
it should be 77 or 78... let's see...

i'll pick 77... it means that, the timer must count 77 times (of 129us) to get 10ms (aprox)

if you are planning to use ONLY the timer interrupt... you must set it so after 77 counts, it will set the flag TMR1IF which only happens when it roll-over form MAX (FFFFh) to min (0000h) so if I set to MAX-77 + 1 it will get to MIN exactly after 77 counts...
so
TMR1 H:L = MAX -77 +1 = 65459 = FFB3
TMR1H = FFh
TMR1L = B3h

done!

I suggest to use the Capture/compare module... (compare with special trigger) you must clear the timer (TMR!H:L = 0) and set CCP1H:L to 77 easy!!!

all this stuff is in the datasheet of the pic you are planni to use... check it for more info...

M3GAPL3X

Points: 2

M3GAPL3X

Junior Member level 3
18f internal oscillator only

Thanks Kurenai_ryu! I'll try this tomorrow morning and see how it goes.

Status
Not open for further replies.