There will be a Freescale app note covering this topic, but in the meantime the tutorial below walks through the steps in lowering the power consumption of their Freedom board.
This tutorial was extracted from Erich Styger's blog http://mcuoneclipse.wordpress.com with his agreement.
The FRDM-KL25Z is a great board: inexpensive (around US$15), small form factor, has easily accessible pins, and has a low power (capable, at least) microcontroller, and comes with an embedded debugging interface. So why not using this board right away ‘as is’ for a low power battery operated device? Great idea, you think? Yes, I thought too. Only to find out that the board needs 20 mA out of the box.
The good news is: It is possible on a week-end to get this 150 times better down to 132 μA, with an RTOS running all the time . I invite you to join a journey with board modifications, jumpers, schematics and many multimeter pictures ….
Preface
Why do I want to use the FRDM-KL25Z as a battery operated device? I’m working on a data logger/weather station project: It features a barometric absolute pressure sensor, and I²C external EEPROM and the nRF24L01+ wireless transceiver. The Freescale FRDM-KL25Z board is great to start with: it is small and provides easy access to all signals, so I can build up my design with bread boards:
Bread Boarding the Data Logger System
Yes, the wiring in the picture looks messy, but it allows quick prototyping and inspection of signals with a logic analyzer.
I get frequent questions and requests about “my SCI, SPI or I2C communication is not working!”: A logic analyzer or oscilloscope is something you should own. Without a logic analyzer, you likely will waste many, many hours. If you do not want to spend around $100 for professional tools, then I recommend you buy at least a $15 FRDM-KL25Z board and use it as a logic analyzer, see this post.
The system has following main parts:
- Microchip 24AA external I²C EEPROM to store data values and configuration data. Data is stored in the EEPROM until it is transmitted over the wireless transceiver.
- Nordic Semiconductor nRF24L01+ wireless transceiver for connectivity.
- MEAS MS5607 I²C digital absolute pressure sensor.
- ARM Cortex-M0+ processor on the FRDM-KL25Z.
I want to use a Cortex M0+ because of the low power characteristics of my application: The KL25Z is over-powered for my final design, but gives me a powerful development platform. And with using Processor Expert as hardware abstraction it allows me to change the processor later very easily: it will be just a different configuration made with a few mouse click .
The question is: how to use the FRDM-KL25Z to help with developing a battery operated low power embedded application?
My plan is the following:
- Breadboard setup of the system with the FRDM-KL25Z: this allows me to develop the software with all the needed hardware.
- Developing a simple ‘Arduino’ shield for the FRDM-KL25Z which has all the external parts (pressure sensor, EEPROM, transceiver) on it. This system will be battery operated and allows me to make long time measurement of the system.
- And finally to develop my board with another microprocessor on it (most likely a KL02 or KL05). In this stage I do not need the FRDM-KL25Z any more.
Low Power (not ‘Ultra-Low-Power’)
The final system will be battery operated, so I need to make sure it uses as few energy as possible. Or better: that it uses as few energy as reasonable possible. And this means that the system shall consume less than 1 mA in average. Yes, this is not one of these ‘ultra-low-power’ applications. Silicon vendors advertise ‘nano-ampere’ solutions, but for many applications they are never achievable: to me these benchmarks are not realistic, as they assume that the processor is alive maybe one second every day? But my system needs to continuously measure and communicate several days a day. So a 99.9% inactivity is not achievable.
Silicon vendors build in multiple low power modes into their microcontroller: unfortunately many modes are easily usable waking up from the ultra-low-power modes is like a power-on-reset: all your SRAM is gone, and the peripherals and pin states are gone too. Such ultra-low-power modes are cool for a ‘dumb’ application, but were hard to deal with a more complex system where for example an operating system is running. Just to set the stage .
There is a lot which can be done to cut the power consumption, without impacting the application functionality or usability. The wireless transceiver, pressure sensor and EEPROM do not have critical power consumption in my design. What is critical is the processor: I need to get it down to below 0.5 mA. And do not want to switch the processor completely off: it shall run the operating (FreeRTOS) RTOS all the time .
FRDM-KL25Z RevE
For my experiments, I’m using the RevE version of the FRDM-KL25Z board. Compared to the earlier RevD it has a newer silicon plus jumpers to disconnect better parts on the board to reduce the power consumption. And I’m using CodeWarrior for MCU10.5 with Processor Expert:
- Processor Expert makes it easier to deal with the low power modes: no need to spend many hours reading to silicon reference manual to understand all the different low power modes. And it makes it really easy to move to another processor later.
- CodeWarrior debugger nicely is able to debug low power modes. Unlike other debuggers, it keeps the connection with the target under debug even if the microcontroller is in low power modes.
Test Setup
To keep things simple in a first phase, I measure only the power consumed by the FRDM-KL25Z (and ignore the external sensors/etc).
In my system I use a microcontroller voltage of 3.3V. Reducing the Vdd voltage usually has positive (square) impact. In my experiments I’m not going to reduce the Vdd. I instead focus on disabling unused board components, reducing clock speed and using low power modes.
The FRDM-KL25Z board runs a stripped down version of my application (just without the sensor and wireless application pats. I’m using a technique with ‘platform macros’ to enable/disable application functions:
1
2 3 4 5 6 7 8 9 10 |
#ifndef PLATFORM_H_
|
Board Power Measurement Jumpers
The FRDM-KL25Z RevE board has two jumpers (J3 and J4) to measure the power used by the KL25Z and/or the power used by the K20 for the OpenSDA debug interface:
Both headers are not populated by default. J3 has a 0 Ohm and 10 Ohm resistor populated.
I guess the idea is to remove the 0 Ohm (R73) so the voltage across R81 (10 Ohm) could be measured by the KL25Z itself?
On the RevD boards both headers hat a ‘cut trace’ between the jumper. I decided to remove all three resistors (R73, R81 and R74) so I can measure the current consumed.
Removing SMD components without the proper equipment is challenging! It works best with SMD de-soldering iron tips. The RevD approach with cutting traces was more user-friendly.
Starting Point: 19.58 mA
I’m not so much interested here about the current consumed by the KL25Z and K20 (OpenSDA), as I need to focus on the overall board consumption. For my experiments I measured the board current coming through the P3V3 on pin 8 of J9:
I started my experiments with following starting point:
- KL25Z using 8 MHz external crystal (PEE mode, 48 CPU clock and 24 MHz bus clock)
- FreeRTOS running SysTick for with 100 Hz RTOS tick counter
- Shell command line interface through OpenSDA (38400 baud)
- Blinking LED heartbeat so I can see that the application is running properly
With this, the board consumes 19.58 mA:
Disabling Accelerometer: 19.55 mA
One rule of low power: disable what I do not use. The FRDM-KL25Z has the MM8451 accelerometer on the board, so I disabled it (disabled the accelerometer through the I²C interface/shell). But saving were minor. I guess only removing the accelerometer would bring some extra savings.
Reduced Clock Speed: 11.91 mA
Second rule of low power: slow down the clock speed. Current consumption usually is linear to the used clock speed. So reducing the clock speed should greatly reduce the current. I do not need that 48 MHz clock speed for my application. So I reduce the core clock to 2 MHz and the bus clock to 1 MHz:
- External Crystal 8 MHz
- MCG settings to BLPE (Bypass Low Power External reference clock)
gives about 12 mA:
Disabled OpenSDA: 7.23 mA
I still have a lot of current consumed. And one part of this is the K20 microprocessor on the board used for OpenSDA. To get rid of that extra current:
- Disconnect P3V3_SDA (remove R74 and remove jumper on J3)
- Disconnect OpenSDA reset line: for this cut the trace under J14 and install a jumper
Remove the J14 jumper to disconnect the reset line between the KL25Z and K20 OpenSDA, as otherwise current can flow between the K20 and KL25Z:
With this, the current went down to 7.2 mA:
Cut J20: 3.55 mA
Good progress so far: from 20 mA down to 7 mA. But what caused me a lot of head scratching: I would not have expected that 7 mA: it should be more in the 3-4 mA range. And indeed, measuring the current to the KL25Z microcontroller on J4 showed 3.4 mA:
So what is using all the excess current? My goal is to go below 1 mA, and somehow the board itself already uses 3.6 mA somewhere. It took me more head scratching (that’s why I’m getting bald ). And after a while I realized that current must be flowing back into U1:
With this, I decided to the trace under J20 and to install a jumper there to prevent that current:
Now my board shows a current I expect :
Using Internal Clock: 2.69 mA
One general rule for low power is: using an external crystal uses less energy than using an internal (on chip) clock generator. However as the FRDM-KL25Z has a high frequency 8 MHz clock needed for its USB operation, it is probably better to use the internal (slower) clock generation module.
For this I disable the external crystal and change the mode from BLPE to BLPI (Bypass Low Power Internal):
And the result is again a reduced current consumption:
I did not expect that much reduction. Not sure why it has such a big impact. But it seems that this 8 MHz external crystal really is not good for low power applications?
Very Low Power Mode: 2.08 mA
To enter the ‘Very Low Power Modes’, I enable the setting in the CPU component. But as the bus clock cannot exceed 800 kHz in this mode, I set it to the next closest value:
With this, I’m close to 2 mA . But still twice as high as where I want to be .
Where is my current going?
To be clear: I’m down to 2.08 mA for the board, while the microprocessor is in RUN mode. So I not enter any of the special low power modes (yet). Still for 2 MHz CPU clock that 2.0 mA are too high to me?
So decided to do another measurement: measuring both the board current and the KL25Z current with the OpenSDA on the board enabled (J14 and P_SDA enabled).
That 6.65 mA for the board is no surprise: the K20 of the OpenSDA is active. However what is interesting to see is that the K25Z current is down to 0.754 mA with the OpenSDA active, while it is very close to the 2.083 mA if the OpenSDA is *not* active. This means that about 1.3 mA is going ‘somewhere’ from the KL25Z if the OpenSDA is deactivated. The question is: where, and why?
OpenSDA Serial Interface
I already have cut the reset line between OpenSDA and the KL25Z. But there is the OpenSDA Serial-to-USB CDC connection:
And I’m using a UART0 in my application: I’m using it to communicate through OpenSDA to the host machine. But now I have OpenSDA disconnected, and there could be a current flowing from the KL25Z to the K20 (which is unpowered). So I turned of the shell and UART, and look at this :
Processor Expert Low Power Modes
So far I’m not using any low power modes. The cool thing with Processor Expert is, that it makes usage of low power modes really easy. Calling SetOperationMode() changes between the different low power modes:
There are several settings inside the CPU component which deal with low power. First is the ‘Low power mode settings‘ group:
In above dialog I specify which modes are allowed, and which interrupt/events bring me out of Low Leakage mode (LLWU = Low Leakage Wakeup Unit): Usually I use the Low Power Timer (LPTMR) to wake me up.
In the Operation mode settings I can specify
- Which mode shall be entered with SetOperationMode()
- What should happen after the wake-up interrupt
Entering Low Power Mode: WAIT down to 0.155 mA
With this, everything is ready to use low power modes from the application.
In my application I have a variable LP_mode:
1
2 3 4 5 6 7 8 |
typedef enum {
|
which is defining the current active low power mode. To switch into a low power mode I use SetOperationMode():
1
2 3 4 5 6 7 8 |
if (LP_mode==LP_WAIT) {
|
WAIT is really easy to use: basically it stops the core clock, while interrupts are still active. And a perfect place to enter that low power mode is from the FreeRTOS Idle task hook:
1
2 3 4 5 6 |
void FRTOS1_vApplicationIdleHook( void )
|
Just doing the WAIT mode I get down to 0.155 mA :
With the above setup, I have only one task running and a blinking LED. The application with all the sensors will have two more tasks added, so the power consumption will go up again.
FreeRTOS Tickless Idle Mode: 0.132 mA
FreeRTOS comes with a cool low power feature: the Tickless Idle Mode. I have enabled it along with using the special Systick Prescaler:
With this, the RTOS will delay the SysTick interrupts as long as possible, extending the low power idle modes and reducing the interrupt load. And this is what I get as board current :
Summary
The week-end is over, and I need to stop here at the WAIT mode. I have not explored the more advanced SLEEP and STOP modes, but on the other hand I’m now well below my target of 1 mA for the board anyway .
Modern microcontroller come with many advanced low power modes. Unfortunately for many applications most extreme low power modes are not usable as they completely shut down the processor, making it hard to use with an application e.g. using an operating system. The Freescale KL25Z processor is no exception to this. But even with ‘moderate’ power saving settings I’m able a reasonable power reduction. Still, there are a lot of settings, and I it is definitely not easy to find my way through the endless and complicated settings the silicon designers have invented. But at least with Processor Expert things are easier to find and configure.
Development boards are great for development or evaluation. They are usually not designed for low power usage, because they have too much components on it consuming energy. However, as shown with the FRDM-KL25Z it is possible to get into a working solution:
- Disable by software any external devices not used (e.g. Accelerometer)
- Disable any on-board debugging devices (e.g. OpenSDA). Do not only cut power, disable as well any other debugging signals (e.g. Reset).
- Carefully check the changed current flow if not using the on board regulators (e.g. prevent current flowing back to the regulators).
- Make sure that there is no current through connection lines to unused devices (e.g. UART0 to K20 OpenSDA).
- Using an RTOS like FreeRTOS does not mean it cannot use low power modes. A mode like WAIT already greatly reduces the power consumption. The tickless idle mode of FreeRTOS is helping to reduce the power consumption too.
- I would not have been able to reach this in such a short time without the help of Processor Expert
The project I have used for my testing is available on GitHub here. Hope this is useful, and helps your battery powering a FRDM-KL25Z. So far I have reached my goals with a board consumption less than 1 mA . But as soon as I find time, I’ll explore the more advanced low power modes. Until then, have a look at the Freescale web site for any documenation about how to use the low power modes for the KL25Z (or any other ARM Cortex-M0+).