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

12LF1822 trouble after sleep, watchdog never fires? [Solved]

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



Joined: 21 Feb 2013
Posts: 8

View user's profile Send private message

12LF1822 trouble after sleep, watchdog never fires? [Solved]
PostPosted: Thu Feb 21, 2013 11:44 am     Reply with quote

CCS compiler 4.140
I am working with the pic 12LF1822 and I cannot seem to get the watchdog system to work.
I feel like I must be missing something really simple, since I have seen nothing else about it.

Now excusing that the pic wizard doesn't produce compilable code for the watchdog (it tires to use the wrong constants that are not available).

I made this dirt simple example to show that the PIC never wakes up from the sleep call.


Sample code:
Code:

#include <12LF1822.h>
#device ICD=TRUE
#device adc=16

#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES WDT_SW                   //No Watch Dog Timer, enabled in Software
#FUSES PUT                      //Power up Timer
#FUSES PLL_SW                   //4X HW PLL disabled, enabled in Software
#FUSES DEBUG                    //Debug mode for use with ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(clock=500000)

#define LED_LIGHT_PIPE     PIN_A4


void main()
{
   setup_oscillator(OSC_500KHZ  | OSC_INTRC | OSC_PLL_OFF );
   
   output_low(LED_LIGHT_PIPE);//turns LED off
   setup_wdt(WDT_ON|WDT_8S);//Turn watchdog on, scaler should = 8ms, WDT_ON and WDT_8S are in the .h

   sleep();//The pic never wakes back up
   setup_wdt(WDT_OFF);
   output_high(LED_LIGHT_PIPE);//turns LED on
   for(;;)
   {//never ending loop
      delay_ms(100);
   }
}

I have also tried using #FUSE WDT and not setting anything in software
(Defaults to a 2s time).

So far the only way I have found to wake it up is with INT_EXT or INT_AD (With AD set to use internal clock ONLY, otherwise it doesn't work).

I really need to be able to put the pic to sleep, I need the power savings.
Does anyone have working code to put this PIC asleep AND have it wake up from the watchdog?


Last edited by Plater on Thu Feb 21, 2013 1:11 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 21, 2013 12:09 pm     Reply with quote

Quote:
I feel like I must be missing something really simple

It's because you have these two fuses:
Quote:

#device ICD=TRUE
#FUSES DEBUG

If the compiler sees either one of those, it shuts off WDT, PROTECT,
and BROWNOUT. Your ICD unit doesn't allow those in debug mode,
so the compiler helpfully shuts them off for you. Unfortunately it
doesn't warn you that it has done this. CCS really ought to add that
feature.

This information about some features not being allowed in Debug mode
is buried in the ICD2 help file in MPLAB. Search for "Requirements for
debug mode".
Plater



Joined: 21 Feb 2013
Posts: 8

View user's profile Send private message

PostPosted: Thu Feb 21, 2013 1:10 pm     Reply with quote

You are correct, I removed those two lines and the watchdog fired as desired.

I came from using the PIC18F6527 which didnt seem to care about that.
I was using the watchdog just fine with:
Code:

#include <18F6527.h>
#device ICD=TRUE
#device adc=8

#FUSES WDT                      //Watch Dog Timer
#FUSES WDT4096                  //Watch Dog Timer uses 1:4096 Postscale
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NODEBUG                  //No Debug mode for ICD(*)


Honestly, I never even knew what that #device ICD=TRUE was doing, I was just carrying it over.

Thanks!
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