View previous topic :: View next topic |
Author |
Message |
erdwin Guest
|
timer2 |
Posted: Wed Jul 04, 2007 8:17 am |
|
|
timer2 for one second exact |
|
|
Ttelmah Guest
|
|
Posted: Wed Jul 04, 2007 8:26 am |
|
|
Depends on your crystal frequency...
Probably not possible. More likely to have to have something like 10mSec exactly, and count to 100.
Best Wishes |
|
|
Guest
|
|
Posted: Wed Jul 04, 2007 8:30 am |
|
|
Ttelmah wrote: | Depends on your crystal frequency...
Probably not possible. More likely to have to have something like 10mSec exactly, and count to 100.
Best Wishes |
the crystal frequency is 20mhz |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Jul 05, 2007 9:37 am |
|
|
With a 20MHZ crystal, try:
setup_timer_2(T2_DIV_BY_16,249,10);
This will cause the timer interrupt to happen 125 times a second. Simply have a variable count to 125 and set a flag. Then, have this flag addressed in your main() somewhere. Don't forget to reset your counter variable to zero when it sets the flag or it will set the flag every time the ISR is entered after that.
Try looking at the spec. sheet for the PIC you are using and look at the section on timer2. It helps to see how the hardware is configured and then understand how the compiler is setting things up.
Ronald |
|
|
|