Low Power

Last modified September 15, 2014

Table of Contents

Introduction

Embedded devices often must limit power usage as much as possible. Devices may lower their power consumption in many ways:

  1. Reduce the processor clock
  2. Shutdown the processor when system is idle (keep peripherals and interrupts running)
  3. Shutdown specific peripherals
  4. Hibernate the system

A NETMF device may optionally support any of these methods. Generally, all GHI devices shutdown their processor when idle. As soon as the system is idle, the processor is automatically shut off while interrupts and peripherals are still active. Peripherals are automatically enabled only when they are needed. If you require even lower power draw, you can completely hibernate the system. When the system is hibernating, it is not executing any code and no peripherals are functional. For example, data coming in on UART will NOT wake up the system. You will lose the incoming data.

Warning

When the device is hibernating, USB stops working. You cannot step through code or access the device. If your program always puts the device into hibernation, you will not be able to load a new program and will have to reload its firmware.

RTC Alarm

A common way to wake a device is using the RTC alarm. Whenever the alarm goes off, it will wake the device. The below examples require the GHI.Hardware and Microsoft.SPOT.Hardware assemblies. Use Microsoft.SPOT.Hardware.HardwareEvent.OEMReserved2 for RTC alarm. When the program starts, it will set an RTC alarm for 30 seconds in the future and then hibernate until then.

using GHI.Processor;
using Microsoft.SPOT.Hardware;
using System;

public class Program
{
    public static void Main()
    {
        RealTimeClock.SetAlarm(RealTimeClock.GetDateTime().AddSeconds(30));

        PowerState.WakeupEvents |= HardwareEvent.OEMReserved2;
        PowerState.Sleep(SleepLevel.DeepSleep, HardwareEvent.OEMReserved2);

        ///Continue on with your program here
    }
}

Interrupts

You can also wake the device using any interrupt port. Whenever any interrupt is triggered, it will wake the device. Make sure though that you only have your desired interrupts enabled. Some modules or devices can use interrupts internally that will cause spurious wakeups if not disabled. Use Microsoft.SPOT.Hardware.HardwareEvent.OEMReserved1 for interrupts. The below code creates an interrupt object and then sleeps until the selected pin is interrupted.

Tip

NETMF interrupts only function when their glitch filter is enabled or they have an event handler subscribed. Make sure to do either of those on your desired pin when using interrupts as a wakeup souce.

using Microsoft.SPOT.Hardware;
using System;

public class Program
{
    public static void Main()
    {
        var interrupt = new InterruptPort(Cpu.Pin.GPIO_Pin0, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
        interrupt.OnInterrupt += interrupt_OnInterrupt;

        PowerState.WakeupEvents |= HardwareEvent.OEMReserved1;
        PowerState.Sleep(SleepLevel.DeepSleep, HardwareEvent.OEMReserved1);

        ///Continue on with your program here
    }

    private static void interrupt_OnInterrupt(uint data1, uint data2, DateTime time)
    {
        //Interrupted
    }
}
Leave feedback about this document.
Let us know if the information presented here was accurate, helpful and if you have any suggestions.
Leave feedback about this document.
Let us know if the information presented here was accurate, helpful and if you have any suggestions.

* Indicates required fields.
This form is only for feedback not support.
Review our how to find information guide on locating helpful resources.