As a Flowcode 6 user I developed a program for the PIC12F683, that must wait a few hours (variable) before continuing.
So far I used the delay(60) seconds for 1 minute delay in an while loop of 240 (for 240 minutes or 4 hours). THis works fine.
However, the full current consumption continuous (1 MHz clock) during this long delay. Almost 250 microAmp at 3.6 Volt.
So I want to replace the delay of 60 secondes with a sleep of 60 seconds. I expected to be allowed to use a C code 'sleep(60);' Then current consumption should drop dramatically, increasing battery life substantially.
However I understand now that live may not be that simple. On the web I can not find any solution for this.
I hope someone can tell me how to solve it.
Sleep instead of Delay
Moderator: Benj
- 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: Sleep instead of Delay
Hello,
As far as I am aware you put the device to sleep and then use a trigger to wake the device back up. The trigger could be a low power enabled timer or an external pin change etc.
The C function to put the device to sleep is like this:
The device datasheet should detail what options you have to wake the device on your specific microcontroller.
As far as I am aware you put the device to sleep and then use a trigger to wake the device back up. The trigger could be a low power enabled timer or an external pin change etc.
The C function to put the device to sleep is like this:
Code: Select all
sleep();
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Sleep instead of Delay
I figured out that sleep() lasts 1.21 sec (clock speed 1 MHz). So when I put this in a while loop (49x times round), then I have 59 seconds sleeping effectively, as I measured. Adding after the while loop a small correction delay of almost 1 sec., yields this altogether the 1 minute as wanted.
I think I 'll stick with this work-around.
But what determines the 1.21 sec sleep-interval? I can find it on the web.
I think I 'll stick with this work-around.
But what determines the 1.21 sec sleep-interval? I can find it on the web.
Re: Sleep instead of Delay
In the circuit the current consumption during sleep interval remains unmodified and the same as when outside the sleep interval.
Can someone tell me what I may be doing wrong?
Can someone tell me what I may be doing wrong?
Re: Sleep instead of Delay
In other words:
My concern is that if I add in the flowcode-6 program diagram inside a while loop the C-code sleep(); , I have to do some other settings first before actually the power consumption goes down during each sleep().
Perhaps the datasheet gives (hidden?) some clues about this issue. I keep studying, but perhaps someone has solved already this?
My concern is that if I add in the flowcode-6 program diagram inside a while loop the C-code sleep(); , I have to do some other settings first before actually the power consumption goes down during each sleep().
Perhaps the datasheet gives (hidden?) some clues about this issue. I keep studying, but perhaps someone has solved already this?
Re: Sleep instead of Delay
To support my posts just before, I herewidth add a portion of the Flowcode-6 diagram showing how the sleep() C-code is inside the while loop.
- Attachments
-
- sleep in flowcode while loop.jpg (9.08 KiB) Viewed 5614 times
Re: Sleep instead of Delay
I forgot to mention in my last post with the diagram that in the start of the program is added:
option_reg = option_reg | 0b00001111; //Configure watchdog to 1:128 Postscaler
wdtcon = 0b00000111; //Configure watchdog 1:256 (from Benj)
osccon = 0x45;
There is no further C-code in the program.
option_reg = option_reg | 0b00001111; //Configure watchdog to 1:128 Postscaler
wdtcon = 0b00000111; //Configure watchdog 1:256 (from Benj)
osccon = 0x45;
There is no further C-code in the program.
Re: Sleep instead of Delay
I found my error: the peripherals were not switched off before the sleep() started.
Now I indeed measure some 30 microAmp current consumption during sleep(). And with the while loop I can make effectively very long sleep periodes.
Sorry for bothering you all with my stupidity.
Now I indeed measure some 30 microAmp current consumption during sleep(). And with the while loop I can make effectively very long sleep periodes.
Sorry for bothering you all with my stupidity.