I have just done some real quick power tests on the G120 to compare the changes with the latest firmware.
Debug.Print("Sleep for 8secs");
Thread.Sleep(8000);
Debug.Print("Doing some hard work");
int n = 500000;
while (n > 0) n--;
Debug.Print("Hibernates/Sleeps");
Thread.Sleep(1000);
PowerState.Sleep(SleepLevel.DeepSleep, HardwareEvent.OEMReserved2);//Hibernate in 4.3.2
Does anyone want to try this in a loop using the Real Time Clock wakeup. I’m sure I had it working, but now it will only do the first deepsleep. Not sure what I changed.
no no, I just meant we should run without VS2012 debugger attached.
:think: can you try to reset the RTC. It may something wrong with RTC and the Alarm can not be set. You can check by GetAlarm to make sure Alarm was set correctly.
To simplify things I gave up with the RTC and am just using an interrupt port.
Here is my code for:-
static OutputPort LED1G120HDR = new OutputPort(GHI.Pins.G120.P1_5, true);
static OutputPort LED1 = new OutputPort(GHI.Pins.G120.P1_14, false); //46
static OutputPort LED2 = new OutputPort(GHI.Pins.G120.P1_17, false); //49
static OutputPort LED3 = new OutputPort(GHI.Pins.G120.P1_16, false); //48
static OutputPort LED4 = new OutputPort(GHI.Pins.G120.P1_15, false); //47
static InterruptPort SW1 = new InterruptPort(GHI.Pins.G120.P2_13, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
public static void Main()
{
LED4.Write(true);
Thread.Sleep(4000);
LED4.Write(false);
SW1.EnableInterrupt();
SW1.OnInterrupt += new NativeEventHandler(IntButton_OnInterrupt);
while (true)
{
LED3.Write(true);
Thread.Sleep(4000);
LED3.Write(false);
LED2.Write(true);
int n = 500000;
while (n > 0) n--;
LED2.Write(false);
LED1G120HDR.Write(true);
SW1.EnableInterrupt();
PowerState.Sleep(SleepLevel.DeepSleep, HardwareEvent.OEMReserved1);
LED1G120HDR.Write(false);
}
}
static void IntButton_OnInterrupt(uint port, uint state, DateTime time)
{
Debug.Print("Button Pressed");
}
The first loop always works fine. I can see the debug LED on the G120HDR board light up until I push the button. The next loop through the LED just flashes really quickly and the loop continues. The other LED’s show me that the rest of the loop is working fine. E.g LED4 only lights up after a reset.
The first loop works ok but after the first wake up the led’s dont change and if i connect MFDeploy i can see the debug output but device is not going to sleep…
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHI.IO;
using GHI.Pins;
using System;
using System.Threading;
namespace MFConsoleApplication1
{
public class Program
{
static OutputPort LED1G120HDR = new OutputPort(GHI.Pins.G120.P1_14, true);
static OutputPort LED1 = new OutputPort(GHI.Pins.G120.P1_17, false); //46
static OutputPort LED2 = new OutputPort(GHI.Pins.G120.P1_16, false); //49
static OutputPort LED3 = new OutputPort(GHI.Pins.G120.P1_15, false); //48
static OutputPort LED4 = new OutputPort(GHI.Pins.G120.P1_9, false); //47
static InterruptPort SW1 = new InterruptPort(GHI.Pins.G120.P2_8, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
public static void Main()
{
LED4.Write(true);
Thread.Sleep(4000);
LED4.Write(false);
SW1.EnableInterrupt();
SW1.OnInterrupt += new NativeEventHandler(IntButton_OnInterrupt);
SW1.EnableInterrupt();
while (true)
{
LED3.Write(true);
Thread.Sleep(4000);
LED3.Write(false);
LED1G120HDR.Write(true);
Debug.Print("Feeling sleepy...");
PowerState.Sleep(SleepLevel.DeepSleep, HardwareEvent.OEMReserved1);
LED1G120HDR.Write(false);
}
}
static void IntButton_OnInterrupt(uint port, uint state, DateTime time)
{
Debug.Print("Button Pressed");
}
}
}