📜 ⬆️ ⬇️

Algorithm of energy saving in practice

From the author


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

Foreword


This article is devoted to solving the problem of energy conservation, which was present during the development of the radio module software for the needs of detecting an open / close circuit and obtaining temperature.

What we have



')
A radio module was developed on the “board” of which: the “brain” - atmega128rfa1, with an integrated radio transmitter and an FM75 temperature sensor. The device is powered by the 1st CR2032 battery (3.3 V, ~ 200 mA * h).


Functions that the module performs



Applicability of the module



Problem


Module consumption:

Thus, if you do not turn off the radio transmitter, and do not transmit or receive anything, then the 200 mA batteries should theoretically be enough for 20 hours, in practice, about 16 hours. And if we say that the module needs to perform more, and some functions ?!

We give two examples of the operation of the module: normal and extreme.
Normal operation (intended):

The practical time of the module has not changed significantly and amounted to all the same 16 hours.

Extreme operation, to find a solution to the problem of energy saving and for clarity:

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

There is over there is a significant error in the assessment, because Batteries have a wide run-up capacity from 190 to 250 mA in one batch, but nevertheless, for a rough estimate of the operating time, this is sufficient.

Pursued goals


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

Decision


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

And so, microcontrollers (hereinafter referred to as "MK") have different sleep modes and methods for removing them from these modes.
But , it is important for us that the MC respond to messages from the server! - and this means that the radio transmitter should be turned on - there is a mode when the MC is sleeping, but “listens” to the air for messages for it and wakes up, if there are any, it is not suitable for us, since power consumption on the order of ~ 10 mA.

What to do then ?! After all, in the “deep sleep” mode, the radio is turned off (i.e., the MK will not receive or transmit anything), and it can be taken out of this mode only by a signal from an external interrupt, OR by a “Watch Dog” who is able to work both in the drop mode of the MC, and in the interrupt call mode - that’s what he will save us!

Algorithm

And so, to solve this 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 back to sleep.
3) Since we need, among other things, to execute commands from the server, it is necessary to periodically turn on the radio and listen to the air for messages for the MC. We put the Watch Dog in the interrupt mode with a periodicity of 0.016 to 8 seconds (for our needs, a period of 8 seconds is sufficient). In the interruption we listen to the ether, if there is nothing for MK, then we again go to sleep.

We analyze the items more

Being in a “deep sleep”, the 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 consider self-discharge now.
Then, the time of “life” is affected only by how often points 2 and 3 are fulfilled.
When an external interrupt is triggered at point 2, the MC operates on the order of 20 ms - which can also be ignored in the “normal operation” mode.
Our main consumer of energy is point 3. For our purposes, it is enough for us that the MC responded to the message from the server within 8 seconds. Therefore, we set up a “dog timer” just so that he checks the air once every 8 seconds and scans the air for 20 ms, then falls asleep again. So if there is no signal from point 2 and there are no messages from the server, then our MC works 20 ms in 8 seconds, which translates to 0.0235 mA * hour.
To reach the MC, the server continuously sends packets for it for 8 seconds, the MC responds differently - maybe instantly, or maybe at the end of 8 seconds - but it responds!

Result


Having embodied the algorithm in the code, the module (in general there are several of them) has currently worked for more than 378 days. The remaining capacity on the battery is 40 mA - so it will still work. The mode of operation is more benign than expected in the “normal operation” mode described above - but such is life, preparing for the worst, hoping for the best.

PS


I hope the article will be useful to someone in solving this problem.

Project development


This article has aroused a keen interest in the development of both hardware and software among habrovchan, which I am very happy about. Now I have finished developing a module for one of the projects in Habré - the DIY-dimmer of the “Smart Home” (this interaction is the result of this article).

Source: https://habr.com/ru/post/202400/


All Articles