Pumpkin, Inc.

Pumpkin User Forums

Timer reload value

If you can't make Salvo do what you want it to do, post it here.

Timer reload value

Postby Raj » Tue Feb 24, 2004 2:55 am

Hi,

Can you please tell me how did you get the value of 156 for the TMR0_RELOAD in the isr.h
for the example programs.

#if defined(SYSA) || defined(SYSE) || defined(SYSF)
|| defined(SYSH) || defined(SYSP)

#define TMR0_RELOAD 156 /* for 100Hz ints @ 4MHz */

Thanks a lot,
Raj.

Raj
 
Posts: 7
Joined: Wed Nov 19, 2003 12:00 am
Location: Erie, PA, USA

Re: Timer reload value

Postby aek » Tue Feb 24, 2004 3:06 am

Hi Raj.

1) Note that the code is written as TMR0 -= TMR0_RELOAD_VALUE.

2) Assume the TMR0 interrupt has happened, and the ISR is being serviced. If it's serviced immediately, TMR0 is now 0x00 (because it's a roll-over 8-bit timer that generates an interrupt when it rolls over), therefore

TMR0-TMR0_RELOAD_VALUE

is

0x00-156d

is therefore

256d-156d

(TMR0 is an 8-bit value) is therefore

100
which means that 156 TMR0 increments from now, TMR0 will roll over again, and cause another interrupt. So, the rest of the (initialization) code is set up to obtain 100Hz ints (and therefore a system tick period of 10ms), and TMR0 has a 10ms/156, or 64us period.

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

[This message has been edited by aek (edited February 25, 2004).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: Timer reload value

Postby Raj » Wed Feb 25, 2004 10:41 am

Hi AEK,

I am sorry I still dont get it!
Can you please explain me how does the 4Mhz processor speed come into the picture?

#define TMR0_RELOAD 156 /* for 100Hz ints @ 4MHz */

Thanks a lot.
Raj.

Raj
 
Posts: 7
Joined: Wed Nov 19, 2003 12:00 am
Location: Erie, PA, USA

Re: Timer reload value

Postby aek » Wed Feb 25, 2004 10:53 am

Hi Raj.

PS2 PS1 PS0 = 101h (see main.h) gives a prescalar of 64.

1us (instruction clock at 4MHz) * 64 * 156 = 9.984ms, i.e. almost exactly 10ms.

N.B in my earlier post (now corrected) I had mistakenly used 100 in a few places where 156 was the right number -- sorry about that.

Regards,

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

[This message has been edited by aek (edited February 25, 2004).]

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm


Return to Coding

Who is online

Users browsing this forum: No registered users and 2 guests

cron