View previous topic :: View next topic |
Author |
Message |
gpacer68
Joined: 18 Jun 2009 Posts: 4
|
PIC16F1936 watchdog enable issue |
Posted: Sat Aug 29, 2009 3:21 pm |
|
|
I am using PIC16F1936 with compiler version: v4.098 of PCW IDE.
I am having trouble getting the watchdog chip function to work as one would expect.
I have attached code below that essentially should boot, print a start message, then a few dots and finally after about 2.3 seconds restart the PIC given that restart_wdt() is commented out. Unfortunately, this never happens. I have spent hours worth of iterating on changing fuse bits and setup_wdt function parameters and all results are the same - the watchdog never times out.
Code: |
#include <16F1936.h>
#include <stdio.h>
#fuses noDEBUG // debug - in circuit debugger enabled on RB6 and RB7 - DISABLED
#fuses noLVP // LVP - low voltage enable - DISABLED
#fuses noFCMEN // Fail safe clock monitor - DISABLED
#fuses noIESO // IESO - internal / external switch over DISABLED
#fuses noBROWNOUT // Brown out reset selection bits - 11 BOR DISABLED
#fuses noCPD // CPD - date code protect DISABLED
#fuses noPROTECT // CP - code protect DISABLED
#fuses MCLR // MCLRE - RE3 is MCLR
#fuses noPUT // PWRTE - power up timer enable bit DISABLED
#fuses WDT_SW // WDTE - watch dog enable bit - not enabled here, in code below
#fuses INTRC_IO // FOSC - oscillator - set to INTRC_IO-- defaults the clock to 4Mhz
#use delay(clock=4000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)
main()
{
int b;
printf("start\n\r\n\r");
delay_ms(2000);
setup_wdt(WDT_2304MS);
b = 0;
while(true){
delay_ms(1000);
//output_toggle(PIN_B0);
//restart_wdt();
putc('.');
}
} |
I did find that the watchdog does fire with these settings:
Code: | #fuse WDT
setup_wdt(WDT_2304MS);
b = 0;
while(true){
delay_ms(1);
//output_toggle(PIN_B0);
restart_wdt();
putc('.');
}
} |
but when you change the delay to 1000 (or 1 sec), the part simply reboots continuously. Changing the delay to 2msec, still causes the part to reboot continuously.
I was wondering if it is possible, given that this part is so new, that compiler v4.098 support for the watchdog function of this part may not be working properly?
Or could it be my code, any help would be great :-) _________________ gpacer68 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Aug 30, 2009 1:17 pm |
|
|
I don't see the compiler writing to the WDTCON register in the .LST file
when setup_wdt() is called.
Make a little test program to do an experiment. See below.
In the start-up code, it disables the Watchdog by clearing the WDTCON
register. Then I have it write to the LATA register, to force it to switch to
Bank 2. Next, I write to WDTCON, as defined in a #byte statement. This
shows that the compiler will select Bank1 and then write to WDTCON at
address 0x17, and do it correctly.
Now examine the .LST code for setup_wdt(). I don't ever see it access
0x17, either directly or indirectly (with the FSR register). This is with
vs. 4.098.
Code: |
// These 6 lines are the later part of the start-up code.
0019: MOVLB 03
001A: MOVWF 0C
001B: MOVLB 01
001C: CLRF 17
001D: MOVLW 07
001E: MOVWF 1C
.................... LATA = 0xAA;
001F: MOVLW AA
0020: MOVLB 02
0021: MOVWF 0C
....................
.................... WDTCON = 0x55;
0022: MOVLW 55
0023: MOVLB 01
0024: MOVWF 17
....................
.................... setup_wdt(WDT_2304MS);
0025: MOVLW 09
0026: MOVLB 02
0027: MOVWF 05
0028: MOVLW 0F
0029: MOVWF 77
002A: MOVLB 00
002B: CLRF 15
002C: CLRF 05
002D: MOVLW 81
002E: MOVWF 04
002F: MOVF 00,W
0030: ANDLW F0
0031: IORLW 07
0032: MOVWF 00
0033: CLRWDT
0034: MOVF 00,W
0035: ANDLW F7
0036: BTFSC 77.3
0037: ANDLW F0
0038: IORWF 77,W
0039: MOVWF 00
....................
.................... while(1);
003A: GOTO 03A
|
Code: |
#include <16F1936.h>
#fuses INTRC_IO, NOLVP, WDT_SW
#use delay(clock=4000000)
#byte WDTCON = 0x97
#byte LATA = 0x10c
//=========================
main()
{
LATA = 0xAA;
WDTCON = 0x55;
setup_wdt(WDT_2304MS);
while(1);
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
gpacer68
Joined: 18 Jun 2009 Posts: 4
|
|
Posted: Mon Aug 31, 2009 6:55 pm |
|
|
Thanks for the reply. I guess I am not following your reply. You are showing that when setup_wdt is called it does not write to 0x17 WDTCON. But then you write a test program that forces it to write to WDTCON and it works. So does this prove what I am saying in that the compiler does have a bug as it does not setup the watchdog init register properly? If so when can the compiler be fixed? _________________ gpacer68 |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Mon Aug 31, 2009 7:19 pm |
|
|
This is NOT CCS Support. This is simply a user forum that is not usually monitored by CCS therefore no one here can tell you when it will be fixed. Read the box in the upper right corner of this web page then send a message with the details to CCS support at the link provided. Maybe they can tell you when it will be fixed... _________________ Google and Forum Search are some of your best tools!!!! |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Wed Sep 02, 2009 8:21 pm |
|
|
Thanks for the clarification. I am new to the forum and it looks so official I thought the site was associated with CCS. I have posted my bug report according to the instructions in the box on the top right. The forum might consider making the box outlined in RED such that it is more prominent.
Thanks again. |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Sep 04, 2009 7:17 pm |
|
|
perhaps it is a bit premature to expect to be able to use the new 16F1xxx
family with CCS -
&&
about making that 'no support' box visible?
i doubt it would make a difference if it flashed in red and violet and poured coffee out of the speakers.
![Very Happy](images/smiles/icon_biggrin.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|