Energy Saving Algorithm in Practice

From the author


This is my first article - I am waiting for constructive criticism, opinions, comments, questions.

Foreword


This article is dedicated to solving the problem of energy saving, which was present during the development of software for the radio module for the needs of detecting open / short circuits and obtaining temperature.

What do we have




A radio module was developed on board which: the brain is atmega128rfa1, with a built-in radio transmitter and a temperature sensor FM75. The device is powered by the first CR2032 battery (3.3 V, ~ 200 mA * hour).


Functions performed by the module

  • when closing / opening contacts, triggered by an external interrupt - sending event data to the server, with confirmation of receipt;
  • when receiving a command from the server, perform the necessary actions, send the result of the actions taken, receive confirmation of receipt (for the task in question, these actions were to obtain the current temperature, obtain the status of contacts, control the status of the module);


Module applicability

  • as an addition to household motion sensors
  • as a radio button (to turn on / turn on the blessing: it is put into ordinary switches, instead of connecting a break in one of the 220 V wires; there is also a voltage in the network 220 V, when a zero sensor is connected; door position, etc.)
  • for periodically collecting temperature data


Problem


Module consumption:
  • with the included transmitter ~ 9.4 mA
  • with continuous radio data transmission at full power ~ 14 mA
  • with radio transmitter off ~ 5.4 mA
  • when receiving temperature ~ 25 mA
  • in deep sleep mode (power down mode) ~ 200 nA

Thus, if you do not turn off the radio transmitter, and do not transmit or receive anything, then a 200mA battery should theoretically last for 20 hours, in practice, about 16 hours. And if we talk about the fact that the module also needs to perform some functions ?!

Here are two examples of module operation: normal and extreme.
Normal operation (expected):
  • 1 time per hour receiving the current temperature, on request from the server
  • 1 time per hour turning on / off, for example - light (i.e. the module informs the server about the status of the switch responsible for the light)

The practical operating time of the module did not change significantly and amounted to the same 16 hours.

Extreme operation, to find a solution to the problem of energy conservation and for clarity:
  • 1000 times per hour receiving the current temperature, on request from the server
  • 1000 times per hour turning on / off, for example - light (i.e. the module informs the server about the status of the switch responsible for the light)

The practical operating time of the module was a modest 4 hours.

Here it’s over there is a significant error in the assessment, because Batteries have a wide run of capacity from 190 to 250 mA in one batch, but nevertheless, for a rough estimate of the operating time, this is enough.

Pursued goals


It is necessary that the battery-powered module with a capacity of 200 mA in room conditions work for at least a year in normal operation (described above).

Decision


The solution is obvious - the use of sleep modes and not just sleep modes, namely “deep sleep” (power down mode). The algorithm proposed below is applicable for microcontrollers of different manufacturers, therefore only the algorithm (without a code) will be given - it will not be difficult to compose a code using the datasheet of the desired microcontroller.

And so, microcontrollers (hereinafter referred to as “MK”) have different sleep modes and ways to get out of these modes.
But , it is important for us that the MK responds to messages from the server! - and this means that the radio transmitter must be turned on - there is a mode when MK is sleeping, but "listening" to the broadcast for messages for him and wakes up, if any, is not suitable for us, because power consumption of the order of ~ 10 mA.

What to do then ?! Indeed, in the “deep sleep” mode, the radio is turned off (that is, the MK will not receive or transmit anything), and you can get it out of this mode only by a signal from an external interrupt, OR by a “dog timer” (Watch Dog) , which can work both in the MK reset mode and in the interrupt call mode - here it will save us!

Algorithm

And so, to solve the set goal, the following algorithm was developed, debugged and tested:
1) MK is always in the “deep sleep” mode (power down mode).
2) When an external interrupt is triggered (changing the position of the switch), the MC wakes up, sends a message to the server, receives an acknowledgment, and goes to sleep again.
3) Because we need, besides everything else, to execute commands from the server, we must periodically turn on the radio and listen to the broadcast for messages for MK. We put Watch Dog in interrupt mode with a frequency of 0.016 to 8 seconds (for our needs, a period of 8 seconds is enough). In the interruption we listen to the broadcast, if for MK there is nothing, then we go to sleep again.

Let's analyze the items in more detail

Being in a "deep sleep", MK consumes ~ 200 nA (if there were no self-discharge of the battery, then 200 mA would be enough for many ... years). We will not take into account self-discharge now.
Then, the “life” time is affected only by how often items 2 and 3 are fulfilled.
When an external interrupt is triggered at item 2, the MC operates on the order of 20 ms — which can also be ignored in the “normal operation” mode.
Our main energy consumer is point 3. For our tasks, it is enough for us that the MK responds to a message from the server within 8 seconds. Therefore, we set up the “dog timer” in such a way that it checks the broadcast every 8 seconds and scans the broadcast for 20 ms, then falls back into sleep. T.O. if there is no signal from point 2 and there are no messages from the server, then our MK works for 20 ms in 8 seconds, which translates into 0.0235 mA * hour.
To reach the MK, the server continuously sends packets for it for 8 seconds, the MK responds differently - it can be instantly, or maybe at the end of 8 seconds - but it answers!

Result


Having implemented the algorithm into code, the module (in general there are several) has currently worked for more than 378 days. The remaining capacity on the batteries is 40 mA - so what else will work. The operating mode is really more sparing than it was assumed in the “normal operation” mode described above - but such is life, preparing for the worst, hoping for the best.

PS


I hope the article is useful to someone in solving a similar problem.

Project development


This article aroused keen interest in the development of both hardware and software among the Habrovsk citizens, which I am extremely happy about. Now I have finished developing the module for one of the projects on the hub - the DIY-dimmer of "Smart Home" (this interaction is the result, of this article).

Also popular now: