are likely towards the end of the battery life. You could
work around this with a buck-boost converter to ensure a
constant voltage output but, of course, this comes at a
cost: The converter and its components constantly
consume power.
Brown-Out Detection (BOD): This functionality
allows you to specify a minimum voltage at which your
microcontroller should operate. If the voltage drops below
that level, then the system enters a “reset” state and won’t
operate until the voltage increases again. I don’t often use
this, but it could be an important consideration if your
project is one that will misbehave at low voltages.
For example, some of your components may stop
working below a certain voltage but not others, causing
the project to behave in an unpredictable (even
dangerous) manner. You can configure the BOD level by
setting specific fuse bits (see the sidebar on Fuses).
We’ve touched on voltage considerations, and
understand that it can significantly impact the power
consumption of a project. Our project this month will get
us into a little more detail, but for now, let’s move on to
the design consideration that will give us the greatest
current consumption savings.
Rock-a-Bye AVR
Okay, I admit, that was a really bad heading to take us
into the details of the most important power-saving design
methodology: the use of sleep modes. We’ve been
building up to this discussion over the past few articles as
we covered topics such as interrupts and timers, and we’re
going to need all that we covered in those articles to
tackle sleep modes.
Let’s start by understanding what it means when a
microcontroller “sleeps.” You could draw an analogy with
animals that go into hibernation: Their systems shut down
or slow down to the minimum needed to keep them alive,
and as a result they consume very little energy and need
very little (if anything) to eat. When a microcontroller is
put into sleep mode, it too shuts down certain of its
modules and peripherals, resulting in drastically reduced
power utilization. Just as the onset of spring triggers the
emergence of animals from hibernation, an interrupt
triggers the end of an MCU’s digital sleep. When
designing an embedded system, it’s common to spend
most of the time in sleep mode, only waking up when
something needs to be done; for example, a temperature
reading being taken.
Most microcontrollers have a range of sleep modes,
but they do vary by specific microcontroller. What we’ll
cover in this article has some generic applications, but is
ultimately specific to our trusty ATmega328P. What
systems does the MCU shut down when it goes to sleep,
and if it is asleep what kind of interrupts are able to wake it
up again? I’m glad you asked, because to understand that
we need to get into some technical detail. We’re going to
spend some time looking at the various sleep modes.
These can seem confusing at first, so if you enjoy a strong
cup of coffee like I do, now would be a good time!
Types of Sleep Mode
The ATmega328P has six types of sleep modes —
each with different combinations of active modules and
wake-up sources. When designing a project, you’ll need to
spend some time deciding which sleep mode is most
appropriate for you. I’ve often found that the one I wanted
to use (due to the power consumption) wasn’t suited to
my project, as I wasn’t able to wake it up with the type of
interrupt I needed to. I’d love to be able to give you a
definitive way to decide on the best mode to use, but the
reality is that it is completely project dependent.
Before you spend time on the details of the various
modes below, consider what it is that drives the
consumption of power in a microcontroller sub-system or
module. If you’ve been really good at reading between
the very blurry lines in this series so far, you may have
guessed that it’s the clock. Without a clock source, the
microcontroller and its modules will not function.
We’ve discussed that tick-tocking drives the CPU, the
ADC, and the timers; how the clock is critical to timing on
the UART; and the I2C interface. Without a clock pulse to
“clock” instructions in and out of the CPU, nothing will
happen. Take a look at the sidebar “How Many Clocks?”
56 January 2016
Figure 3: Sleep mode
characteristics.