Low power uC with ADC - Page 1
Forum section: electronics / beginners

author: Godzilla
author_rank: Contributor
timestamp: October 14, 2021, 02:05:06 pm
content: Hello guys, im trying to build a simple board that has to be supplied by 2 AA batteries, so i was looking for a suitable low power microcontroller. I want the batteries to last as much as possible (1yr min) and the micro will only turn on once every hour for as little time as possible. The micro must have an ADC, i dont need fancy stuff like tons of channels or high resolution, but i need to read voltage on a couple of sensors on the board. Do u have any suggestions?

author: Kleinstein
author_rank: Super Contributor
timestamp: October 14, 2021, 03:30:45 pm
content: 2 AA cells could provide some 2.4 to 3.2 V. Some µCs are OK to directly run from this.With some 2000 mAh and some 10000 hours one would have an average current available of some 0.2 mA. For a low power µC this is a lot, when most of the time in a standby mode.It would start to get a little challanging if you have power from a little LI coin cell with maybe 20 mAh and thus 2 µA total.So take your choice of a reasonable modern 8 bit µC. This cold be STM8 , AVR, PIC16, PIC18, some 8051 variants or MSP430. They should all work.

author: ledtester
author_rank: Super Contributor
timestamp: October 14, 2021, 04:31:26 pm
content: The main techniques for lowering microcontroller power consumption are:- put the microcontroller in sleep mode as much as possible- use a lower clock frequency (even 32 KHz when you can)- turn off peripherals (timers, adc, ...) when they are not needed; this includes off-chip devices- run directly from the battery or use a voltage regulator with a low quiescent currentThis video is targeted at AVR microcontrollers but the ideas apply equally well to other devices:Atmel: picoPower Labs - Basic Power-Saving Techniques -- Microchip Makeshttps://youtu.be/bdWV-tOTVSE

author: Godzilla
author_rank: Contributor
timestamp: October 14, 2021, 04:56:32 pm
content: Quote from: Kleinstein on October 14, 2021, 03:30:45 pmI've found the STM8AL31E88TCY that seems to have everything that i need, do i need decoupling caps even if i run them directly from battery? If yes, do i need them for every rail (VDD1,VDD2, etc..)?Quote from: ledtester on October 14, 2021, 04:31:26 pmThe micro will stay on sleep almost all the time. Im gonna use it with the lower clock possible. I may need to turn it on with a timer interrupt unless it has other fancy features for the wake up. It will run directly from battery.

author: DavidAlfa
author_rank: Super Contributor
timestamp: October 14, 2021, 06:16:09 pm
content: Yes, decoupling caps are a must, they compensate high frequency current transients, a battery has internal resistance, the traces also add impedance, specially at high frequencies.Just 1uF+100nF will do the job for a low current mcu, costing close to nothing.It'll probably work correctly without them, but some day you'll find a strange bug causing data corruption, lockups, random resets...Definitely, you don't want that to happen onceyour product was shipped, causing 1000s of RMAs and lots of losses.Read the datasheet for the AC characteristics.The MCUs have static current consumption + dynamic depending on the frequency of operation.Usually, there's a sweet spot where the best performance and consuption is achieved.Checking thedatasheet, 16Mhz has the most efficient speed/power ratio.So, run the code as fast as you, and for any delay, instead of waiting, start a timer and set the core in the lowest power mode until the timer wakes it.That way it'll be extremely efficient.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: October 14, 2021, 08:00:11 pm
content: Definitely use decoupling capacitors.Your uC may seem to work without it, but it increases the chances of hard to debug "weird" things.Sleeping for a year on two penlights and doing a bit of simple work every hour is a relatively simple task for most microcontrollers.If you design really carefully you may get 3, maybe even 5 or more years out of your penlights.Some modern microcontrollers go as low as a few hundred nA while still being able to do useful work. If you really want to hunt the average power consumption down, it becomes an art. Often a higher clock frequency can get things done quicker, and putting your uC to deep sleep sooner, so the average power consumption goes down, but running at 20MHz while waiting in a loop until your ADC has done a conversion is counter productive. You can put it in a low(-er) power mode during such waits, but crystals have long startup times and this may become a noticeable factor.In the lowest power down mode, usually all clocks are stopped, and a microcontroller can not wake itself anymore. You will need to keep at least some kind of timer running.You also have to consider all external circuitry carefully. Radio's often have high (peak) currents, and quickly become a dominant factor. For ultra low power, the leakage of even an electrolytic capacitor may be dominant. External IC's, often have a "power down" mode, but may still use too much current when powered down. Current leakage though a BJT used as a power switch may be smaller then though a MOSfet, and both are highly temperature dependent.And when choosing a microcontroller family you have make a lot of other choices too. Personally I do not touch any microcontroller if it does not run GCC. (Maybe SDCC is acceptable for some projects if the uC is already chosen in a pre-existing project).For some microcontroller families you need an EUR100 programmer, while for some others you can buy a programmer for a handful of pennies. How important are such costs to you?Another important factor is how much effort you want to put into a single project? If you're satisfied with a year of battery life, you can choose a controller based on a big family, so you can use similar microcontrollers for all your other projects. If you want to go to 5+ years, you do not have that luxury and must select on low power consumption.Accurate power measurement is a must during development and this also becomes more cumbersome for very low current measurements.A simple & cheap way to measure current is to put a shunt resistor in the power line (For example 10k will have 100uA/volt), and then put a silicon diode in parallel. Below approx 200mV leakage through the diode won't be too big (but highly temperature dependent). This gives you a relatively high resolution for low current measurement and at the same time limit voltage drop to 700mV or so when the uC wakes up.Another method is to use a capacitor instead of a battery as power source, ad a Fet-input opamp as buffer to measure the battery voltage and monitor how fast the battery voltage drops. You can even add a schmitt-trigger to top up your capacitor and count the number of times the capacitor needs to be recharged. Adding a second microcontroller to regulate and count charge pulses is a single afternoon project.These methods may not give very accurate absolute values for current consumption, but it does make it easy to compare what influence the software and sleep mode have during tests.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: October 14, 2021, 08:25:36 pm
content: Some time ago I've chosen STM32. It started with the "Blue Pills", the "Maple Mini". Later I bought a few "Black Pills" with STM32F411, but I still have not used them much.ST claims that the STM32U5 series has 110nA shut down mode, but also needs 350uA with RAM and an active RTC, and 19uA/MHz. Those are probably the most important numbers to compare with other microcontroller families, but I do not know how much the marketing arseholes force the engineers to lie about such numbers, so you always have to verify.

author: Godzilla
author_rank: Contributor
timestamp: October 14, 2021, 09:08:10 pm
content: Quote from: Doctorandus_P on October 14, 2021, 08:00:11 pmSadly the batteries will also run a small DC motor every once in a while (twice a day) for like 10 sec every time. So the run consumption of the uC will be negligible at that point. I saw that that stm8 has a sleep mode with RTC enabled, and i was thinking about using that for waking it up every hour and accordingly to datasheet it should only drains tens of uA. About the programming part im almost a newbie, ive only used Atmega and ESP in the past so st8 is totally new, and i was thinking about using SPI (ST-LINK) to flash the firmware if it is an option. I was thinking about making a simple PCB with just the battery connector and the uC with caps and many solder points for the GPIOs, just to be able to play a bit with it a bit before making the final board...Also for the motor part, im not sure if there are many low current DC motor around, and i think that the consumption will be heavily dependent on the load, is there anything that is well known to work well with batteries?For the measurament part i was thinking about using a simple uA meter to see the exact consumption during sleep, do u think that is not enough accurate?

author: magic
author_rank: Super Contributor
timestamp: October 14, 2021, 09:44:16 pm
content: Never used those parts, but ATtiny412 datasheet gives 0.71µA typ / 6µA max at 85°C in standby with RTC.That's SO8 with ADC on all pins and internal 32kHz oscillator or option to use a watch crystal for better time accuracy.Somewhat similar to classic AVR, but new peripherals, different registers, etc.

author: ledtester
author_rank: Super Contributor
timestamp: October 15, 2021, 12:29:38 am
content: Quote from: Godzilla on October 14, 2021, 09:08:10 pmWhat specific simple uA meter do you have?The main problem with low current measurements is the burden voltage. Another problem measuring microcontroller power consumption is that a microcontroller's activity is usually very spikey.For accurately measuring low currents you might have a look at:- µCurrent Gold --https://www.eevblog.com/projects/ucurrent/- CurrentRanger --https://lowpowerlab.com/guide/currentranger/For measuring spikey power consumption:- BattLab-One --https://bluebird-labs.com/(~$100)- Otti Arc --https://www.qoitech.com/otii/(~$700)and I'm sure there are some other products out there.

author: james_s
author_rank: Super Contributor
timestamp: October 15, 2021, 12:40:35 am
content: I have atmega328's that will run over a year on a pair of AA cells, the trick is to run them at 1MHz on the internal oscillator and have them go to sleep whenever they are not actively being used. Most modern microcontrollers have low power modes for battery applications, a pair of AA's is actually quite a lot of capacity compared to a lot of stuff, the real challenge is getting a reasonable life out of a CR2032 cell.This was one of the resources I used.https://lowpowerlab.com/

author: radiolistener
author_rank: Super Contributor
timestamp: October 15, 2021, 02:40:58 am
content: you can use MSP430 they are ultra low power.I was used MSP430F149 for ultra low power device which was expected to work several years from lithium battery. It has 60 kB flash, 2 kB RAM, 12 bit ADC, hardware timers which can be used as hardware counter and other stuff. But it was about 20 years ago, so this model may be too old and you can find more new one from MSP430 series with more memory and other resources.

author: james_s
author_rank: Super Contributor
timestamp: October 15, 2021, 05:43:03 am
content: The MSP430 was one of the early low power microcontrollers but I think most others on the market have caught up quite a while ago.

author: cgroen
author_rank: Unknown
timestamp: October 15, 2021, 06:57:18 am
content: Quote from: ledtester on October 15, 2021, 12:29:38 amI use a couple of Joulescopes, these are really (really!) a good investment.On the talk about clock frequency, I have had several projects where it was better to run a high(er) clock frequency when the CPU wakes up in order to finish the work it is doing faster. Often it is not so that the current consumption is doubled when frequency doubles, so getting "stuff" done faster means lower consumption overall. This is where the (f.ex) Joulescope comes in handy, you get full transparency in the numbers!

author: Godzilla
author_rank: Contributor
timestamp: October 15, 2021, 09:38:44 am
content: Quote from: james_s on October 15, 2021, 12:40:35 amAt first i thought about using the 328 cuz im familiar with arduino, but after a bit of research i saw that it consume hundreds of uA during sleep so i discarded it...Quote from: magic on October 14, 2021, 09:44:16 pmQuote from: radiolistener on October 15, 2021, 02:40:58 amAre they easier to develop than stm8?Quote from: ledtester on October 15, 2021, 12:29:38 amEverything here is out of budget for the moment exepct for the uCurrent Gold, but it seems out of stock atm.

author: radiolistener
author_rank: Super Contributor
timestamp: October 15, 2021, 11:00:17 am
content: Quote from: Godzilla on October 15, 2021, 09:38:44 amyes, you can write code in C and debug it inside device through JTAG interface.It has about 1 uA current consumption in standby mode.

author: Psi
author_rank: Super Contributor
timestamp: October 15, 2021, 11:07:43 am
content: Don't make the mistake of putting an electrolytic cap across the battery.I did that on a hobby thing once, it was flat in 1 month just from the cap leakage current.Use ceramic caps instead.

author: ledtester
author_rank: Super Contributor
timestamp: October 15, 2021, 03:56:11 pm
content: Quote from: Godzilla on October 15, 2021, 09:38:44 amThat might be old/inaccurate information or the chips tested might be fake:Sleep Mode breaks on cheap Pro-Mini? Testing ATMEGA328 - is it counterfeit? - Kevin Darrahhttps://youtu.be/PlGycKwnsSwAlso:Arduino Low Power Project - 200 nA Atmega328p -- Eric Oud Ammerveldhttps://youtu.be/plkn13dOgpU

author: james_s
author_rank: Super Contributor
timestamp: October 15, 2021, 09:42:59 pm
content: Quote from: Godzilla on October 15, 2021, 09:38:44 amThey were out of stock a couple years ago when I tried to order one too so I built my own. The design is open source so you can do that. I had a batch of blank PCBs made and then sold the extras at cost to other members here.

author: ledtester
author_rank: Super Contributor
timestamp: October 16, 2021, 02:48:02 am
content: This blog post contains more specifics on lowering atmega328p power consumption:https://blog.duk.io/sleeping-atmega328-on-1ua-with-timer-wakeup/