Page 1 of 1

Need help with "Sleep mode"

Posted: Thu Apr 10, 2008 9:04 am
by Andi
Hi!
I want to do the following:

i want to check a device if an error occured or not...
this should last for about 20minutes...
when the 20 minutes are over the pic18F1320 should be set into sleep mode
this sleep mode should last for 6hours
then the pic should wake up and check again the device

I don't have any clue how to work with sleep mode and the timer/interrupts...
Can somebody help me to get this working please?

regards, andi

Re: Need help with "Sleep mode"

Posted: Thu Apr 10, 2008 9:26 am
by Benj
Hello Andi

Sleep mode can be activated in Flowcode by using a C code icon with the following line of code.

sleep();

For help waking up the device please refer to the device datasheet. Also searching Google for "PIC sleep project" will also probably help a lot.

Re: Need help with "Sleep mode"

Posted: Thu Apr 10, 2008 11:21 am
by Andi
isnt it possible to let the pic sleep for a specific time?
something like this :
sleep(3600); //sleep 3600 seconds

Re: Need help with "Sleep mode"

Posted: Thu Apr 10, 2008 11:30 am
by Steve
To do this, you would need to set the PIC to wake up periodically using the TMR1 interrupt. If the 6 hours are not up, then immediately go back to sleep.

You can set TMR1 to work using an external crystal. With the correct value, an appropriate timer period can be used to give an interrupt each whole number of milliseconds, which should mean you can gey a fairly accurate 6 hour period.

Note that your PIC may need to wake up many times each second and then go back to sleep. But the power saving should be great in this case as the PIC will be fully powered for only a fraction of the total time.

More details can be found in the relevant PIC's datasheet under the "Sleep" and "Timer1" sections.

Re: Need help with "Sleep mode"

Posted: Thu Apr 10, 2008 3:15 pm
by Andi
is this also possible if i use Timer0?
i ask this, because if it is possible, i can use the programm in the flowcode examples (digital clock)

Re: Need help with "Sleep mode"

Posted: Thu Apr 10, 2008 3:29 pm
by Steve
Unfortunately not. The PIC can be woken up by various interrupts (see the datasheet for the device you are using), but timer0 is not one of them.

There have been some discussions on this forum about setting up timer1 in the FCD file so it can be used in a similar way to timer0. There may help.