Autres articles / Other articles

Sleep mode on ARDUINO cards

published: 22 December 2020 / updated 22 December 2020

Lire cette page en français

 


SLEEP mode

ARDUINO cards incorporate a micro-controller. This micro-controller, when it works normally consumes some current. Here is the assembly made to measure consumption an ARDUINO NANO card:

The ARDUINO NANO card is powered in two ways:

On the photo, we derive the power supply  +5V  towards a milliAmperemeter.

The  +5V  power supply is taken from a power supply stabilized (on the right in the photo above).

We activate this power supply, then we connect the milliAmperemeter. The ARDUINO NANO card lights up and the milliAmperemeter display shows 18.3 mA.

Activating IDLE

The idle sleep mode is the only mode available with FlashForth. Here is a very simple definition to use this mode:

: myBoot ( ---) 
    ei  idle ; 

This definition can only be entered with the ARDUINO NANO card connected to the USB port of the PC and via the terminal.

If you run myBoot, nothing seems to happen. However, the ARDUINO card is switched to sleep mode.

In order to measure the correct execution of idle which is in the definition of myBoot, it must tell FlashForth to run myBoot at startup:

' myBoot is turnkey 

We unplug the USB port. Turn the stabilized power back on, then prepare for perform a new current measurement with our milliAmeter.

As soon as the milliAmpeter is connected, the ARDUINO NANO card turns on, the current measurement reads 18.3 mA for about a second, then changes to 11.8 mA!

The LED which indicates that our ARDUINO NANO card has been switched on correctly remains on.

The ARDUINO NANO card will exit IDLE mode as soon as it is requested by:

The IDLE sleep mode in C language:

LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART0_OFF, TWI_OFF);

The different sleep modes

As we have seen, the sleep mode idle brings back the current consumption from 18.3 mA to 11.8 mA, i.e. 6.5 mA, i.e. a gain in consumption of 30%. We can do better, but that's not the subject of our article.

The different sleep modes are controlled by the SMCR register (Sleep Mode Control Register) whose structure is as follows:

7654 3210
-------------------- SM2SM1SM0SE

Bit b0, marked SE (Sleep Enable) authorizes sleep mode if its content is 1.

The other bits SM0, SM1 and SM2 are used to select a sleep mode:

SM2SM1SM0Sleep Mode
000Idle
001ADC Noise Reduction
010Power-down
011Power-save
100Reserved
101Reserved
110Standby
111External Standby

Note: 1. Standby mode is only recommended for use with external crystals or resonators.

On the ATmega328P, Idle mode is the only sleep that leaves interrupts enabled AND the USART running. This means you can wake up out of IDLE mode just by sending a char to the USART.

For all other sleep modes, you must either use reset or provide some kind of timed or external event to wake up the USART won't work.

For those who would like to drastically reduce the current consumption of their ARDUINO card NANO, here is a video that explains some manipulations:

Attention: in the video, you can remove the current regulator. If you do, you will be forced to supply your ARDUINO NANO card with a current source having a voltage strictly between 3.5 and 5.5 Volts!

Marc PETREMANN