Saturday, November 24, 2012

In our last post we came to know about the process of configuring the core clock for EFM32. Basically how to make the Coretx-M3 clock from the External Crystal source HFXO.
Next we would take a detailed look at the Energy modes in the EFM32 microcontroller. Again we are going to use the Keil MDK with GCC and the STK3700 kit.
In the EFM32 Microcontroller the Energy Management Unit(EMU) takes care of the setting the power, reset and clock-gating. Additionally it also takes care of Brownout detection for resetting the MCU if the voltage falls below a specified threshold to prevent spurious code execution. However we would focus more on the Energy modes that govern the operation of the Microcontroller core as well as its peripherals and clocks. This might be a bit confusing that CMU is responsible for clock then why EMU. Yes, the CMU is for conguration of the clocks, clock-gating and dividers, but the oscillator control also has additional parameters that are decided by the EMU. We would cone to clarity on this soon.


First let us understand what are the causes of excess power consumption in a normal embedded application. Most peripherals in an microcontroller are digital circuits and when non functional but clocked they keep consuming power due to switching. This unwanted switching can be disabled by clock-gating as explained earlier. However with that some times the configuration of that peripheral is also lost. Possibly another case may be that it loses track of what it was doing earlier. In that we would any how need to reset the peripheral or reconfigure it again. This again takes power and time of the main core. Modern microcontrollers provide an easier way out. They internally make sure the state of the peripheral is retained without effecting its functionality.
Apart from this we have clock trees that drive the peripherals. These consists of  synchronization units, buffers and of course oscillator blocks. Now they might be completely unnecessary at time when the specified peripheral that they are clocking is gated. Thus by shutting down these we can get additional power savings.
Plus, some of the modern MCU such as EFM32 have internal regulators that provide supply to the various peripherals. This is done so that we can provide only single supply to the microcontroller from outside, however still be able to run the lower voltage peripherals. Disabling these regulators can be another power saving trick.
Now to summarize we have the following things to do to have lower power consumption:
  • Shut down unnecessary peripherals
  • Shut down clock trees
  • Shut down regulators
  This might seem simple but thing of how to come back to main core executing code again after it was shut down or even its clock was removed. Same is the case for the peripherals. However there is nothing to worry. The modern microcontrollers like EFM32 are equipped with Energy Modes.
In the above discussion we clearly see that we need to shut down clocks, peripherals and the main core and also make them come back to their previous state. All this is internally handled by the Microcontroller Energy Modes. When the microcontroller enters a specified energy mode the particular clocks are disabled and state retention is attained automatically. There are specific events from the remaining peripherals that are working in the given Energy Mode to wake up the main core or peripherals when triggered.
So, in short the Energy modes are a way to make the microcontroller go to special state of sleep by disabling clocks and peripherals; then providing a way to wake it back up to operation when triggered by events on the peripherals. This is what Energy modes are for.

EFM32 Microcontroller has a special section Energy Management Unit(EMU) that is responsible for controlling not only the Energy Modes but also the associated segments such as Regulator, Clocks, Backup Power Domain and Reset, to name a few.
Let us now look in detail about each of the Energy Modes and how to enter & exit them:
  1. Energy Mode 0 (EM0) : This is the default energy mode of the microcontroller after reset, All the enabled oscillators are running and all the peripherals can be activated. This means High Frequency Clock trees are operational for both the core and high frequency peripherals. In general all the other energy modes return the microcontroller state to this mode when they are triggered.

    Entry: Reset, Wake-up from other Energy Modes
    Exit: Reset, Setting of Energy modes
    Clocks: All Enabled Clocks are Active
    CPU: Active
    Peripherals: All peripherals are available
    RAM: Retained

  2. Energy Mode 1 (EM1) - Sleep Mode : This is first Energy mode, only the main core clock is disabled. Which means that only the CPU clock tree is disabled. All other peripherals are available and all the clocks as well as the Memories are intact and available for operations. There is a special system feature called the Peripheral Reflex System (PRS) that can be utilized to performed several activities without any need of CPU to process data from other peripherals. We would be discussing about this in our future posts. This mode can be triggered after enabling an interrupt from any of the peripherals that would be active in this mode. It is to note that if the Peripheral interrupt is not active from this mode then we cant come back to EM0 up again. Also it needs to be taken care that the execution would first enter the interrupt subroutine(ISR) that was enabled before initiating the EM1 sleep and then it would exit to the next line of code after the emlib function call.

    emlib Function: EMU_EnterEM1()
    Exit: Interrupt from active peripherals
    Clocks: Only MCU Clock tree is disabled
    CPU: Sleep
    Peripherals: All peripherals are available

  3. Energy Mode 2 (EM2) - Deep Sleep Mode : In this mode all the high frequency clocks and peripherals are deactivated. Only the low frequency clocks and peripherals are active. For this reason the EFM32 has the special Low Power Peripherals that work using alternative clock sources of lower frequency such as LEUART, LESENSE etc. We would be discussing this in details in our future posts on how to harness the true power of these low power peripherals using application examples. This mode has a limited set of wake up sources as compared to EM1 due to non availability of the high frequency peripherals. Again the process of the wake up is similar to the EM1, so first the ISR is entered and then we go to the next instructions after the emlib sleep call. There is an additional feature that while going into this sleep mode we can configure that while waking back up the state of the other high frequency oscillator to be restored or not. So if this configuration restore is not allowed then when we wake up from EM2 the HFRCO is the only high frequency source active. Also if the HFXO external crystal oscillator was being used, then till all the clock high frequency trees stabilize the CPU would be in stall. Although this takes a very small time to stabilize but might be critical in Real Time application cases. Also another case can be that although HFXO is not used for core clock, possibly for USB clock; after wake up from EM2 the execution would not wait fro HFXO to stabilize. This means that the program needs to separately take care of this else functionality such as USB would be hampered after waking up from EM2 mode. The emlib also provides function to prevent entry into this mode in case it is needed to prevent the use case error as we just mentioned.

    emlib Functions:
        - EMU_EnterEM2 (bool restore) : To enter in to the EM2 mode with 'restore' controlling if the high frequncy clocks need to be restored or not.
        - EMU_EM2Block() : To prevent accidental entry into the EM2 mode. This also means that after executing the sleep function the next set of code would run as it is.
        - EMU_EM2UnBlock() : To restore the ability to go into the EM2 mode.
    Exit: Interrupt from the active peripherals in this mode as specified in the Table 10.3 of d0053_efm32gg_reference_manual.pdf. The same is attached below.
    Clocks: LFXO,LFRCO,ULFRCO are active
    CPU: Sleep
    Peripherals: Low energy peripherals as listed in Table 10.1 of the d0053_efm32gg_reference_manual.pdf. The same is attached below.
    RAM: Retained

  4. Energy Mode 3 (EM3) - Stop Mode : This is another level in the energy modes where all the clocks except ULFRCO is inactive. This clock is used for Watchdog operation. Although no peripheral clocks are available in this mode still there are asynchronous peripherals that can cause an interrupt even in this mode. The events that can cause wake up are: I2C Address Match, Asynchronous Pin Interrupts on enabled GPIO pins, Analog Comparator(ACMP) state change and Voltage Comparator(VCMP) used to detect brownout condition of low voltage. It is also possible to reset the CPU if needed from this mode using the Watchdog peripheral or the Voltage Comparator(VCMP) peripheral. Else they can also be used as normal interrupt wake up sources. Again we need to take care during the wake up, all clocks need to be restored. The emlib function provides the option to disable that. However there is another problem that while waking up from EM3 it would not wait for the LFXO,LFRCO etc to stabilize. This means as a precautionary measure like in EM2 we would need to take care of stabilizing all the clocks that are being used by peripherals at the time of wake up from EM3.

    emlib Function: EMU_EnterEM3(bool restore) - The 'restore' variables gives an option to re-enable all the clocks that were disabled while entering EM3.
    Exit: Interrupt from the active peripherals in this mode as specified in the Table 10.3 of d0053_efm32gg_reference_manual.pdf. The same is attached below.
    Clocks: ULFRCO is the only clock active
    CPU: Sleep
    Peripherals: Asynchronous peripherals and Watchdog as listed in Table 10.1 of the d0053_efm32gg_reference_manual.pdf. The same is attached below.
    RAM: Retained

  5. Energy Mode 4 (EM4) - Shut Off Mode : This is the lowest power consumption mode when the current consumption is as low as 20nA. Very difficult to measure current in this mode. We generally can call that consumption being only attributed due to leakage in the chip. Else the chip is completely stopped. This means that the only way to exit this mode is a reset. Additionally the RAM in case would be flushed after the reset. Only thing that the program can come to know is the cause of the reset. There are still ways to wake up from this mode, though now there are no longer ISR but the reset entry point. There is a special peripheral called Backup RTC (BURTC) which is powered by the Backup Domain (BU). This can wake up the microcontroller to reset. Additionally the EFM32 provides a feature to retain the GPIO pin configuration even after reset when wake-up happens from EM4. The GPIO peripheral can be configured to do so. This is just in case we wanted that the thing that are controled by the EFM32 don't run erratically. Also using the same Backup Domain(BU) are Backup Retention Registers, these would also be preserved after EM4 wake-up. However to enable Backup Domain (BU) we need to perform special configuration and support the chip with additional battery or super capacitor. We would discuss on this in our future posts. The configuration of the wake-up sources as well as the wake-up state of the microcontroller needs to be performed before entering the EM4 mode. The emlib provides function to Enable the configuration locking of the EM4 mode as well as function to set the wake-up configurations of EM4 mode. This might seam to be strange mode, however there are lot of useful applications - For example if one wishes to have 1 button shutdown or power off and still have fast wake up without any special external components. Another one could be one needs really long battery life for embedded sensor applications as used in Tsunami Buoys or embedded strain sensor in concrete. Well there can be endless applications where such low power mode can be really useful.

    emlib Functions:
       - EMU_EnterEM4() : Function to Enter the EM4 mode
       - EMU_EM4Lock(bool enable) : Function to lock or unlock the EM4 mode configuration. The 'enable' is used to indicate the locking as true and unlocking as false.
       - EMU_EM4Init(EMU_EM4Init_TypeDef *em4init) : Function to configure the EM4 wake-up configuration using the 'EMU_EM4Init_TypeDef' structure. There is a default value EMU_EM4INIT_DEFAULT that can be used for this.
    Exit: Reset
    Clocks: All clocks are stopped except the ones configured for BURTC
    Peripherals: Only BURTC, Asynchronous Pin Interrupts in GPIO on specific EM4 interrupt pins.
    RAM: Only Backup Domain - Backup Retention Registers are preserved, rest are reset

Some of the Details from the EFM32GG Reference Manual:

Energy Savings and Entry conditions
Table 10.1 Showing Peripherals that are active in respective Energy Modes
Table 10.3 Showing the Trigger Sources for Wake up from Energy modes

Now that we have looked up all the modes lets try to use each one of them. There are some applied examples that need understanding of Timers. However we would cover them in details some other time.

EM1 Mode Example: Using the earlier clock settings code and then adding the blink using TIMER0.
We had earlier done the code using the Clock setting example. However while using the 'CMU_OscillatorEnable' means that we dont need to again check for setting of the oscillator in the interrupt. Its setting and wait for stabilization is done internally in the emlib. So this time we skip that. We just use the Timer 0 to blink an LED at the rate to 2 seconds.
Here is the AEM plot:
AEM Plot for the EM1 mode Current Consumption in the Program

EM2 Mode Example: Using LETIMER0 and LFXO as the clock source to blink an LED when the CPU wakes up from EM2 mode
This code uses the LETIMER to wake up the CPU from EM2 and then restores the clocks to blink the LED. Later it again goes back EM2 sleep. An important point to note here is that while accessing any of the Low Power Domain peripherals such as LETIMER or LEUART .etc. we need to enable the HFCORECLKLE in the CMU_HFCORECLKEN0 register. For this we use emlib API : CMU_ClockEnable(cmuClock_CORELE, true); This is needed so that the Low Frequency domain registers and peripherals can be accessed when in EM0 mode.

Here is the AEM Plot:
AEM Plot for the EM2 mode Current Consumption in the Program


EM3 Mode Example :Using :LETIMER0 and ULFRCO as the clock source to blink an LED when the CPU wakes up from EM3 mode

Here is the AEM plot:
AEM Plot for the EM3 mode Current Consumption in the Program


 Coming Up Soon ....
We are facing some issues with the clocking in EM4. We would post the code for all the other modes as soon as we get through with them.

Please help us by posting your comments, linking to us and providing suggestions.

Watch out!! in our next post in this Low Power Series we would talk more about Clock switching, Energy Modes and Backup Power Domain. So, see you again soon.

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Welcome to Boseji's Blog

Popular Post

Blogger templates

Welcome

Creation by Electronics Hobbyists from Bharat(India) to encourage & help people. This blog hosts the numerous innovations, discoveries and projects we provide.
Our Research Wing Adhar Labs
Contact Form | Email Address
We Support Open Source Hardware Definition v1.0
Creative Commons License
All works on this blog are licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at forbharat.wordpress.com and m8051.blogspot.com.

Permissions beyond the scope of this license may be available at http://forbharat.wordpress.com/permissions/.
Thank you for all your support.

© A.D.H.A.R Labs Research 2008-2013 . Powered by Blogger.

Follow by Email

Followers

PCB Unit Converter

mils
mm

- Copyright © Electronics for Bharat -Robotic Notes- Powered by Blogger - Designed by Johanes Djogan -