📜 ⬆️ ⬇️

STM32. Lose weight practice or controller diet



What kind of nonsense, some readers will probably think when they see the title of the publication. Is the author wrong about the resource? Or was it planned to be placed in the Health Geek hub? And they will be partly right, but only partly ... Under the cut, we will discuss the method of reducing and optimizing the energy consumption of electronic devices.


Some time ago I got into the hands of the X-NUCLEO-LPM01A board , which lay idle for the time being, until I decided to study the energy consumption of a single self-powered device under design.



This board was developed by STMicroelectronics and is positioned as "Power shield, Nucleo expansion board for power consumption measurement". I did not find an explanatory Russian-language description on the network for working with this devkit and decided to figure it out myself, and at the same time share information with the respected habro-community.


If you select the main one, the expansion board is a programmable power supply from 1.8 to 3.3 volts with the ability to measure load current in real-time (in dynamic mode up to
50 mA) with a sampling frequency of up to 100 KHz. The device can operate both autonomously and as part of a software and hardware complex. The STM32Cube MonitorPower utility is used to graphically display the measured values. This software also allows you to set all the necessary parameters and process on the occurrence of an event (trigger start). X-NUCLEO-LPM01A is sharpened to work with Nucleo-32 (64, 144) boards, Arduino Nano (Uno), for this, the corresponding shields are placed on it, but there is a possibility of working with arbitrary boards. The photo below shows the connection of the device under study to one of the connectors on the board.




In addition to the application software, X-NUCLEO-LPM01A supports command mode, in which any terminal program should work. (Here I think I got a little overwhelmed , HTerm wound up with a half-kick, but with my favorite ZOC I had to mess a bit). And, judging by the description, due to the use of the VCP driver, the device can pour data into the COM port at a speed of up to 3686400 baud. Such a high speed is ensured in particular by transmitting a binary data stream (for sampling frequencies above 50 KHz), for ASCII characters the speed is slightly lower.


More specifically, the task that I will try to solve with X-NUCLEO-LPM01A is:

  1. Get information on the dynamic power consumption of the components of interest in the designed product using the trigger launch of X-NUCLEO-LPM01A in the studied areas of the program code.

  2. In the process of continuous operation of the device to organize the accumulation of the necessary fragments for subsequent generalized analysis.


The screenshot below shows the current consumption log of the SD card during data recording.



')

STM32Cube MonitorPower allows not only qualitatively, but also to quantify the power consumption of the device under study. In the lower part of the picture, the minimum, maximum, average values ​​of current consumption and the integrated value of energy are given. Such data are available both for the whole measurement and for the selected fragment.


In the User manual, it is noted that the trigger measurement is triggered by an impulse on the foot of the D7 Arduino Shield. As it turned out, only a one-time process start followed by continuous recording works. The attempt to organize the start-stop mode of current registration (on both fronts of the pulse) did not succeed. That is, once having started recording in the right place on the rising front, it is impossible to slow down the process with a falling front of the pulse. And this is not exactly what I expected to receive from this device.


Fully controlled start-stop mode can be set using a sequence of commands from the terminal program.

team

description

htc

host control capture

volt 3300-03

supply voltage on the measured channel 3300 mV

acqtime 0

continuous measurement without time limit

freq 10,000

sampling frequency 10 kHz

start

the beginning of measurement

...

froze (data pour in terminalku)

stop

end of measurement


The problem is that this is a manual control that is not synchronized with the events in the target controller. You can certainly try to form the specified sequence of commands on the side of the device under investigation, not on the host, but then the output data stream from the X-NUCLEO-LPM01A will also be poured into the controller and it is not clear what to do with them, and redirecting the output to somewhere else ( although there are UART Tx, Rx pins on the board, they are listed as "reserved" in the manual and, probably, are not involved in the current firmware version). I got out of this situation as follows:


The following command sequence is formed on the host (computer) side.

team

description

htc

host control capture

volt 3300-03

supply voltage on the measured channel 3300 mV

acqtime 1

measurement duration
(you can use a range from 10 microseconds to 10 seconds)

trigsrc d7

synchronization of the beginning of measurement with the growing front
pulse on pin D7

freq 10,000

sampling frequency 10 kHz

start

the beginning of measurement

...

measurement (data starts at the front of the pulse and stops
crumble after the time specified in acqtime)


Now the data will be recorded "in batches", and not in a continuous stream. This approach allows you to explore the consumption of the scheme in different places of the program and at different intervals of time that are far enough from each other. That is, if there is a need to collect information on the power consumption of a device that works for an hour (day, week), you do not need to write a continuous stream, and even with the maximum sampling rate, and then understand this porridge, you just need to provide the above described algorithm of work. And if the terminal program writes time markers to its log, as shown in the picture below, then parsing the chronology of events on such a file will be quite simple.




It's like a DVR with a motion detection record and time stamps.


Let me give you a couple of screenshots obtained using the X-NUCLEO-LPM01A . The first is the controller's power consumption while reading data from the integrated ADC. 32 values ​​are read from a 4 kHz timer interrupt and stored in memory.




On the second - a similar reading and saving data, but only the controller "allows itself to sleep" after each measurement, before the occurrence of the next timer interruption, using one of the available power saving modes.




Immediately, a significant delta in the current consumption during the measurement, ~ 6 mA, is noticeable. These two examples do not pretend to optimize the power consumption of low-power devices, but only demonstrate the capabilities of the X-NUCLEO-LPM01A , which is capable of measuring currents from 1 nA.


In conclusion, I will say that, in my humble opinion, this device seems to be quite a suitable tool that can take its rightful place next to an oscilloscope and a logical signal analyzer on an embedder table. And the use of the described approach will allow not only to “moderate the appetites of the controller” when developing devices that are critical for power, but also to better understand the dynamics of the processes in diverse power saving modes actively used by developers of modern electronic devices.


The cost of the board is somewhat clouded by the picture's iridescence - more than 7,000 rubles, but is such an insignificant sum for modern times, the amount will be able to stop a real geek from the possibility of owning this wonderful girlfriend?


PS Despite the indication in UM that the UART is reserved for future applications, I still stuck at it and found that it lives as a second interface (I / O is duplicated from the VCP) at a speed of 921600 8N1 and can be used as a command one, forming start and stop to start - the end of the measurement. The disadvantage of this approach will be the obligatory availability of a free UART on the side of the controller under study, not to mention the fact that 921600 baud is often impossible at low clock frequencies.


PPS After writing the article I noticed the difference in the last pictures ~ 2 mA at the entrance to the measurement and at its end. Probably I didn’t turn off ADC clocking, or left the timer to work, but this is already, as Leonid Kanevsky likes to say: "a whole different story" ...


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


All Articles