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 support@ccsinfo.com

pic24fj + explorer16 + WDT + v5.045d

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



Joined: 20 Aug 2015
Posts: 17

View user's profile Send private message

pic24fj + explorer16 + WDT + v5.045d
PostPosted: Thu Aug 20, 2015 2:00 am     Reply with quote

Hello,

After reading many time the datasheet of this micro, I'm not able to apply correctly the WDT and DSWDT. There are some concepts which I don't really understand and hope that someone could explain...

Here is my source code:
Code:

MAIN.H //////////////////////////////

#include <24FJ128GA310.h>

#FUSES WDT                      //Watch Dog Timer
#FUSES WDT32                    //Watch Dog Timer uses 1:32 Postscale
#FUSES WPOSTS11                 //Watch Dog Timer PostScalar 1:1024
#FUSES WINDIS                   //Watch Dog Timer in non-Window mode
#FUSES NOLVR                    //Low Voltage Regulator Disabled
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOJTAG                   //JTAG disabled
#FUSES IOL1WAY                  //Allows only one reconfiguration of peripheral pins
#FUSES NOOSCIO                  //OSC2 is clock output
#FUSES CKSFSM                   //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES VREFNORM_CVREFNORM       //VREF and CVREF are mapped to their default pins
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES WPFP                     //Write/Erase Protect Page Start/End Location, set to last page or use WPFP=x to set page
#FUSES VBATBOR                  //VBAT BOR Enabled
#FUSES SOSC_SEL                 //SOSC circuit selected
#FUSES WDTWIN_25%               //Watchdog Window is 25% of WDT period
#FUSES NOBROWNOUT               //No brownout reset
#FUSES WPDIS                    //All Flash memory may be erased or written
#FUSES NOWPCFG                  //Configuration Words page is not erase/write-protected
#FUSES WPEND                    //Flash pages WPFP to Configuration Words page are write/erase protected
#FUSES DSWDT_1SEC               //DSWDT uses 1:32768 Postscale (1.057Secs)
#FUSES DSWDTCK_LPRC             //DSWDT uses LPRC as reference clock
#FUSES DSBOR                    //BOR enabled in Deep Sleep
#FUSES DSWDT                    //Deep Sleep Watchdog Timer enabled
#FUSES DS_SW                    //Deep Sleep is controlled by the register bit DSEN

#device ICD=TRUE
#device ICSP=1
#use delay(internal=8MHz)

#define RUN_LED PIN_A0


MAIN.C ////////////////////////////////////////////////////

#include <main.h>


void main(){

  setup_wdt(WDT_ON);

  output_low( RUN_LED ); // turn on RUN LED
  delay_ms(1000);
  output_high( RUN_LED ); // turn off RUN LED
  delay_ms(1000);

  while (true){
  sleep(SLEEP_IDLE);
  delay_cycles(1);
  output_toggle(RUN_LED); 
  delay_ms(1000);
//  restart_wdt();
}
}


As you can imagine, this code is not working and I do not get exactly the reason why...I guess the problem are the configuration bits, but I have tried all combinations and still doesn't seem to work.

My question is the following...

DSWDT:

I guess it is only applied when the mcu is in sleep mode...doesn't it?
Is it required to execute the instruction setup_wdt(WDT_ON) to enable it if the fuse DS_SW is not present?

WDT:

POR when software malfunction or any instruction takes too long (under values set in prescaler and postscaler).

In case it is not driven by software and pre and post are using fuses...is it required to execute the instruction setup_wdt(WDT_ON)? it it does...if we use setup_wdt(WDT_ON| WDT_1S)...does this last parameter overrides the values set using FUSES? Does this instruction affect WDT and DSWDT?


I know these are really basic concepts but I've read the datasheet many times and I do not get it. Moreover, the most frustrating is that I'm able to make it work with xc16 but not with ccs.


Thanks in advance.
Ttelmah



Joined: 11 Mar 2010
Posts: 19338

View user's profile Send private message

PostPosted: Thu Aug 20, 2015 8:24 am     Reply with quote

Key thing. One simple statement. The watchdog, is _always_ disabled in DEBUG mode.

Simple little thing you can always do, look at the end of the LST file to see the actual fuses being generated. You will find:

Code:

Configuration Fuses:
   Word  1L: 378A   WPOSTS11 WDT32 NOWDT WINDIS ICSP1 NOLVR DEBUG NOWRT NOPROTECT NOJTAG
          H: 0000

Note 'NOWDT'.

If you turn off ICD, you will instead see:

Code:

Configuration Fuses:
   Word  1L: 3FEA   WPOSTS11 WDT32 WDT WINDIS ICSP1 NOLVR NODEBUG NOWRT NOPROTECT NOJTAG
          H: 0000

Note 'WDT'.....

This is a limitation with DEBUG/ICD.

To debug this you have to use a chip directly, not in DEBUG.
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