CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

using tmr0 & wdt simultaneously

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
willie.ar



Joined: 21 Jan 2004
Posts: 15
Location: Argentina

View user's profile Send private message

using tmr0 & wdt simultaneously
PostPosted: Tue May 25, 2004 9:44 pm     Reply with quote

can I do this:
setup_timer_0(RTCC_DIV_256|RTCC_INTERNAL);
setup_wdt(WDT_2304MS);
Confused

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
PostPosted: Wed May 26, 2004 2:35 am     Reply with quote

willie.ar wrote:
can I do this:
setup_timer_0(RTCC_DIV_256|RTCC_INTERNAL);
setup_wdt(WDT_2304MS);
Confused

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
PostPosted: Wed May 26, 2004 9:06 am     Reply with quote

Ttelmah wrote:
willie.ar wrote:
can I do this:
setup_timer_0(RTCC_DIV_256|RTCC_INTERNAL);
setup_wdt(WDT_2304MS);
Confused

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
PostPosted: Wed May 26, 2004 9:12 am     Reply with quote

[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!. Laughing

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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