Sleep and Wake on Interrupt

Does anyone have any details and/or examples of putting a Gadgeteer board to sleep and then waking it up some time later from a timer, interrupt, etc? I just wanted to get to grips with some of this stuff before I look at some low power projects that would benefit from running on a battery?

Thanks,

J.

using System;
using System.Threading;
using Microsoft.SPOT.Hardware;
using SmartSensor;

namespace SmartSensorTest
{
    public class Program
    {
        private static SmartSensor.Hardware.UserLed _led;
        private static InterruptPort _key; 
        public static void Main()
        {
            _key = new InterruptPort(STM32.Pin.PA4, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeHigh);
            _key.OnInterrupt += key_OnInterrupt;
            _led = new Hardware.UserLed();
            _led.BlinkUserLed();
            Thread.Sleep(Timeout.Infinite);
        }

        static void key_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            _led.BlinkUserLed(5,50);
            int n = 500000;

            while (n > 0) n--;

            Thread.Sleep(5000);
            PowerState.Sleep(SleepLevel.DeepSleep, HardwareEvent.GeneralPurpose);
        }
    }
}
2 Likes

@ Jason - Which mainboard are you using?

GHI use a Hibernate command that can be woken from an RTC alarm. Note - Doesn’t work on G120 yet, but I hear they are fixing that imminently.

Other boards use the PowerState method that Justin demonstrates. I don’t think we know how to set this up to wake from a timer or realtime clock yet. I had a quick go at the meetup, but it wasn’t obvious.

1 Like

@ hagster - i had a look at the STM firmware today…

You can wake using a timer if you are in Sleep but not DeepSleep as the clocks have been stopped…

So yes you can use an Interrupt or Timer etc in Sleep but Sleep doest do much, only DeepSleep saves juice.

So…

I am going to have a tinker with Sleep to save some Go Juice which will work with Timers…

So back down the rabbit hole i go…

4 Likes

This seems like a newbie question, but where do I find the NETMF or GHI information that informs about

Does it exist online?

@ hagster - I mainly use my Spider, but have a Cobra II, plus the board from the weekend. Just trying to see what can be done to keep power consumption to a minimum by only switching the device on when needed.

@ Jason - Good question…must be there somewhere…you would think… ::slight_smile:

As for me, i just ask the Swiss Oracle direct and poke about in the porting kit to see whats going on…

1 Like

@ Jason - that’s a fair question. The netmf documentation just says that the implementation is chip specific and to refer to hardware vendor.

GHI have a document about low power here

https://www.ghielectronics.com/docs/141/low-power
I have put also put some stuff on codeshare and written up some of my experiments with the G120 (nxp lpc1788) here.

https://www.ghielectronics.com/community/forum/topic?id=13119&page=3

The Spider uses an NXP chip so should be similar if you look up the correct registers

1 Like

Hi guys,

I have a weird behavior when implementing the sleep mode with the new netmf 4.3 on my G120.

I implement something very similar to this:


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.Sleep(SleepLevel.DeepSleep, HardwareEvent.OEMReserved1);

        ///Continue on with your program here
    }

    private static void interrupt_OnInterrupt(uint data1, uint data2, DateTime time)
    {
        //Interrupted
    }
}

The difference is that I have an “inactivity” counter that puts my device in sleep mode if the user has no interaction with it after a given amount of time - meaning the Sleep command is in a seperate thread, and not in the main loop - and my interrupt port is declared like this:

powerDown_resume = new InterruptPort((Cpu.Pin)G120.P2_11, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
powerDown_resume.OnInterrupt += powerDown_resume_OnInterrupt;

I works fine: after that given amount of time, the device enters in suspend mode, and, when I push the button connected to the interrupt port, it resumes, as expected.

After another inactivity period, the device goes back to sleep, as expected, but, for some reason, it wakes up by itself after 2 seconds, without having pushed any buttons.

My questions are:
With the new netmf 4.3, do we need to clear the interrupts?
Does the glitch filter works ?

By the way, my hardware works, it used to work with the same code running out netmf 4.2 (the Hibernate has been replace by PowerState.Sleep).

Thanks.

There is some issue with repeated sleeps on the G120. GHI are investigating.
https://www.ghielectronics.com/community/forum/topic?id=16365