Page 1 of 1

PIC12F629- How to go to SLEEP?

Posted: Mon Apr 02, 2007 1:54 pm
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

Posted: Mon Apr 02, 2007 3:48 pm
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.

Posted: Mon Apr 02, 2007 4:28 pm
by mjs7770
Thanks Ben,

That was fast and easy

Best regards,

Michael

Re: PIC12F629- How to go to SLEEP?

Posted: Thu Feb 07, 2008 12:38 pm
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.

Re: PIC12F629- How to go to SLEEP?

Posted: Thu Feb 07, 2008 1:13 pm
by Benj
Hello

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

sleep();

Re: PIC12F629- How to go to SLEEP?

Posted: Thu Feb 07, 2008 1:24 pm
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

Re: PIC12F629- How to go to SLEEP?

Posted: Thu Feb 07, 2008 1:45 pm
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.

Re: PIC12F629- How to go to SLEEP?

Posted: Fri Feb 08, 2008 12:24 pm
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 ?

Re: PIC12F629- How to go to SLEEP?

Posted: Fri Feb 08, 2008 2:56 pm
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.