Hibernate and Watchdog

Switching from 4.1 to 4.2 I notice that low power mode on EMX seems to not work as before. May be I am wrong, but in the past I was using hibernate with the following:



As far as I remember, without instantiating directly an innterupt port I was observing that pressing button on my board (inputport) was waking up the board. 

Now It seems not working as before, pressing the button does not wake up the board, but the watchdog does (whereas  I didn't notice this behavior in the past).

Up :-[

@ leforban -


InterruptPort interrupt = new InterruptPort((Cpu.Pin)....
interrupt.EnableInterrupt();
interrupt.OnInterrupt += new NativeEventHandler(interrupt_OnInterrupt);
Power.Hibernate(Power.WakeUpInterrupt.InterruptInputs);

Make sure you have these in your code

That doesn’t work either the system go hibernate but it wake up only with watchdog any idea?

What device and version, please?

Hello Dat this happen on EMX and 4.2.11.1 Premium Lib.

Our application is suposed to enter in Hibernate mode using a input port. Before entering into hibernation we dispose the port and assign the pin to an interrupt port.

The board then sleeps but action on the interrupt port does not wake up the board and the watchdog (30 second) restart the system.

@ leforban -

Can you tell us what pin you are trying, plese? We want to go exactly into your problem.

We are using IO17.

Here’s a testcase:

using System;
using System.Threading;
using Microsoft.SPOT;
using GHI.Hardware.EMX;
using GHI.Premium.Hardware.LowLevel;
using Microsoft.SPOT.Hardware;



namespace MFConsoleApplication1
{
    public class Program
    {
        public static void Main()
        {
            Debug.Print(
                Resources.GetString(Resources.StringResources.String1));

            OutputPort LED;
            LED = new OutputPort((GHI.Hardware.EMX.Pin.IO33), true);
            InputPort bp = new InputPort(GHI.Hardware.EMX.Pin.IO17, true, Port.ResistorMode.PullUp); 
            GHI.Premium.Hardware.LowLevel.Watchdog.Enable(30000);
            while (true)
            {
                LED.Write(!LED.Read());
                Thread.Sleep(1000);
                GHI.Premium.Hardware.LowLevel.Watchdog.ResetCounter();
                if (!bp.Read())
                {
                    Power.Hibernate(Power.WakeUpInterrupt.InterruptInputs);
                }
            }
        }
    }
}

@ leforban -

Hello,

You should need a pin as InterruptPort to wake up from hibernate.
Input port may not work.

Code can be like my post #2

Hello Dat, I hope you are fine

Please try this code and check this does not work!

using System;
using System.Threading;
using Microsoft.SPOT;
using GHI.Hardware.EMX;
using GHI.Premium.Hardware.LowLevel;
using Microsoft.SPOT.Hardware;



namespace MFConsoleApplication1
{
    public class Program
    {
        public static  OutputPort buz = new OutputPort(GHI.Hardware.EMX.Pin.IO13, false);
        public static bool toggleOnOff = false;
        public static void bp_on_interupt(uint port, uint state , DateTime time)
        {
            buz.Write(!buz.Read());
            Thread.Sleep(50);
            buz.Write(!buz.Read());
            Debug.Print("Button pressed");
            if (!toggleOnOff)
            {
                toggleOnOff = true;
                Power.Hibernate(Power.WakeUpInterrupt.InterruptInputs);
                toggleOnOff = false;
            }
        }
        public static void Main()
        {
            Debug.Print(
                Resources.GetString(Resources.StringResources.String1));

            OutputPort LED;
            LED = new OutputPort((GHI.Hardware.EMX.Pin.IO33), true);
            InterruptPort bp = new InterruptPort(GHI.Hardware.EMX.Pin.IO17, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            bp.EnableInterrupt();
            bp.OnInterrupt += new NativeEventHandler(bp_on_interupt);

            GHI.Premium.Hardware.LowLevel.Watchdog.Enable(30000);
            while (true)
            {
                LED.Write(!LED.Read());
                Thread.Sleep(1000);
                GHI.Premium.Hardware.LowLevel.Watchdog.ResetCounter();
                
            }
        }
    }
}

What am I doing wrong?

You will notice that pressing button does not wake up the board and that the watchdog fires after 30sec of hybernation.

@ leforban -

There are 2 thing, one from our firmware, and one from your code: :slight_smile:

  • First thing is, hard to explain but it related to one of LCD Pin. So to get hibernation work on EMX, you please set LCD config. If you don’t use LCD in your project, then you just use FEZ Config to set LCD configuaration to T35 (or any), that is fine.

  • Second is, you call hibernate in side interrupt function, and use that interrupt to wake up EMX, you will be in a loop hibernate -> wakeup -> hibernate -> wakeup… as I just tested here

Try with my code below for testing

using System;
using System.Threading;
using Microsoft.SPOT;
//using GHI.Pins;
//using GHI.Processor;
using GHI.Premium.Hardware;
using GHI.Premium.Hardware.LowLevel;
using GHI.Hardware.EMX;
using Microsoft.SPOT.Hardware;

namespace EMX_TestInterruptHibernateUser
{
    public class Program
    {
      
         //static OutputPort LED= new OutputPort((GHI.Pins.EMX.IO48), true);
         //static InterruptPort bp = new InterruptPort(GHI.Pins.EMX.IO30, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
         //static InputPort buttontest = new InputPort(GHI.Pins.EMX.IO23, false, Port.ResistorMode.PullUp);

        static OutputPort LED = new OutputPort((GHI.Hardware.EMX.Pin.IO48), true);
        static InterruptPort bp = new InterruptPort(GHI.Hardware.EMX.Pin.IO30, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
        static InputPort buttontest = new InputPort(GHI.Hardware.EMX.Pin.IO23, false, Port.ResistorMode.PullUp);
        public static void bp_on_interupt(uint port, uint state, DateTime time)
        {
            Debug.Print("Wakup ");
            
        }
        public static void Main()
        {
            bp.EnableInterrupt();
            bp.OnInterrupt += new NativeEventHandler(bp_on_interupt);
            while (true)
            {
                LED.Write(!LED.Read());
                Thread.Sleep(500);
                if (buttontest.Read() == false)
                {
                    Power.Hibernate(Power.WakeUpInterrupt.InterruptInputs);
                }
            }

        }

    }
}

Dat

1 Like

Supergreat, now we just need a wakeup on a timer…?

And also please let us know on which boards to use the LCD hack…?

@ njbuch -

should only on EMX 4.2 and it is fixed in 4.3 - next release

Timers or LCD hack?

@ Dat - Ping… I am not clear on your answer…

@ njbuch -

I meant 4.3 we fixed that problem.
But 4.2 we are considering, so use our workaround above.

I am also not clear about your question related to timer :slight_smile:

This thread is still hanging…
https://www.ghielectronics.com/community/forum/topic?id=15296&page=2

I am using LCD pin as GPIO. So I can’t use FezConfig to set LCD configuration. I need to set configuration manually. How to achieve that programatically? Does this bug refers to the first known issue described in the release note?

You may be right but for now it hibernate and does not wakeup so I can not confirm

Ok now it’s time to solve that. We have some customers that need to have this feature.

The power off button is connected on IO17 as an input port.

The wake up button is IO18 as interuptport.

As I already said LCD pins are used for other purpose in my product. Any way I can do something like:



Configuration.LCD.Configurations c = new Configuration.LCD.Configurations(800, 600, true, false, false, false, false, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 1);
                    Configuration.LCD.Set(c);

But this has no effect after 5 second the board reboot


GHI.Premium.Hardware.LowLevel.Watchdog.Enable(5000);
tab_V[channel].affect(true);
bpc.list_of_bpc[1].in_port.Dispose(); // this dispose IO18 previously declared as Inputport.
InterruptPort bp = new InterruptPort(GHI.Hardware.EMX.Pin.IO18, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
Thread.Sleep(100);
bp.EnableInterrupt();
bp.OnInterrupt += new NativeEventHandler(bp_on_interupt);
                    
Configuration.LCD.Configurations c = new Configuration.LCD.Configurations(800, 600, true, false, false, false, false, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 1);
Configuration.LCD.Set(c);
Debug.Print("Hibernate");
Power.Hibernate(Power.WakeUpInterrupt.InterruptInputs);

 
public static void bp_on_interupt(uint port, uint state, DateTime time)
        {
            Debug.Print("Wakup");
            //PowerState.RebootDevice(false);
        }