View previous topic :: View next topic |
Author |
Message |
Lykos1986
Joined: 26 Nov 2005 Posts: 68
|
16F877A and WDT |
Posted: Sun May 20, 2012 11:17 am |
|
|
Hello to everyone! I am trying to use the WDT into one of my programs and I am facing the problem of a "dead" WDT! So, I try to use one of the example programs of CCS:
Code: |
#include <16F877A.h>
#fuses XT,WDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C0, rcv=PIN_C1)
void main() {
switch ( restart_cause() )
{
case WDT_TIMEOUT:
{
printf("\r\nRestarted processor because of watchdog timeout!\r\n");
break;
}
case NORMAL_POWER_UP:
{
printf("\r\nNormal power up!\r\n");
break;
}
}
setup_wdt(WDT_2304MS);
while(TRUE)
{
restart_wdt();
printf("Hit any key to avoid a watchdog timeout.\r\n");
getc();
}
}
|
I've made a few basic changes at the processor name, clock speed (HS to XT), and the serial port pins.
But again the same problem. It seems that the WDT is not working at all! If I don't press any button the μC is not resetting as it's supposed to! Any help? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 20, 2012 11:25 am |
|
|
Prove that the serial communications work correctly. Test it, in a
separate program. |
|
|
Lykos1986
Joined: 26 Nov 2005 Posts: 68
|
|
Posted: Sun May 20, 2012 11:31 am |
|
|
The serial communication works perfectly (using the same program)! I am getting the "Hit any key to avoid a watchdog timeout." message.
If I press any button then I am getting again the same message as it supposed too. But I never get the "Restarted processor because of watchdog timeout!" even if I let the program to run for more than 5minutes (just in case that the timings are way off the charts). |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 20, 2012 11:55 am |
|
|
1. What's your CCS compiler version ?
List of versions:
http://www.ccsinfo.com/devices.php?page=versioninfo
2. Are you testing this on real hardware or is this a Proteus project ?
3. Why are you using a software UART instead of the hardware UART
on pins C6 and C7 ?
4. Describe the external circuits connected to your soft UART pins. |
|
|
Lykos1986
Joined: 26 Nov 2005 Posts: 68
|
|
Posted: Sun May 20, 2012 12:00 pm |
|
|
My CCS version is: 4.114
I am using real hardware that it is working fine with my project. I've try to include the WDT as a safety measure using my program in the beginning. Without any luck and believing that I am making a mistake somewhere I've load the example program to try the functionality... no luck here either!
I am using the software UART because the hardware UART is already in use by another part (a GSM module).
The soft UART pins of my μC are directly connected to the TX and RX pins of an FTDI clip. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 20, 2012 12:59 pm |
|
|
It works fine for me. I installed a 16F877A on my PicDem2-Plus board
with a 4 MHz crystal. I installed vs. 4.114 of the PCM compiler. I jumpered
pins C0 and C1 to pins C6 and C7 so that the soft UART pins were
connected to the Max232 chip on the board. I programmed it with a ICD2
and watched the output in a TeraTerm window. It works. I can press the
Enter key repeatedly and it prevents the WDT reset from occurring.
When I stop pressing Enter, then I get a WDT reset:
Quote: |
Restarted processor because of watchdog timeout!
Hit any key to avoid a watchdog timeout.
Hit any key to avoid a watchdog timeout.
Hit any key to avoid a watchdog timeout.
Hit any key to avoid a watchdog timeout.
Hit any key to avoid a watchdog timeout.
Hit any key to avoid a watchdog timeout.
Hit any key to avoid a watchdog timeout.
Hit any key to avoid a watchdog timeout.
Hit any key to avoid a watchdog timeout.
Hit any key to avoid a watchdog timeout.
Restarted processor because of watchdog timeout!
Hit any key to avoid a watchdog timeout.
|
Are you doing anything weird ? Are you trying to single step through the
code in Debug mode ? I wonder if the FTDI device is affecting it. |
|
|
Lykos1986
Joined: 26 Nov 2005 Posts: 68
|
|
Posted: Sun May 20, 2012 1:08 pm |
|
|
I don't thing that I am doing anything weird. I will try tomorrow another PIC 16F877A in a breadboard using the same program.
I am not using debug mode either. Just the regular ICD2 in the programming mode. I've also unplug the ICD2 just in case this was the cause of the problem.
Maybe the FTDI device is the problem. I will investigate tomorrow... |
|
|
Lykos1986
Joined: 26 Nov 2005 Posts: 68
|
|
Posted: Mon May 21, 2012 1:59 am |
|
|
Good morning! I've build a small circuit in a breadboard in order to test the WDT.
The problem is the configuration bits! I an using "#fuses XT,WDT,NOPROTECT,NOLVP" as the settings in my code but if I look at the Configure -> Configuration Bits of the MpLab 8.6 the WDT is disabled! I don't know if this is a CCS / MpLab bug or just a stupidity that I am making somewhere!
Somehow I managed to enable the WDT from the same window of MpLab (by unchecking the "Configuration Bits set in code" and enabling the WDT) and it worked perfectly!
The problem now is that is not letting me to enable the WDT again from the same window. If I select enable WDT when I will compile the program it will turn to WDT Disabled again. I've try to totally comment the #fuses section in my code just in case that this was the problem but again the same thing. I am selecting WDT Enable and when I am compiling it turn to WDT Disable. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19541
|
|
Posted: Mon May 21, 2012 2:48 am |
|
|
MPLAB.....
It has two modes of operation. Debug, and release. It _defaults_ to using debug mode. When debug mode is selected, certain fuses are overridden - in particular the watchdog fuse.
You need to select 'release' in the build options.
A search here would have found several posts about this, or mentioning 'MPLAB' earlier would have got the answer.
Best Wishes |
|
|
Lykos1986
Joined: 26 Nov 2005 Posts: 68
|
|
Posted: Mon May 21, 2012 10:36 am |
|
|
Silly me! I should mention the MpLab word earlier! Now everything is working fine! Thanks to both of you for the precious help! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Lykos1986
Joined: 26 Nov 2005 Posts: 68
|
|
Posted: Wed May 23, 2012 2:11 am |
|
|
Really thank you! Very useful post! |
|
|
|