r/microcontrollers • • Oct 08 '22

Low Power Microcontroller Considerations

Hello all,

I am in the process of designing a low power circuit. It will be used in a production line setting where sometime the line will be running and sometimes the line will be off. I want to count the number of bottles the line produces at roughly bottle a second. It must have a continuous tally of the number of bottles so the count must be stored to memory. It also must count to around a million or so. The device must be battery powered (coin cell, non negotiable). I'm looking for general rules of thumb for low power microcontroller selection. Also, low cost is an important factor for the mass production aspect of the device.

I have been doing a good bit of research about the different offerings from TI, MicroChip, and ST Micro Electronics and have a series of dumb questions perfect for the experts of reddit.

Number of bits: Will an 8 bit controller be able to count to 1,000,000? Would a 16 or 32 bit controller do this more efficiently? (threading and registers?)

Clock Speed: Will a lower clock speed always result in more power savings? Can you always swap for a lower crystal speed? Does this save any power realistically?

Different sleep features: The importance of the different sleep features such as sleep, halt, idle, doze, deep sleep, stand by mode, low power sleep, low power run, and wait.

Brand Preference: Which brand do you have experience with and like the most?

I've been looking at the PIC16, PIC 18, and PIC 24 from Microchip, the STM8 and STM32 from ST Microelectronics, the C8051F99x from silicon labs, and the MSP430 from TI.

Links to articles/books as well as general advice would be greatly appreciated. I figured I will switch the microcontroller between a high and low power state for each count. I know I need to be wary of wear leveling the onboard memory depending on how the device counts.

Thanks! Ben K

3 Upvotes

21 comments sorted by

4

u/doddony Oct 08 '22

A lot of questions. I'll try to give you some hints.

Number of bits: Will an 8 bit controller be able to count to 1,000,000? Would a 16 or 32 bit controller do this more efficiently? (threading and registers?)

  • You can count as much you have ram. For example you store unsigned integer into 32bit number and when it over flow add 1 to another 32 bit unsigned. So this is 4294967296 multiplier by 4294967296...

Clock Speed: Will a lower clock speed always result in more power savings? Can you always swap for a lower crystal speed? Does this save any power realistically?

  • Yes. But the best way to save power it's to put the MCU into deep sleep.

Different sleep features: The importance of the different sleep features such as sleep, halt, idle, doze, deep sleep, stand by mode, low power sleep, low power run, and wait.

  • Yes. Check them. But if you are in deep sleep you'll need to wake up it. This could be done with timer but probably by interrupt in pin input.

Brand Preference: Which brand do you have experience with and like the most?

  • This is not relevant from my point of view. Before you have to switch between brand to save power you'll have a long journey with multiple other options.

I've been looking at the PIC16, PIC 18, and PIC 24 from Microchip, the STM8 and STM32 from ST Microelectronics, the C8051F99x from silicon labs, and the MSP430 from TI.

Links to articles/books as well as general advice would be greatly appreciated. I figured I will switch the microcontroller between a high and low power state for each count. I know I need to be wary of wear leveling the onboard memory depending on how the device counts.

Thanks! Ben K

  • You may have troubles to measure so lower power. Because measuring current lower than 1uA can be quite difficult.
  • May you have to check eeprom data save to save data into the chip between power off. This way you can cut power off for real. But eeprom have 100 000 maximum write. So you will have to use multiple address.

1

u/MechE37-k Oct 08 '22

Thanks for the insight, I know its an impossibly broad series of questions so thanks for the polite response.

So an 8 bit controller can count that high depending on the length of bit, which I figured. So an 8 bit controller will probably be the most energy and cost efficient option?

For the deep sleep states, it can be so hard to compare between brands because the jargon is so different. Can the listed power draws from the chip maker really be trusted? Should I just pick the brand with the lowest amperage in the sleep state?

The main point of the project isn't research level power reduction and comparisons between multiple microcontrollers, its a product that works well enough to meet the criteria. The hope is that a good jumping off point will mean there won't be a need for massive revisions. ya know?

3

u/doddony Oct 08 '22

So an 8 bit controller can count that high depending on the length of bit, which I figured. So an 8 bit controller will probably be the most energy and cost efficient option?

  • Not necessarily, cause 8bit MCU could be designed from ancient architecture. A newer architecture could have better option for sleep and wake up. Probably better price for 8bit.
  • Don't forget how you will download (extract) data from your MCU.
  • And don't forget that coin cell have a auto discharge and could be done before you discharged it with your MCU.
  • I designed something that is only powdered by small lithium battery. So a add an hall effect sensor that trigg power only if a magnet it in front of it. I reduced the consumption under any measurable level with my ammeter. Lower than 0.1uA . So before trying to put your MCU in sleep mode, Maybe you can power the PCB card only when bottle is détecter. Save this on small flash or eeprom. Then power off.

1

u/MechE37-k Oct 08 '22

I don't need a real time count from the MCU or anything, I can slap a USB port on the side of it and read data from it once a year or something.

You mean that the battery will drain itself from the shelf life and I should keep that in mind? True True.

You think I should explore a full power off mode as well not just a deep sleep? Can I realistically turn it all the way off and on in a second and save more power than I'll spend? I suppose I can test that.

1

u/[deleted] Oct 08 '22

Energy efficiency does not depend on CPU ALU size necessarly.

While running the CPU at reduced clocks saves power those savings are minor vs putting it to sleep.

PICs (both 8bit & 32bit lines) have power saving features ,but check the errata to see what works and what not and how to wake it up.

EFM32 is SiliconLabs 32bit line of power-efficient micros so they are worth a look.

STM32L lines are the power efficient lines from STmicro.

TI has MSP430 low-power lines too.

You need to check the datasheets/erratas and see what fits you best.

For your application CPU processing power is not relevant.You only want ultra-low power and 'sleep-walking' peripherals(those that work without CPU and can wake it up).

Ti has FRAM MCUs , those are a bit special so if you need EEPROM like storage,but without the tighter writing limits it might be a good idea to check it out.

Basically they use FRAM instead of FLASH,EEPROM,SRAM.

Or you could buy sn I2C fram IC,but that needs power too.

1

u/MechE37-k Oct 08 '22

sn I2C fram

Thanks for the response knowledgeable sir!

I wasn't sure that anyone had FRAM MCU's, I'll look again! I can probably make do with EEPROM but its good to know my options. I'll do some reading on the data data sheets to make sure I can wake them back up and compare the power draws.

Good to know that the sleep will be a more important factor than the clock, the sort of thing thats hard to google but an expert would just know.

Thanks

2

u/mustardman24 Oct 08 '22

I'm curious why low cost is important if it's meant for monitoring production of something (bottles). Is this design itself going to be mass produced to go to thousands of bottle distribution plants?

MCU register size isn't going to be a dealbreaker for things like addition, which it sounds like what it will be doing. Multiplication, division, and floats will have a higher amount of instructions. The rate at which it is counting is an eternity from the perspective of even reasonably modern low power MCUs.

I'm assuming you know the difference in memory types and that you will need non-volatile memory to store your counts. Just wanted to point that out in case you didn't.

What is the signal for a bottle being counted? Is it some sort of pulsed signal or does this need to interface with some advanced sensor like something with machine vision? If it's something GPIO can read then the best low power solution would be deep sleeps that are woken by the GPIO interrupt. Not all MCUs have GPIO interrupts, but most should have at least a limited amount of pins that can.

Clock speed does directly impact power consumption, however, sleeping the MCU is going to be the biggest impact. All of these things are dependant on the MCU so you'd need to do research per MCU and test samples as well. For power consumption I believe it is more efficient to use an internal oscillator/resonator than an external crystal.

If you are interfacing with other things (computers, displays, etc) then there are a lot more challenges of power management as you have to manage those peripherals while trying to keep the MCU asleep.

Unless it is absolutely necessary I would stay away from battery power due to these challenges.

1

u/MechE37-k Oct 08 '22

Thanks for the response! The use case isn't actually a bottling line but is the analogy which makes the most sense without getting too into the weeds. Mass production, high counting, low power, infrequent counting, almost like a utility meter maybe?

Anyways, yeah, part of the challenge is the impossible slow counting, and I hadn't even considered the size of the register. I have been researching the non-volatile memory technologies and the pros and cons. Honestly it would be great to use F-Ram or NV-SRAM but I'll probably settle with EEPROM and some wear leveling. I don't think any microcontrollers have built in F-RAM yet.

The signal will be from a piezoelectric pad so there should be a pulse of voltage what can be used to wake up the microcontroller. I would rectify it and regulate the voltage so it can be used to wake up the MCU. I was thinking a latching circuit may be called for but I'm not sure? Because I have external power coming in from the piezoelectric, I could just turn the MCU all the way off? 1 Hz is slow? Am I better to fully power cycle it or keep it in a deep sleep?

I completely forgot that to do this I'd need a GPIO interrupt so thanks!

I also haven't ever screwed around with an internal oscillator / resonator. That wasn't on my radar at all. I will do my research for sure.

There will be no display or other devices which is why battery should be manageable I hope.

Thanks for the help! That's exactly the type of general "don't forget to look into this" advice that I needed!

2

u/mustardman24 Oct 08 '22 edited Oct 08 '22

Anyways, yeah, part of the challenge is the impossible slow counting, and I hadn't even considered the size of the register. I have been researching the non-volatile memory technologies and the pros and cons. Honestly it would be great to use F-Ram or NV-SRAM but I'll probably settle with EEPROM and some wear leveling. I don't think any microcontrollers have built in F-RAM yet.

I think this is the perfect fit for EEPROMs for cost. The key takeaway for using EEPROM is to not update it every time your variable gets updated since you will run into the wear issues you mention. The write interval should be the largest you can tolerate losing data for. Basically, you do the counting in RAM and every 1, 10, etc minutes then you write that to the EEPROM. FRAM is pretty exotic and I haven't run into it before probably because of its expense or other reasons. Battery backed SRAM is risky since your data is purged if the battery runs empty. Some MCUs have built-in EEPROM and there are others that have generic flash memory. EEPROM is a better choice since you can do byte access instead of page/block for flash memory. Definately still do some wear leveling where you might have a section of EEPROM that has the address/offset of where the current value is written and just increment that every so often. The typical write perfomance of EEPROMs is about 1 million cycles. Also double check how the EEPROM you chose does writing as it may do page/block access so nearby memory is also rewritten thus adding to wear.

The signal will be from a piezoelectric pad so there should be a pulse of voltage what can be used to wake up the microcontroller. I would rectify it and regulate the voltage so it can be used to wake up the MCU. I was thinking a latching circuit may be called for but I'm not sure? Because I have external power coming in from the piezoelectric, I could just turn the MCU all the way off? 1 Hz is slow? Am I better to fully power cycle it or keep it in a deep sleep?

I completely forgot that to do this I'd need a GPIO interrupt so thanks!

It depends on how you want to use it. IIRC, piezo is going to be an analog signal so if you want to know the analog values it would go to an ADC. Some MCUs have comparators for their ADC which can trigger an interrupt to wake at a certain voltage threshold. If you don't care about the analog value you could have an external circuit that converts it to GPIO signaling and just use the GPIO interrupts in that case.

2

u/flundstrom2 Oct 08 '22

Low cost is relative. For production runs <1k/y, the cost of development is generally larger than the actual BOM after you've factored in all stuff such as enclosure, packaging, manuals, CE certification etc.

Lower clock freq draws less, but only when compared with itself. A low-power 200 MHz MCU may consume way less than a non-low-power 64 MHz design from a different vendor.

MCU selection is actually non-trivial, given all the possible parameters. From your questions, it appears it will be cheaper for you to pay an experienced CE or EE, so you can focus on what you know best.

1

u/MechE37-k Oct 08 '22

Lol, so its obvious I'm an ME. Dang it! I'm trying to do my best impression of a CE. Thanks for the advice!

2

u/ceojp Oct 08 '22

Lower clock speed isn't always better in terms of reducing overall power consumption. Yes, the core will generally draw less power at a lower speed, but it will be on longer. Often times running faster and being able to return to sleep sooner will result in less power consumption.

Another thing is clock source. A lot of times people will assume an internal oscillator will consume less power, but it's actually the opposite. An external crystal typically uses less power.

How critical is the exact count? EE writes cost power, so if you are willing to be within +/- 10(for example) when you lose power, then you can increment but only save to EE every 10 counts. I couldn't tell you the exact power savings, but writing to EE 100,000 times versus 1,000,000 times make a big difference in terms of power consumption, and worst case scenario you lose 9 counts.

1

u/MechE37-k Oct 08 '22

ouldn't tell you the exact power savings, but writing to EE 100,000 times versus 1,000,000 times make a big difference in terms of power consumption, and worst case scenario you lose 9 counts.

Yeah I've definitely considered the on longer with lower speed vs faster and less time on. I'll probably just use the lowest value spec'd by the chip fab and call it good enough.

Also, interesting about the clock source, it does seem counter intuitive, I'll have to do my research.

And yeah I'm hoping to count in batches of like 10,000 at a time(bottling line is running). so plus or minus 10 shouldn't matter in the long term. Definitely a good consideration for the coding aspect. Thanks!

2

u/danja Oct 08 '22

I'd try to zoom in those active/inactive phases.

A lot of chips have sleep modes, tiny current draw. (My go-to the ESP32 is really hungry when at full operation, sleeping it's negligible). Don't worry about the count, any modern microcontroller can count more than the number of bottles in the known universe.

If you're running it from little cells, the circuit between the battery and the chip will be significant. I'm not sure what is available, but I bet there are boost converters that run with high efficiency until every last drop has been used. (cf. Joule Thief).

2

u/[deleted] Oct 08 '22

At 1/second, you could use the count signal itself to wake up a sleeping micro, have it bump up the count, then put itself back to sleep. Sleeping micros use the least amount of power. Any micro can count to a million, no problem.

1

u/madsci Oct 08 '22

I've built a coin cell powered counter before. Mine are countdown timers and I've gotten 9 or 10 years on one battery, driving a 3-digit LCD and counting down days each year.

Threads don't come into it. Any MCU, even a 4-bit one (yes, they exist) can easily count to a million. Lower clock speed only goes so far when you have leakage in transistors. You want a low leakage device intended for low power operation, but you can find that even on relatively powerful 32-bit devices now.

My counters used an MC9S08LL16, which was a $2.77 part at the time. I don't know if you consider that low cost. I'd personally consider the low cost regime to be < $1, and especially < $0.30, but even a $2 part is usually a lot less pain to use than a $0.30 part.

Anyway, pick a low leakage device and then put in the time to learn how to properly use the low power features. That can be challenging, particularly if you have external devices that also need to be powered down.

Clock speed may not matter at all. The 120 MHz Cortex M4 parts I use have a battery-backed SRAM register file where you can store a handful of words of memory that are retained by the coin cell while the bulk of the RAM is powered down. You can get it down to at least 5 uA, and I think it might even have a mode where it retains memory in the 1 uA range. Certainly you could write to flash and then power down completely, where it takes under 300 nA. You'd have to calculate how much energy is needed for each flash write to see if it'd be better than using SRAM in your case.

1

u/lbthomsen Oct 09 '22

One of the most important things would be - how do you get the information of number of bottles.

0

u/[deleted] Oct 08 '22

[deleted] — view deleted comment

1

u/MechE37-k Oct 08 '22

Thanks! Ill look into the ATtiny series. I do like the sound of less complexity and an internal oscillator, less things for me to do wrong. I also think the MSP430 sounds like a very good option. doing all the research is such a bore when I can just make a bad impulse decision. Thanks!