PIC12F629- How to go to SLEEP?

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

Moderators: Benj, Mods

Post Reply
mjs7770
Flowcode v5 User
Posts: 15
Joined: Mon Apr 02, 2007 1:11 pm
Location: Australia

PIC12F629- How to go to SLEEP?

Post by mjs7770 »

Can someone help me with SLEEP? I am losing a lot of it over this problem.':cry:'

Is there a command in Flowcode 3 to put my PIC12F629 to SLEEP by software?
I would like to be able to put it to SLEEP at a few places in the code and was wondering how to do this. I cannot find anything in the Help and the only reference to SLEEP in the Forums is to "wanted features in Flowcode 3".
If it has to be done by inserting C code, can anyone guide me as to what to write. (I am an old Fortran programmer and don't know any C).

On a similar note, a normal Flowcode program has a "BEGIN" and an "END". Does the "End" constitute SLEEP or is it something else?

Basically I want to run the PIC12F629 from batteries, and use an Input Switch to WAKE it up and also Input to the program, and then later, using the same Input switch, send the PIC12F629 to SLEEP.

Any help is appreciated.
Best regards,

Michael

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:

Post by Benj »

Hello

The sleep command in C is

Code: Select all

sleep () ;
You then wake up from sleep mode by triggering an interrupt eg a switch connected to RB0.

You must make sure that the relevant interrupt is enabled before you enter sleep mode or you will not be able to wake the device back up.

mjs7770
Flowcode v5 User
Posts: 15
Joined: Mon Apr 02, 2007 1:11 pm
Location: Australia

Post by mjs7770 »

Thanks Ben,

That was fast and easy

Best regards,

Michael

pic-newbie

Re: PIC12F629- How to go to SLEEP?

Post by pic-newbie »

Having a problem with the Sleep command. Attempting to get the device to go to sleep at the end of the program, however adding a C object with..

SLEEP () ;

doesn't seem to work, just get unknown identifier errors during C compilation.

Do I have to add anything to the suplimentary code window, or am I missing something else.

Thanks again all.

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: PIC12F629- How to go to SLEEP?

Post by Benj »

Hello

C code is case sensitive, try retyping the command in lower case.

sleep();

pic-newbie

Re: PIC12F629- How to go to SLEEP?

Post by pic-newbie »

:oops:

Well dont I feel like an idiot :) Could have sworn I tried it with both. Working fine now. Cheers again Ben

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: PIC12F629- How to go to SLEEP?

Post by Benj »

:lol: No problem everyone has these difficulties at some point.

In fact its nearly always something simple that leaves us scratching our heads.

Let me know if you have any further problems.

pic-newbie

Re: PIC12F629- How to go to SLEEP?

Post by pic-newbie »

One more question :)

The device is going to sleep fine (running on a 12F629), but waking it up is proving more of a challenge. We're using the reset button to start the program running, but once the device has gone to sleep, that input doesn't seem to wake it up there after. Is there a simple way of having the device wake up and start the program again on the pressing of the one button ?

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: PIC12F629- How to go to SLEEP?

Post by Sean »

Hello,

If the RESET pin is not bringing the chip out of sleep mode it is possible that it has been configured as general purpose i/o. This can be changed in the Chip->Configure menu in Flowcode. The 'Master Clear Enable:' option should be set to 'External' to enable the RESET function.

Waking the chip with a RESET will cause the program to start from the beginning again. The use of the GP2/INT pin will allow the device to continue operation from where it was put to sleep (the pin must be configured as an input). If interrupts are enabled the device will execute the interrupt service routine, otherwise it will continue with the main program.

Post Reply