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 We are glad to have you as a customer.
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");
}
}
}
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?
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.