SLEEP period

Period - is a variable/constant which specifies the duration of sleep in multiples of 2.3 seconds (1-65535).


Sleep for some period (multiples of approximately 2.3s (2.1s on X1/X2 parts)).

The sleep command puts the microcontroller into low power mode for a period of time. When in low power mode all timers are switched off and so the pwmout and servo commands will cease to function. The nominal period is 2.3s, so sleep 10 will be approximately 23 seconds. The sleep command is not regulated and so due to tolerances in the microcontrollers internal timers, this time is subject to -50% to +100% tolerance. The external temperature affects these tolerances and so no design that requires an accurate time base should use this command.

Shorter 'sleeps' are possible with the nap command (where supported). Some PICAXE chips support the disablebod (enablebod) command to disable the brown-out detect function. Use of this command prior to a sleep will considerably reduce the current drawn during the sleep command.

On non-X2 parts the command 'sleep 0' is ignored. 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. The chip will not respond to new program downloads when in permanent sleep.

On M2 parts the 'time' variable will not increment while a 'sleep' command is being executed.

Effect of increased clock speed:

The sleep command uses the internal watchdog timer which is not affected by changes in resonator clock speed.

Applies To:
See Also:
Related Create:

    Flash an LED

    Slowly flash a LED on and off while conserving power

    Code Example:
    main:	high 1		; switch on output 1
    	sleep 10	; sleep for 23 seconds
    	low 1		; switch off output 1
    	sleep 100	; sleep for 230 seconds
    	goto main	; loop back to start
    Copy Code Submit an Example

    Submit Your Own Code!

    You must be logged in to submit code examples. Login now.