AVR Low Power Example Project

 Objective

This page illustrates several methods of configuring an 8-bit AVR® MCU to operate with low power consumption. With this exercise you will:

  • Create a project and add simple code to blink an LED
  • Run the project and measure the power consumption
  • Make modifications to the code to lower power
  • Run the modified project and observe reduced power consumption

 Materials

Software Requirements

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
swtool-28px.png
Atmel® Studio
Integrated Development Environment

Hardware Requirements

  • ATmega328PB Xplained Mini board
  • Power Debugger Kit
  • Two micro USB Cables
  • Three female to male wires, and one male to male wire
Tool About Purchase
ATmega328PB-XplainedMini-50px.png
ATmega328PB Xplained Mini
Evaluation Kit

ATmega328PB Xplained Baord

The ATmega328PB Xplained Mini Evaluation Kit is a hardware platform for evaluating the Atmel ATmega328PB microcontroller. An external debugger is NOT needed to run these exercises. The ATmega328PB has a fully integrated embedded debugger on-board.

xplained-board.png

Power Debugger Kit

The Power Debugger is a CMSIS-DAP compatible debugger which works with Atmel Studio v7.0 or later. The power Debugger sends runtime power measurement and application debug data to the Data Visualizer.

power-debug.png

The Power Debugger has two independent current sensing channels for measuring and optimizing the power consumption of a design.
The ‘A’ channel is the recommend channel for accurately measuring low currents.
The ‘B’ channel is the recommended channel for measuring higher currents with lower resolution.

Hardware Setup

Connecting the Power Debugger to the ATmega328PB Xplained Board.

The ‘A’ and ‘B’ channel current measurement ports on the Power Debugger board are depicted with ammeter symbols on the silkscreen. The voltage supply is connected to the input of the ammeter, and the load (target) is connected to the output. With the following steps, the power debugger measures the consumption on the AVR core.
Table 1-1 Power Debugger and ATmega328PB Xplained Mini connection.

table.png

Figure 1-1 Power Debugger and ATmega328PB Xplained Mini connection.

connection.png

Hardware Configuration

hw.png

Measuring the Current in Active Mode

 Procedure

A

Project Creation

  • Open Atmel Studio 7
  • Select File > New > Project
  • Select GCC C Executable Project and give it the name LowPower.
  • Choose a location to save the project on your computer.
location.png
  • When the Device Selection window appears, enter 328P into the search window and then select the Atmega328PB. Click OK.
device-selection.png
  • A project will be created containing an empty while(1) loop in main().

Select View > Solution Explorer from the menu bar.

In the Solution Explorer, right click the project and select Properties.

se.png

Under Tool, Select mEDBG and debugWIRE

debugwire.png

B

Add Code to the Project

  • Add the following two statements in main() to call TMR0_init and set an I/O pin as an output:

Add the Timer 0 initialization routine

  • Provide the TMR0 interrupt service routine to the project, and make the LED blink at about 1 Hz.

The complete program is as follow,

C

Verify the Project Runs

  • Build the project and program the device by selecting Debug > Continue.

The LED will blink if the project is working correctly

  • Ensure debugging for the project is terminated by selecting Debug > Disable debugWire then Close.

D

Measure the Power Consumption in Active Mode

  • In Atmel Studio 7, open the menu Tools > Data Visualizer

Power Debugger Data Gateway should be selected by default in DGI Control Panel, select it if not. Click on Connect.

connect.png
  • Select Power and Start
power-and-start.png
power-monitor.png

Turn off the target Power Supply to Xplained board and enable power measurement

enable-power.png
  • Close the Device Programming
  • Verify that the average current consumption is about 2.6 mA

Reducing the power consumption

There are several methods you can use to reduce the power consumption of an AVR® microcontroller. This example reduces power by:

  • turning off unused peripherals
  • Stopping leakage current on the digital I/O pins
  • Using sleep mode. Power consumption optimization techniques are implementing in the function Optimize_power_consumption() which is called from main().

Disable digital input buffers and Analog comparator

For analog input pins, the digital input buffer should be disabled.

The digital input buffer measures the voltage on the pin and represents the value as a logical one or zero. An analog signal level close to VCC/2 on an input pin can cause significant additional current consumption. If the pin is used as analog pin there is no need to know if the analog signal’s digital value would be a one or zero; these digital pins should be disabled.

Turn off unused peripherals

Disable the peripherals not used in the application. The Power Reduction Register (PRR0) and (PRR1) can stop the clock to individual peripherals to reduce power consumption. Resources used by the peripheral remain occupied when the clock is stopped. In most instances, peripherals should be disabled before the clock is halted.

1. Include the <power.h> file in the main program
#include <avr/power.h>
2. Add below code to optimize_power_consumption().

3. Add and #include for <wdt.h> to main.c.
#include <avr/wdt.h>
4. Add the following code in optimize_power_consumption() to turn off watch dog timer.

Apply pull-up resistors

Unused and unconnected pins consume power. The un-needed power load of floating pins can be avoided by using the AVR's internal pull-up resistors on the unused pins. Port pins can be set to input pull-ups by setting the DDxn bit to 0 and PORTxn bit to 1. (where x is PORT B,C,D,E and n is 0 to 7)

Use Sleep function

Sleep mode allows the application to save power by shutting down unused modules. The AVR provides various sleep modes allowing the user to tailor the power consumption to the application’s requirements.

1. Include <avr/sleep.h> header file from AVR library at the top of file.
2. Set the desired sleep mode in the optimize_power_consumption () function by configuring the microcontroller to use the sleep mode SLEEP_MODE_PWR_DOWN for minimum power consumption.

3. Call the function sleep_mode() from main() to enter sleep mode.

Using Pin Change Interrupt

To wake up the microcontroller from SLEEP_MODE_PWR_DOWN the Pin Change Interrupt is used. The ATmega328PB Xplained Mini board's switch (SW0) is connected to PB7. Pin PB7 is the source for the pin change interrupt. Make the following additions to main():

#include avr/interrupt.h

Configuring bit PCINT7 and PCICR register:

Add the interrupt service routine:

In order to enable the ISR routines, the vector name for the PCINT7 is ISR (PCINT0_vect), defined in device header file.

Completed Code

After making the previous changes the complete code should like the following:

Program the application and measure power consumption.

  1. Program the code by selecting Debug > Continue.
  2. Wait until the application is programmed and the message at the bottom of the window appears as Running.
  3. Exit the debugger by selecting Debug > Disable debugWire then Close.
  4. Open the DataVisualizer window and check the power consumption as shown below.
one-five.png

Current consumption observed should be down to around 1.52 mA.

  • Set target power switch off: Tools > Device Programming > Tools setting
threema.png

Current consumption should have been lowered to approximately 20.7 μA.

Note that the Timer does not wake the device from SLEEP mode. The application is set to exit sleep mode when the Pin Change Interrupt occurs.

 Conclusions

This example demonstrated several different techniques to lower the power consumption of an AVR application. The power consumption can be significantly reduced by:

  • Intelligent design
  • Using sleep modes
  • Switching off unused peripherals

This example used the Atmel Studio 7 Data Visualizer and the Power Debugger Board to measure the power.

© 2017 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.