Truncated match.
PICList
Thread
'1 Second Timer Interrupt'
1997\08\05@132113
by
Jean-Francois Joly
Hello! I have a pic16c84/04 here and I would like to know if there is
a way to make the timer interrupt go on each second. How can I do
that? Thank you very much!
Jean-Francois
BTW: sorry for the newbie question!
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Jean-Francois Joly - spam_OUTjolyalTakeThisOuT
capitalnet.com
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
1997\08\05@134203
by
avrbasic
At 01:07 PM 5/8/97 -0400, you wrote:
>Hello! I have a pic16c84/04 here and I would like to know if there is
>a way to make the timer interrupt go on each second. How can I do
>that? Thank you very much!
>
>Jean-Francois
if you want really interrupts on each second you must use a very low
frequency for the crystal. at normal speeds pic16c84 timer 8 bit +
prescaler 8 bit will alwasy overflow faster than once per second
the best way to get 1 second interval is to set the timer reload value
and prescaler to some suitable values and extend the timer in software
by counting intrrupts until one second is elapsed.
antti
No Limits Go To
Basics of AVR AVR
AVRBASIC http://www.avrbasic.com Born for Basic
Grand opening in August.
Watch out for first week offers.
1997\08\05@152740
by
Byron A Jeff
>
> Hello! I have a pic16c84/04 here and I would like to know if there is
> a way to make the timer interrupt go on each second. How can I do
> that? Thank you very much!
Well presuming that you're going to clock it at 4 Mhz, there isn't a way
to do it. It's a hardware limitation.
The clock oscillator divides the input clock by 4. That gives you 1Mhz.
The TMR0 is 8 bits. You can also prescale up to 8 bits which in effect
divides the clock by 256. So the maximum divide factor in hardware is
65536. Dividing this into 1 Mhz gives you 15.2587890625 HZ. The amounts
to one interrupt every 65 milliseconds.
The solution that is usually put to use isn't hard. Simply let the interrupt
tick faster than the clock you want and count the ticks. When the ticks add
up to your desired 1 second, then call the routine that actually does something
once a second.
So for the same example, take the 1 Mhz and prescale by 64. This gives
a tick rate for TMR0 of 15625 Hz. Now set up TMR0 to roll over after 125
ticks (which is the largest factor of 15625 - in fact it's the square root).
This will give you exactly 125 ticks per second. You'll have the reset the
TMR0 register each interrupt to count off 125 more ticks until the next
interrupt. Also note the number of interrupts that has occured. When you
reach 125 interrupts, you know that one second has elapsed and then you
do your one second routine.
Now this isn't the most precise method because resetting the TMR0 each
interrupt resets the prescaler too. This means you'll lose a bit of time
each time.
If timing is important and needs to be real precise then choosing a better
initial clock frequency will help immensely. The objective is to get the
TMR0 to roll over naturally without having to be preset. Then the free
running TMR0 and prescaler will never lose any time.
For example changing the input clock to 4.096 Mhz will accomplish this task.
The 1.024 Mhz input can be prescaled by 32 (giving exactly 32000 ticks to
TMR0. With this clock a free running TMR0 will generate exactly 125 interrupt
each second. And because both the prescaler and TMR0 are free running the
clock will be quite accurate.
Hope this helps,
BAJ
More... (looser matching)
- Last day of these posts
- In 1997
, 1998 only
- Today
- New search...