Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Calculations for Timer1 on 18f (16 bit timer)

Status
Not open for further replies.

M3GAPL3X

Junior Member level 3
Joined
Jul 29, 2009
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,521
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

Advanced Member level 2
Joined
Jun 10, 2006
Messages
671
Helped
159
Reputation
316
Reaction score
99
Trophy points
1,308
Location
Bolivia
Activity points
5,909
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
    Helpful Answer Positive Rating

M3GAPL3X

Junior Member level 3
Joined
Jul 29, 2009
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,521
18f internal oscillator only

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

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top