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 CCS Technical Support

ex_wdt.c does not seem to work on PIC18F8720: why not?

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



Joined: 23 Feb 2004
Posts: 51

View user's profile Send private message

ex_wdt.c does not seem to work on PIC18F8720: why not?
PostPosted: Tue Feb 24, 2004 2:22 pm     Reply with quote

Friends,

Has anyone tried to run watchdog example ex_wdt.c on an 8720 -- or on any target chip for that matter? I'm running CCS's "Minipicd8x20" 18F8720 demo board and compiler v3.185.

- It does appear to time out.
- But when it restarts, I don't get any reset_cause() return other than "normal power up." I would think it would cite "wdt timeout" as the reason.

2) What is the correspondence between the #fuses values like WDT128 and the millisecond values of earlier chips?

Thanks,

Smile Robert
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 24, 2004 6:29 pm     Reply with quote

Quote:
Has anyone tried to run watchdog example ex_wdt.c on an 8720
-- or on any target chip for that matter? I'm running CCS's "Minipicd8x20" 18F8720 demo board and compiler v3.185.


Which CCS example file are you using ? There are two different ones,
depending upon which PIC you have: ex_wdt.c and ex_wdt18.c

Also, vs. 3.185 has at least one known problem with the bit_set()
function, in which a previously working function was broken.
So I would be cautious about trusting that version. It may have
other problems. http://www.ccsinfo.com/forum/viewtopic.php?t=18394

Regarding testing the ex_wdt18.c program:
I don't have an 18F8720. I only have an 18F458. I modified
the ex_wdt18.c file slightly to work with my demo board,
and it ran fine. This is with PCH vs. 3.178. Here are the
messages displayed on the terminal window.

    Normal power up!
    Hit any key to avoid a watchdog timeout.

    Restarted processor because of watchdog timeout!

Code:
#ifndef __PCH__
 #error This example is only for PIC18
#endif

#include <18F458.h>
#fuses XT,WDT128,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) 

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_ON);

   while(TRUE)
   {
      restart_wdt();
      printf("Hit any key to avoid a watchdog timeout.\r\n");
      getc();
   }
}   
RKnapp



Joined: 23 Feb 2004
Posts: 51

View user's profile Send private message

PostPosted: Wed Feb 25, 2004 2:12 pm     Reply with quote

PCM Programmer,

Thanks for your reply, and for trying it on your board.

Mine still does not work! I tried the exact same code as yours except:

- my include file is the device file for 8720, "18F8720.h"

- #fuses XT is, in my code, #fuses HS. (I don't know what the different kind of clock arrangements are, and don't know how to find out what CCS means by these different options, but I think their protoboard can use only "HS", a 20MHz oscillator between pins 49 & 50, as a supplied timing source.)

- I'm not sure what our hardware differences would be; I'm using CCS v3.185 on their prototyping board "Minipicd8x20".

But it still does not work. I will submit a tech support request, but have not had great luck with these so far. If you have any other ideas, or anyone else tries this with an 8720, pls let me know.

Thanks anyway,

Sad Robert
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 25, 2004 3:25 pm     Reply with quote

Post the .LST file that you got when you compiled my test program.
(I mean, the program, after you changed it for the 18F8720).
I'll compare it to the code generated for vs. 3.178.
RKnapp



Joined: 23 Feb 2004
Posts: 51

View user's profile Send private message

PostPosted: Wed Feb 25, 2004 3:57 pm     Reply with quote

PCM,

.LST is below. Alas, I don't know assembly so I don't see anything obvious. It must be some kind of "fuse?" (Whatever "fuses" are, they're not documented; CCS manual says "typical choices are" blah blah.. but I can't see any mention of what these would correspond to in the Microchip Data Sheet.)

Thanks!

Smile Robert

Code:
CCS PCH C Compiler, Version 3.185

               Filename: C:\KNAPP\NTEK_HDV100\RAK_8720\ExampleTests\ex_wdt.LST

               ROM used: 368 (0%)
                         Largest free fragment is 0
               RAM used: 6 (0%) at main() level
                         6 (0%) worst case
               Stack:    1 locations

*
0000:  GOTO   00B8
....................  #include <18F8720.h>
....................  //////// Standard Header file for the PIC18F8720 device ////////////////
.................... #device PIC18F8720
.................... #list
....................
.................... #use delay(clock=20000000)
.................... #fuses HS, WDT128, NOPROTECT, NOLVP
.................... #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)
....................
....................
.................... void main()
.................... {
00B8:  CLRF   FF8
00BA:  BCF    FD0.7
00BC:  CLRF   FEA
00BE:  CLRF   FE9
00C0:  MOVLW  0F
00C2:  MOVWF  FC1
00C4:  MOVLW  07
00C6:  MOVWF  FB4
00C8:  MOVLW  81
00CA:  MOVWF  FAF
00CC:  MOVLW  26
00CE:  MOVWF  FAC
00D0:  MOVLW  90
00D2:  MOVWF  FAB
....................
....................    switch ( restart_cause() )
....................    {
00D4:  MOVF   FD0,W
00D6:  ANDLW  0E
00D8:  BCF    FD0.1
00DA:  MOVWF  00
00DC:  MOVLW  04
00DE:  SUBWF  00,W
00E0:  BTFSC  FD8.2
00E2:  GOTO   00F4
00E6:  MOVLW  0C
00E8:  SUBWF  00,W
00EA:  BTFSC  FD8.2
00EC:  GOTO   0118
00F0:  GOTO   013C
....................       case WDT_TIMEOUT:
....................       {
....................          printf("\r\nRestarted processor because of watchdog timeout!\r\n");
00F4:  CLRF   06
00F6:  MOVF   06,W
00F8:  CALL   0004
00FC:  INCF   06,F
00FE:  MOVWF  00
0100:  MOVF   00,W
0102:  BTFSS  F9E.4
0104:  GOTO   0102
0108:  MOVWF  FAD
010A:  MOVLW  34
010C:  SUBWF  06,W
010E:  BTFSS  FD8.2
0110:  GOTO   00F6
....................          break;
0114:  GOTO   013C
....................       }
....................       case NORMAL_POWER_UP:
....................       {
....................          printf("\r\nNormal power up!\r\n");
0118:  CLRF   06
011A:  MOVF   06,W
011C:  CALL   004E
0120:  INCF   06,F
0122:  MOVWF  00
0124:  MOVF   00,W
0126:  BTFSS  F9E.4
0128:  GOTO   0126
012C:  MOVWF  FAD
012E:  MOVLW  14
0130:  SUBWF  06,W
0132:  BTFSS  FD8.2
0134:  GOTO   011A
....................          break;
0138:  GOTO   013C
....................       }
....................    }
....................
....................    setup_wdt(WDT_ON);
013C:  BSF    FD1.0
....................
....................    while(TRUE)
....................    {
....................       restart_wdt();
013E:  CLRWDT
....................       printf("Hit any key to avoid a watchdog timeout.\r\n");
0140:  CLRF   06
0142:  MOVF   06,W
0144:  CALL   0078
0148:  INCF   06,F
014A:  MOVWF  00
014C:  MOVF   00,W
014E:  BTFSS  F9E.4
0150:  GOTO   014E
0154:  MOVWF  FAD
0156:  MOVLW  2A
0158:  SUBWF  06,W
015A:  BTFSS  FD8.2
015C:  GOTO   0142
....................       getc();
0160:  BTFSS  F9E.5
0162:  GOTO   0160
0166:  MOVF   FAE,W
....................    }
0168:  GOTO   013E
.................... }
....................
016C:  GOTO   016C

Configuration Fuses:
   Word  1: 2200   HS NOOSCSEN
   Word  2: 0E0C   NOBROWNOUT WDT128 NOWDT BORV25 PUT
   Word  3: 0183   NOWAIT MCU CCP2C1
   Word  4: 0001   STVREN DEBUG NOLVP
   Word  5: C0FF   NOPROTECT NOCPD NOCPB
   Word  6: E0FF   NOWRT NOWRTD NOWRTC NOWRTB
   Word  7: 40FF   NOEBTR NOEBTRB
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Wed Feb 25, 2004 4:20 pm     Reply with quote

RKnapp wrote:
PCM,

.LST is below. Alas, I don't know assembly so I don't see anything obvious. It must be some kind of "fuse?" (Whatever "fuses" are, they're not documented; CCS manual says "typical choices are" blah blah.. but I can't see any mention of what these would correspond to in the Microchip Data Sheet.)

Thanks!

Smile Robert


In general a microcontroller's fuses refer to bits in its configuration word or words. This is well documented in most PIC data sheets, usually in the "Special Features of the CPU" section. About page 240 of the PIC18Fxx20 data sheet (http://www.microchip.com/download/lit/pline/picmicro/families/18fxx20/39609b.pdf)
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
RKnapp



Joined: 23 Feb 2004
Posts: 51

View user's profile Send private message

PostPosted: Wed Feb 25, 2004 11:06 pm     Reply with quote

rwyoung,

Thank you very much for pointing me to this area. I hadn't understood the "#fuses" concept of these bits. I'll take a closer look at the datasheet and see what I can suss out.

Again, thanks,

Smile Robert
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 26, 2004 1:37 am     Reply with quote

After studying the ASM, I'm not sure what the problem might be.
At this point, if this was my problem, I would put several printf
statements into the program, and display the value of the RCON
register at various points.

I also noticed that you have the DEBUG fuse set. I don't have it
set in my test program. I wonder, are you running your program
under ICD2 in Debug mode ? I don't know what effect that would
have, but it might be important. I did my test as a standalone
program, and programmed the 18F458 with my PicStart-Plus.

If you want to pursue this and use printfs to display RCON,
then you need to put the following line of code above main():

#byte RCON = 0xFD0

Then, within the program, you need to insert several statements
like these, at the appropriate points:

printf("initial RCON value = %x\n\r", RCON);

printf("RCON after setup_wdt() = %x\n\r", RCON);

printf("RCON after restart_wdt() = %x\n\r", RCON);

printf("RCON after getc() = %x\n\r", RCON);

Then run the program and let a Watchdog timeout occur,
(by not pressing a key), and see what values are displayed.
Then analyze them while referring to the data sheet.
TSchultz



Joined: 08 Sep 2003
Posts: 66
Location: Toronto, Canada

View user's profile Send private message

PostPosted: Thu Feb 26, 2004 6:14 am     Reply with quote

Here are the fuse setting I normally use for PIC18 series parts with watchdog timer enabled, > 4MHz clock, and 5V supply.

#fuses HS, PUT, BROWNOUT, WRT, NOWRTD, WDT, WDT128, STVREN, BORV42, NOLVP

The biggest one is the WDT, this enables the watchdog timer. This is different than how the PIC16 series parts handle this. The WDT128 sets the watchdog prescaler to 128.
RKnapp



Joined: 23 Feb 2004
Posts: 51

View user's profile Send private message

PostPosted: Thu Feb 26, 2004 4:10 pm     Reply with quote

Friends,

Thanks for your attempts to help! I still can't get this thing to work; it must be some dumb thing. I'm running CCS v3.185, connected to an ICD-U40 v1.20, on CCS's 18F8720 prototyping board called "Minipicd8x20".

0) First of all, I can't figure out how to get the board to run independently of the ICD-U40: I'd sometimes like it in "programming" mode but not in "debug" mode. How is this done? As PCM noted, this could be important.

1) The "DEBUG" bit per se, however, appears to only to dedicate B6 & B7 to the interface if the 8720's .pdf, "PIC18F8xx20", page 245 (document page 243) re bit 7 of Config4L Bit 7, is to be trusted.

However, in any case, I cannot get this bit "un-set." There is some kind of error which pops up saying that ICD=TRUE must be in the #devices statement. However, whether in or out, this bit stays set... (?)

2) Now, I did try the suggested fuses

#fuses HS, PUT, BROWNOUT, WRT, NOWRTD, WDT, WDT128, STVREN, BORV42, NOLVP

but it immediately whined, saying "need #use delay if RS232 is to be used." So I added to this set:

#use delay(clock=20000000, RESTART_WDT)

but this did not appear to help, either.

3) I noticed that fuse WDT somehow does NOT lead to bit 0 of Config2H being set. My .lst file says, for the #fuses above:

Configuration Fuses:
Word 1: 2200 HS NOOSCSEN
Word 2: 0E04 NOBROWNOUT WDT128 NOWDT BORV42 PUT
Word 3: 0183 NOWAIT MCU CCP2C1
Word 4: 0001 STVREN DEBUG NOLVP
Word 5: C0FF NOPROTECT NOCPD NOCPB
Word 6: E0FF NOWRT NOWRTD NOWRTC NOWRTB
Word 7: 40FF NOEBTR NOEBTRB

Thus I conclude that WDTEN is not set, and that the WDT is under SWDTEN control. Is this material? Should this affect the call to tickle the watchdog, the example's restart_wdt (); call which turns into CLRWDT?

I.e., should I be directly trying to write the SDWTEN bit?

This must be simple.... maybe just detaching the ICD-U40 from the proto-board for standalone operations? I can't figure out if the plot is getting thicker or thinner here.

Smile Robert
RKnapp



Joined: 23 Feb 2004
Posts: 51

View user's profile Send private message

PostPosted: Thu Feb 26, 2004 6:34 pm     Reply with quote

AHA! A break in the case: I think I've figured out how to run the board in "standalone" mode, and when I was able to do this, for some reason the WDT works fine -- and timeouts lead to the WDT_TIMEOUT reason.

0) I'd tried to talk directly to the ICD-U40 before, but the "control" always came up in ICD-S, not ICD-U mode (showing a little screen with COM1 and COM3 as the only possible choices. This is not good since it's a USB-based device.) I was annoyed at this but didn't want to click on either COM1/COM3 in case this would somehow confuse the IDE's Debugger -- which hasn't been confused before -- into wrongly thinking that I have an ICD-S. (When in doubt, never tempt Windows into serving up new annoyances.)

1) But finally I did try to click on COM1 just for the heck of it -- and after it greyed out for a while it came back offered the right choice, an ICD-U40. I clicked on this and a fancy graphical screen showing a board, an ICD, and a PC popped up!

2) Well shucks, this "ICD Control" screen offers lots of nice choices that do NOT involve debugging. You can update the ICD's firmware to 1.23 (the latest version), download .COFF files to the target, start/stop. When just "run" as a program, somehow, the WDT works fine and cites the correct restart_cause() value.

Fuses are still mysteriously set to NOWDT (indicating SWDTEN is still in charge) and I would love to know how this all works, if anyone knows -- but I guess I can't argue with success.

I'm posting this to THANK everyone who has wondered what is going on: Standalone ops are required for the WDT and ex_wdt.c to work correctly.

Smile Robert
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