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

PIC 10F sleep, wake on pin change

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



Joined: 17 Oct 2005
Posts: 28
Location: Hampshire, UK

View user's profile Send private message

PIC 10F sleep, wake on pin change
PostPosted: Fri Dec 16, 2005 6:13 am     Reply with quote

Hi all,

I am trying to use the sleep() feature in a PIC10F206. It's the difference between 200ua and 40ua!
I've never used sleep before, and the examples from colleagues are ones where a CPU picks up after where the sleep was instigated.

I am using the sleep thus:
Code:

void main(void)
{   
   BYTE WakeupCause;

   // Find out why we have started. We want to know if it was a regular,
   // periodic WDT or a pin change during sleep - which is the one we are
   // really interested in
   //
   WakeupCause = restart_cause();
   
   // Initialise the system
   InitSystem();
       
   // Kick watchdog.
   restart_wdt();
   
   if ( 
         ( WakeupCause != WDT_FROM_SLEEP        ) &&
         ( WakeupCause != PIN_CHANGE_FROM_SLEEP )
      )
   {
      // Take the current trigger inputs as the current defaults.
      GetInputTriggerDefaults();
   }
   
   while ( TRUE )
   {       
      // 1ms 'tick'. Absolute timing is not critical. This gets close enough.
      delay_us(900);
     
      // Timer counts are 16-bit, so overflow at 65s
      Trig1Timer++;   
      Trig2Timer++;           
     
      // Process state machines for the two trigger inputs.
      Trig1StateMachine();
      Trig2StateMachine();
     
      // Use values calculated in state machines to set the outputs.
      SetTriggerOutputs();   
       
      // Kick watchdog.
      restart_wdt();
     
      if ( ( Trig1State == QUIESCENT ) && ( Trig2State == QUIESCENT ) )
      {
         sleep();
      }
   };
}

But if I do this it never wakes up on a pin change (I have set PIN_CHANGE_FROM_SLEEP !). I get a periodic WDT glitch every ~3s too, which I don't want!

Any ideas?

TIA

Nige
_________________
No comment! (Can't think of anything interesting to say!)
Brian S



Joined: 06 Sep 2005
Posts: 13

View user's profile Send private message

Sleep/Wake
PostPosted: Fri Dec 16, 2005 9:16 am     Reply with quote

Please repost your code using the "Code" button;
it makes it much easier to follow.

Including all code - Includes, Fuses, Devices etc,
as well as variable declarations and non-included isr's.

Thanks!
Guest








PostPosted: Fri Dec 16, 2005 9:31 am     Reply with quote

Check out Microchip's TB082 (http://ww1.microchip.com/downloads/en/DeviceDoc/91082A.pdf) which covers the Reset and wake-up conditions for the 10F devices.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 16, 2005 1:31 pm     Reply with quote

Quote:
But if I do this it never wakes up on a pin change
(I have set PIN_CHANGE_FROM_SLEEP !).

I don't see this in your code. The GPWU bit which enables this mode
is in the OPTION register. You need to post the InitSystem() function so
we can see your init code. i.e., Did you disable the comparators, etc. ?

Also, the data sheet says that you must read the GPIO port
before entering sleep, if you want to wake-up on change.
You're not doing this.
Quote:
Note:
Caution: Right before entering Sleep,
read the input pins. When in Sleep, wake-up
occurs when the values at the pins
change from the state they were in at the
last reading. If a wake-up on change
occurs and the pins are not read before
re-entering Sleep, a wake-up will occur
immediately even if no pins change while
in Sleep mode.
aopg64



Joined: 17 Oct 2005
Posts: 28
Location: Hampshire, UK

View user's profile Send private message

PostPosted: Fri Dec 16, 2005 5:12 pm     Reply with quote

Hi Guys,

Thanks for the help so far! I'm back at home now, so it'll be Monday before I can give the ideas a go:

1) Sorry about the listing - I'm fairly new to the forum Embarassed
2) I didn't want to include 'all' the code. It's longwinded enough as is! But, yes, I can see that some of it might be relevant!
3) Yes, I have disabled the comparators! That took me 1/2 of Thursday to discover that one! Mad
4) Fuses (if I remember rightly!): WDT, NOMCLR, NOPROTECT.
5) WDT (if I remember rightly!): setup_wdt(2304ms | DISABLEPULLUPS | PIN_CHANGE_ON_SLEEP)
6) Naively, I assumed my reads in my state machines would do the read of the port... Embarassed
7) No isrs() of any kind in this code.
8) It's basically a glitch stretcher to correct a design error before we can re-spin a board. The 10F has the necessary two inputs and outputs we need and will fit into a very small space. We just want to catch any >100ms pulse (effectively a debounce) of either polarity and assert a level for another PIC to see within the next ten seconds. After that, the 10F takes the new level of the line as the new default.
9) For the re-spin we may try to use another PIC, low-power is the priority. The other two are running at 100kHz, so 4MHz is a sledgehammer to crack a nut! One with enough I/O (2 in/2 out) and an external RC clock we can run at 100kHz (or less!) would be fine. Any ideas, guys? Very Happy
10) I've got a non-sleeping 200uA version we can use for the first versions if I can't get it sorted, so the boss won't fire me (yet), but I can see that learning to use the sleep() on various other PICs is going to be a very relevant topic for me in the next 6 months!
Guess I'll have a read up on setting this GPWU bit and doing the GPIO read this weekend!
Sorry kids, no presents this Xmas! Daddy had to read up about PICs last weekend instead of doing the gift buying! Sad

Only joking! No kids! Laughing

Thanks guys,

Nigel
_________________
No comment! (Can't think of anything interesting to say!)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 16, 2005 5:17 pm     Reply with quote

Quote:
Guess I'll have a read up on setting this GPWU bit and doing the GPIO read this weekend!

Look at this thread on the set_options() macro, which is an easy way
to set the OPTIONS register.
http://www.ccsinfo.com/forum/viewtopic.php?t=23899
aopg64



Joined: 17 Oct 2005
Posts: 28
Location: Hampshire, UK

View user's profile Send private message

PostPosted: Mon Dec 19, 2005 5:14 am     Reply with quote

Hi Guys,

I tried setting the Options register with this method, as well as looking at the compiled listing for comparisons.

What was meant to be a 1-day quick-fix is now in day 4, so I am giving up on the low-power and going for the 200uA option which works.

Having originally chosen the wrong combination of pins in the middle of last week (I only later realised GP3 was input only!), it seems that my latest choice was also non-ideal! Confused
I still got the glitch when I tried the sleep and wake-on-change. It still didn't work and then I realised I couldn't use GP2 for wake-on-change anyway!

Disaster-limitation means that I will use what I've got that works and maybe tweak it later when the initial panic is over!

So, thanks for your help so far guys, I will revisit this in the New Year, and hopefully do a new version for later revised models. What I really need is an example 10F program using sleep to see how it's done properly!

Merry Xmas and a Happy New Year!
Wink

Nige
_________________
No comment! (Can't think of anything interesting to say!)
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