InterruptPort -OnInterrupt time parameter

Criticism and comments are very okay. Most of our features were added because users like you suggested them. GHI has a full team, not one engineer like most others, and we are very much dedicated ti supporting you. It seem that you already tried our devices and support and I do not need to do any sales pitch here :slight_smile: We are glad to have you as a customer.

Maybe you can let us quote you on what you just said about GHI? Can you do this please? http://www.tinyclr.com/forum/15/702/

I got OutOfMemoryException around 1 sec after this code is executed:


using System;
using System.IO.Ports;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;

namespace SCSUQuadcopter
{
    public class Program
    {
        static PWM pPwm = new PWM((PWM.Pin)FEZ_Pin.PWM.Di10);
        static InterruptPort pInt = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di1, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeHigh);
        static OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, false);

        public static void Main()
        {
            pPwm.SetPulse(2000000, 1000000);
            pInt.OnInterrupt += new NativeEventHandler(pInt_OnInterrupt);
            while (true)
            {
            }
        }

        static void pInt_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            Debug.Print(time.Millisecond.ToString() + " ");
            if (led.Read())
                led.Write(false);
            else
                led.Write(true);
            Debug.Print(time.Millisecond.ToString() + "\n");
        }
    }
}

What type of signal is driving the interrupt pin (frequency & duration)?

Interrupts queue - if youā€™re driving the interrupt pin faster than it can be serviced something will break eventually.

while (true)
            {
            }

This is EXTREMELY bad! You are killing the processor in a dead loop.

Instead use

Thread.Sleep(-1);

Good catch, Gus. I missed that, but I bet youā€™ve seen it a hundred times!

For readabilityā€™s sake I would recommend that you replace the while(true) with:

            Thread.Sleep(Timeout.Infinite);

TimeOut.Infinite is the same as -1, but it makes it more ā€œportableā€ and more likely to work if Microsoft make some change to the MF in the future and change the meaning of that -1.

The default program you get when you create a new project has the following code in it. The while(true) is used here because there is a Thread.Sleep inside the loop.

            while (true)
            {
                // Sleep for 500 milliseconds
                Thread.Sleep(500);

                // toggle LED state
                ledState = !ledState;
                led.Write(ledState);
            }
 

I m feeding the pwm signal into the interrupt port. Itā€™s 2ms and 50% duty cycle.

I just switched from c embedded programming and this is how it was done in c. I donā€™t quite get the idea of thread.sleep. Can somebody direct me a tutorial?

The while loop just makes the execution go crazy on a tight loop. Instead you want to put your thread to sleep to allow the rest of the system to work

In your c code you didnā€™t have threading :wink:

Ok got it. I will report my result later.

OK, with replacing the infinite loop with Thread.Sleep and removing Debug.Print messages, I get a pulse of 4ms. So the ISR is executed every 2ms. I think it should be alright.

EDIT: arghā€¦ I should actually look at the delay time insteadā€¦ will post results when I get to the lab.