|
|
View previous topic :: View next topic |
Author |
Message |
kd5uzz_ Guest
|
Timer1 help - 500ms ISR for Timer1 on 16F688 |
Posted: Fri Dec 05, 2008 4:55 pm |
|
|
Hello,
I've never used Timer1 before, I always use Timer2 for my LEDs, etc. This time I'm using a 16F688 and it doesn't support Timer2.
I'm using the internal clock @ 8mhz.
I need to check a pin every 500ms.
8,000,000/4 = 2,000,000 -> clock ticks
2,000,000/8 = 250,000 ticks per ISR
250,000 ticks = 5ms (1000/250,000) right?
So that means I've got to have a counter that counts 100 ISRs. Any better way to do it? |
|
|
kd5uzz_ Guest
|
|
Posted: Fri Dec 05, 2008 4:57 pm |
|
|
Oh yeah..
Code: | #include <16F688.h>
#fuses NOWDT,NOPROTECT,NOBROWNOUT, NOMCLR, INTRC
#use delay(clock=8000000)
#use rs232(stream=Jech_Bus, baud=19200, xmit=PIN_C4, rcv=PIN_C5) |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 05, 2008 5:35 pm |
|
|
It's a 16-bit counter. It can count from 0 to 65535. If you use a
pre-scaler of 8, the timer clock is 250,000 Hz. It takes that many clocks
to count up 1 second. To count for a 1/2 second, it takes half that many
clocks: 125,000. The timer can do that in two interrupts, at 62,500
clocks each. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|