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

WDT Sleep() and wakeup

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



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

WDT Sleep() and wakeup
PostPosted: Mon Jun 25, 2007 4:36 pm     Reply with quote

Greetings,
I seem to remember seeing something written about where the WDT re-enters the code exectution after a wakeup.
If I turn on the WDT, use a sleep() function and have the WDT bring the chip out of sleep, where does the code start at? Does the code restart from zero? Can I tell it where to re-enter the code?

I need to set some output pin states, keep those states while asleep, wake up and set the pin states again with possible new values. I do not want to reset the code to start again at the beggining. This puts glitches in my output pin states. (For instance PIN_A6 is also CLKO, I can see a square wave on PIN_A6 after the WDT wakeup.)

I read that if in sleep mode, the WDT will wake up the chip (not reset) and continue on with code execution.

Am I doing somehting wrong or just not reading the data sheet correctly?

(using PIC18F1220, internal osc @8Mhz)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 26, 2007 1:00 am     Reply with quote

Quote:

I read that if in sleep mode, the WDT will wake up the chip (not reset)
and continue on with code execution.

It should do that.

Quote:
Where does the code start at?

At the next instruction after the SLEEP instruction.

Quote:

For instance PIN_A6 is also CLKO, I can see a square wave on PIN_A6 after the WDT wakeup.

The 18F1220 data sheet says this:
Quote:
19.3 Two-Speed Start-up
Because the OSCCON register is cleared on Reset
events
, the INTOSC (or postscaler) clock source is not
initially available after a Reset event; the INTRC clock
is used directly at its base frequency.

I don't have any more time to research this right now, but I think either
it may be fixable with fuse settings, or it may not be fixable.

Post a very small test program and show the #fuses statement.
Also post your compiler version.
If possible, post the list of Config bit settings that the compiler puts
at the end of the .LST file.
jimcbride



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

PostPosted: Tue Jun 26, 2007 2:51 pm     Reply with quote

I will redo a smaller sleep only program and see what that does. I read about the dual speed startup. But since I am already using the internal RC I thought that it would not be a problem. I am not worried about speed waking up or how long it takes so long as the logic levels stay constant. I do have the option of using a different pin if we can't figure this out with the data you requested. Keeping everything on one port does have its advantages though.

More later...


Last edited by jimcbride on Thu Jun 28, 2007 10:10 am; edited 1 time in total
jimcbride



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

PostPosted: Thu Jun 28, 2007 10:08 am     Reply with quote

From the .LST file.
Configuration Fuses:
Word 1: C900 INTRC FCMEN IESO
Word 2: 150E BROWNOUT WDT BORV20 PUT WDT1024
Word 3: 8000 MCLR
Word 4: 0081 STVREN NODEBUG NOLVP
Word 5: C003 NOCPD NOPROTECT NOCPB
Word 6: E003 NOWRT NOWRTD NOWRTC NOWRTB
Word 7: 4003 NOEBTR NOEBTRB
Compiler version:
3.188

Code:
#include <18F1220.h>
#device adc=8
#zero_ram
#fuses intrc, WDT1024, BROWNOUT, PUT, NOLVP
#use delay(clock=8000000)
void main()
{
      setup_adc(ADC_OFF);
      setup_wdt(WDT_OFF);
      output_low(pin_a6);//set CLKO low

   while(TRUE)
   {
      output_high(pin_b0);
      delay_ms(100);
      output_low(pin_b0);
      setup_wdt(WDT_On);
      sleep();     
      setup_wdt(WDT_Off);     
   }
}

This code will flash an LED. Using a scope, I see that pin_a6 is outputting a 2 MHz signal which is 1/4 the intrc.(8 MHz) This pulse occurs for 100ms.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Jun 28, 2007 10:34 am     Reply with quote

I'm not really sure to understand what you want to do. You are refering to A6 as CLKO, do you mean here that in some situations you want to use this pin for outputting the processor clock?

Check the datasheet for oscillator configurations (chapter 2.1).
With the fuse INTRC you get Fosc / 4 output on RA6 and I/O on RA7.
With the fuse INTRC_IO you can use both RA6 and RA7 for I/O.

My guess is you want the INTRC_IO setting.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 28, 2007 11:02 am     Reply with quote

I had assumed that you were already using INTRC_IO and so that
you must have some really bizarre problem that was undocumented.
But that's not the case.
jimcbride



Joined: 05 Apr 2006
Posts: 23

View user's profile Send private message

PostPosted: Thu Jun 28, 2007 11:52 am     Reply with quote

Thank GAWD, I was hoping it was me doing something stupid, (ususally is).

I went back and forth so many times with intrc and intrc_io trying to get int internal osc working that somewhere I got them turned around in my head. I had these two backwards in my head.

Thanks for the help gentlemen.
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