View previous topic :: View next topic |
Author |
Message |
Doug Guest
|
O.T. - WDT timeout |
Posted: Mon Mar 01, 2004 11:13 am |
|
|
Where in the program should I put restart_wdt()? I need the prescaler for timer0 and my program loop is 35ms. Would it be a bad idea to put a restart_wdt() instruction inside a delay loop which lasts 25ms? If the program gets stuck in the loop it will never time out. What should I do?
Thanks,
Doug |
|
|
agrj
Joined: 26 Sep 2003 Posts: 48
|
|
Posted: Mon Mar 01, 2004 11:27 am |
|
|
Hi,
which PIC are you using? how are you doing this loop?
thanks
Dinho |
|
|
Ttelmah Guest
|
Re: O.T. - WDT timeout |
Posted: Mon Mar 01, 2004 11:53 am |
|
|
Doug wrote: | Where in the program should I put restart_wdt()? I need the prescaler for timer0 and my program loop is 35ms. Would it be a bad idea to put a restart_wdt() instruction inside a delay loop which lasts 25ms? If the program gets stuck in the loop it will never time out. What should I do?
Thanks,
Doug |
You speak as though you are waiting for an 'event', that happens at 35mSec intervals?.
If so, then consider using a counter inside your wait loop. Something like:
Code: |
counter=65000;
while (TRUE) {
if (counter) {
--counter;
restart_wdt();
}
if (check_for_event()) break;
}
//The code will arrive here, if the 'check_for_event' test has returned true
|
If the counter gets to zero before the 'check_for_event' test returns true, the watchdog will stop resetting, and 18mSec latter the watchdog will trigger. The 'event' is still tested in this time.
Best Wishes |
|
|
Doug Guest
|
|
Posted: Mon Mar 01, 2004 12:39 pm |
|
|
I'm using a 12c672 (I would like to use a 12F675 but my compiler version does not do them.)
Here is the loop:
Code: |
no_pulse = TRUE; // set no_pulse flag
time_out = MAX_OFF_TIME; // number of times to loop
do{
if (!input(PULSE_IN)) { // test PULSE_IN pin
disable_interrupts(GLOBAL);
edge_detect(); // call routine to measure pulse
enable_interrupts(GLOBAL);
if (!no_pulse) // if no_pulse is cleared,
break; // jump out of loop
}
} while(--time_out);
|
It loops the number of times in time_out and if PULSE_IN pin goes low it calls edge_detect() which will measure the length of the pulse and make no_pulse FALSE. When time_out reaches 0 it will exit the loop with no_pulse set to TRUE.
Thanks,
Doug |
|
|
Doug Guest
|
|
Posted: Mon Mar 01, 2004 12:45 pm |
|
|
Can just I add a restart_wdt() into the loop? or is it better to have it outside the loop.
How many of you actually use the WDT?
Thanks,
Doug |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
automatic Delay Watchdog restart |
Posted: Mon Mar 01, 2004 1:20 pm |
|
|
You might read the user manual about #use delay(xxxxxxx, restart_wdt) to see if this might help. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Doug Guest
|
|
Posted: Mon Mar 01, 2004 2:58 pm |
|
|
Thank you, that cleared up a few questions.
Doug |
|
|
|