how to sleep and re awaken on a given condition??

does anyone know if it is possible to put picaxe in a low power mode using sleep or nap or something else, but to come back to normal power when a certain condition occurs. Like a button press for example.
Looking in the picaxe manual I cant see if this is possible as all the commands use a timer to wake up again.
 

srnet

Senior Member
Did you see this bit in the description of the Sleep command ?

"On X2 parts ‘sleep 0’ puts the microcontroller into permanent sleep - it does not
wake every 2.1 seconds. The microcontroller is only woken by a hardware
interrupt (e.g. hint pin change) or hard-reset."
 

kranenborg

Senior Member
An alternative way is to set the microcontroller's frequency to the lowest value possible, which is 32kHz based on the internal LP oscillator and -to decrease the power consumption even more - to use the DISABLEBOD command. This can be done using the SETFREQ k31 + DISABLEBOD command sequence and is applicable to all M2 and X2 controller types. Furthermore, it is important to tie any unused input with a resistor to ground (or alternatively declare any output-capable non-connected pin as an actual output).

Measurements that I did a long time ago indicated that power consumption is then reduced to a value similar to the use of the sleep command. The advantage of this approach is that the controller is still "alive" and fully functional (albeit extremely slow, executing in the order of 10 BASIC instructions per second) and thus being able to act on a certain input condition. You could implement a loop and then poll an input pin (or use interrupts, since that works also).


Due to the slowness of execution at 32kHZ the input trigger condition needs to persist some time in order to be always noticed. If the input condition is changing very quickly (i.e. a very short pulse) you may miss it at times, but then the latch available on the M2 devices may come to help (the latch is essentially a memory bit that can be controlled by both hard- and software). In another project I made a fast-spike detector where the spike sets the latch. The latch output pin is then connected to an input pin where the signal can be noted and acted upon. For inspiration to such a setup, see my first entry ("fast spike detection") in the following link: http://www.kranenborg.org/electronics/10-picaxe-and-zbasic-code-contributions (in your case the input signal could drive the latch directly, no comparator needed).

Best regards,
Jurjen
http://www.kranenborg.org/electronics
 
Last edited:

kranenborg

Senior Member
In my post #4 I added the DISABLEBOD command suggestion as well as avoiding unconnected inputs, in order to get the truly lowest possible current consumption

/Jurjen
 
Top