Need help with "Sleep mode"

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
Andi
Posts: 19
Joined: Thu Nov 29, 2007 12:08 pm
Contact:

Need help with "Sleep mode"

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Need help with "Sleep mode"

Post 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.

Andi
Posts: 19
Joined: Thu Nov 29, 2007 12:08 pm
Contact:

Re: Need help with "Sleep mode"

Post by Andi »

isnt it possible to let the pic sleep for a specific time?
something like this :
sleep(3600); //sleep 3600 seconds

User avatar
Steve
Matrix Staff
Posts: 3426
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: Need help with "Sleep mode"

Post 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.

Andi
Posts: 19
Joined: Thu Nov 29, 2007 12:08 pm
Contact:

Re: Need help with "Sleep mode"

Post 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)

User avatar
Steve
Matrix Staff
Posts: 3426
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: Need help with "Sleep mode"

Post 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.

Post Reply