|
|
View previous topic :: View next topic |
Author |
Message |
Triton
Joined: 07 Apr 2006 Posts: 4
|
WDT only resets 1 time. |
Posted: Fri Apr 07, 2006 12:01 pm |
|
|
Hello All,
I am trying to understand how the WDT actually functions. This program began as a way to measure the WDT, but I guess I'm missing some fundemental principal. I have included the pertinent code below. The micro is a PIC12F629. The toggling is just so that I can see if anything is happening. The first while statement toggles correctly and then times out but then my output just remains low. I thought that the WDT would reset the main program so that the while loop would keep timing out. Does anyone know what I'm missing here?
Thanks,
John
#include <12F629.h>
#use delay(clock=4000000)
#fuses WDT,INTRC_IO, NOCPD, NOPROTECT, NOMCLR, NOPUT, NOBROWNOUT
#byte OPTION_REG=0x81
#byte TRISS=0x85
#byte VRCON=0x99
void main()
{
Setup_WDT(WDT_72MS);
setup_counters(RTCC_INTERNAL,RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
OPTION_REG=0xfa;
TRISS=0x0e;
VRCON=0; // vref off for low power
OUTPUT_BIT(Pin_A5,0);
delay_ms(10);
Restart_WDT();
while(1)
{
OUTPUT_BIT(Pin_A5,1);
Delay_ms(1);
OUTPUT_BIT(Pin_A5,0);
}
OUTPUT_BIT(Pin_A5,0);
delay_ms(10);
Restart_WDT();
while(1)
{
OUTPUT_BIT(Pin_A5,1);
Delay_ms(1);
OUTPUT_BIT(Pin_A5,0);
}
} |
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Fri Apr 07, 2006 1:01 pm |
|
|
The only bit of code that will execute will be
Code: | void main()
{
Setup_WDT(WDT_72MS);
setup_counters(RTCC_INTERNAL,RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
OPTION_REG=0xfa;
TRISS=0x0e;
VRCON=0; // vref off for low power
OUTPUT_BIT(Pin_A5,0);
delay_ms(10);
Restart_WDT();
while(1)
{
OUTPUT_BIT(Pin_A5,1);
Delay_ms(1);
OUTPUT_BIT(Pin_A5,0);
}
////// WILL NEVER REACH HERE !!!!!
..
..
..
}
|
The watchdog will timeout at somepoint in this endless loop. (after approx 75ms). At that point it will start the programm from the beginning and repeat the process.
What were you trying to achive ? How were you expecting it to work ?
FYI : Use the 'code' tags when including code in a post. It makes it easier to read and keeps the format. _________________ Regards,
Simon. |
|
|
Triton
Joined: 07 Apr 2006 Posts: 4
|
|
Posted: Sat Apr 08, 2006 10:06 am |
|
|
I added the second endless loop to try and understand what was going on. I expected the WDT to timeout on the first endless loop and then restart from the beginning of main(). If this were the case, I would expect to see 75ms bursts of the toggling in the endless loop separated by a 10ms low on the output. However, I see the first 75ms burst indicating that the WDT did in fact timeout, but then the output remains low. Am I missing something here?
Thanks,
John |
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Sat Apr 08, 2006 10:44 am |
|
|
Look at table 9-7 in the data sheet, DS41190C. The GPIO do not change during a watch dog timeout. _________________ David |
|
|
Ttelmah Guest
|
|
Posted: Sat Apr 08, 2006 2:48 pm |
|
|
I'd suggest simplifying things quite a bit.
First, the compiler has it's own TRIS access function, so get rid ofthe defines for this. In fact, since you are not using 'fast_io', you do not need to access the TRIS register at all. The setting for the TRIS register is wrong (you set the low four bits as inputs, yet you use the bottom two as outputs...
Then (and more importantly), you are setting the option register in three seperate places. You only need:
setup_counters((RTCC_INTERNAL,WDT_72MS);
or
setup_timer_0(RTCC_INTERNAL);
setup_wdt(WDT_72MS);
Remember that on boot, the watchdog timer will already have started, and it runs at the full speed, till it is reprogrammed. Hence you should restart the timer as soon as you reprogram it, or there is a significant chance the processor will never reach the end of the 10mSec delay...
Best Wishes |
|
|
Triton
Joined: 07 Apr 2006 Posts: 4
|
|
Posted: Mon Apr 10, 2006 12:44 pm |
|
|
Thank you very much for the help. I have simplified as requseted. Table 9-7 does state that the GPIO will not change during WDT reset, however, after the reset I am trying to change the IO. It still does not function as I expect. I would think that once the WDT times out in the while loop, the program would restart at main(). But still I see the first while loop timeout, and then the output remains low. Here is the simplified code.
#include <12F629.h>
#use delay(clock=4000000)
#fuses WDT,INTRC_IO, NOCPD, NOPROTECT, NOMCLR, NOPUT, NOBROWNOUT
void main()
{
Setup_WDT(WDT_72MS);
Restart_WDT();
setup_Timer_0(RTCC_INTERNAL);
OUTPUT_BIT(Pin_A5,0);
delay_ms(2);
Restart_WDT();
while(1)
{
OUTPUT_BIT(Pin_A5,1);
Delay_ms(1);
OUTPUT_BIT(Pin_A5,0);
}
} _________________ John |
|
|
Ttelmah Guest
|
|
Posted: Tue Apr 11, 2006 4:24 am |
|
|
I have just tried it, and the code works for me.
Timeout, on my particular PIC, was nearer to 60mSec, than the 'nominal' 72mSec (the watchdog, is a very inaccurate timer...), but it repeats fine.
Are you sure that you have everything setup right. MCLR for instance?. Though you have this disabled, there is a behaviour with this pin, where, because it is also used for the programming voltage, it does not have the protection diode that is present on normal pins (actually part of the output MOSFET driver). Because this is missing, the pin can float above 5v, and if it does, the chip will still reset (the voltage 'leaks' through into the reset circuit...).
I'd be perhaps inclined to think you have a hardware problem (what is connected to the A5 output pin?), that is causing a problem.
Also, what version is the compiler?. Some have 'known' problems with particular chips, and possibly one of these is 'biting' you.
Best Wishes |
|
|
Triton
Joined: 07 Apr 2006 Posts: 4
|
|
Posted: Tue Apr 11, 2006 5:53 am |
|
|
Thanks again for the information. At least now I know that it SHOULD work as I expect. My compiler is PCM Ver 3.249. Is this the version that you are using? Also, I have MCLR tied to Vdd with a 10k resistor. _________________ John |
|
|
|
|
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
|