|
|
View previous topic :: View next topic |
Author |
Message |
willie.ar
Joined: 21 Jan 2004 Posts: 15 Location: Argentina
|
using tmr0 & wdt simultaneously |
Posted: Tue May 25, 2004 9:44 pm |
|
|
can I do this:
setup_timer_0(RTCC_DIV_256|RTCC_INTERNAL);
setup_wdt(WDT_2304MS);
from the 16f628 data sheets
" An 8-bit counter is available as a prescaler for the Timer0 module, or as a postscaler for the Watchdog Timer " so, can the CCS compliler manage both things I need. If not, I already have all the code writen using tmr0 -since it should be a 16 bit one- and I need a wdt each 2 seconds aprox. How can I do that ???
tks
CCS compiler version 3.180 |
|
|
Ttelmah Guest
|
Re: using tmr0 & wdt simultaneously |
Posted: Wed May 26, 2004 2:35 am |
|
|
willie.ar wrote: | can I do this:
setup_timer_0(RTCC_DIV_256|RTCC_INTERNAL);
setup_wdt(WDT_2304MS);
from the 16f628 data sheets
" An 8-bit counter is available as a prescaler for the Timer0 module, or as a postscaler for the Watchdog Timer " so, can the CCS compliler manage both things I need. If not, I already have all the code writen using tmr0 -since it should be a 16 bit one- and I need a wdt each 2 seconds aprox. How can I do that ???
tks
CCS compiler version 3.180 |
Using the internal hardware, you can't.
A 'simple' solution, is to not use the internal watchdog, but add an external retrigerable monostable multivibrator, that when it times out, operates the MCLR pin. Then connect the 'trigger' from one output bit on the PIC, and toggle this to reset the 'watchdog'.
Another solution is to leave the watchdog at the shorter (nominal 18mSec) interval, and if you have a timer that triggers at (say) 10mSec intervals, reset the watchdog in this, with code like:
Code: |
int8 wdog=200;
//inside the tiner tick
if (wdog) {
--wdog
restart_wdt();
}
//Then to 'reset the watchdog' in your code, just use:
wdog=200;
|
What then happens is that the watchdog is reset on each 'tick' interrupt, so long as wdog contains a value. When it reaches zero, the watchdog is no longer reset, and will trigger a little latter. Using a 10Sec 'tick', it will count down for just over 2 seconds, before this happens.
Best Wishes |
|
|
Guest
|
Re: using tmr0 & wdt simultaneously |
Posted: Wed May 26, 2004 9:06 am |
|
|
Ttelmah wrote: | willie.ar wrote: | can I do this:
setup_timer_0(RTCC_DIV_256|RTCC_INTERNAL);
setup_wdt(WDT_2304MS);
from the 16f628 data sheets
" An 8-bit counter is available as a prescaler for the Timer0 module, or as a postscaler for the Watchdog Timer " so, can the CCS compliler manage both things I need. If not, I already have all the code writen using tmr0 -since it should be a 16 bit one- and I need a wdt each 2 seconds aprox. How can I do that ???
tks
CCS compiler version 3.180 |
Using the internal hardware, you can't.
A 'simple' solution, is to not use the internal watchdog, but add an external retrigerable monostable multivibrator, that when it times out, operates the MCLR pin. Then connect the 'trigger' from one output bit on the PIC, and toggle this to reset the 'watchdog'.
Another solution is to leave the watchdog at the shorter (nominal 18mSec) interval, and if you have a timer that triggers at (say) 10mSec intervals, reset the watchdog in this, with code like:
Code: |
int8 wdog=200;
//inside the tiner tick
if (wdog) {
--wdog
restart_wdt();
}
//Then to 'reset the watchdog' in your code, just use:
wdog=200;
|
What then happens is that the watchdog is reset on each 'tick' interrupt, so long as wdog contains a value. When it reaches zero, the watchdog is no longer reset, and will trigger a little latter. Using a 10Sec 'tick', it will count down for just over 2 seconds, before this happens.
Best Wishes |
tks for your quick answer Ttelmah
I see now that I was confused. Actually I'm using the TMR1 for the 16 bit stuff so, I can use the TMR0 for the wdt without problems.
Willie.ar |
|
|
Ttelmah Guest
|
Re: using tmr0 & wdt simultaneously |
Posted: Wed May 26, 2004 9:12 am |
|
|
[quote="Anonymous"][quote="Ttelmah"] willie.ar wrote: | tks for your quick answer Ttelmah
I see now that I was confused. Actually I'm using the TMR1 for the 16 bit stuff so, I can use the TMR0 for the wdt without problems.
Willie.ar |
That does rather solve the problem!.
Best Wishes |
|
|
|
|
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
|