Hi
I'm tryying to generate data pulses on one of the outputs of my Netduino plus 2 board which have to have pulse width of 150µs, 300µs and 450µs.
Sine the lowest resolution of the timer in the micro framework is 1 ms, I need another approach
I would like to have it event based, since it should be able to receive IR commands from a remote control in parallel to this, so looping in a loop until ticks indicates that 150µs has passed is not an option, since I guess it will block all other execution
I have tried to use the PWM functionality on pin 10, and generate pulses each 150µs and define pin 11 as an interrupt port, and then connect pin 10 to pin 11.
I have tried the code below, but both the board and Visual Studio 2013 seems to be unstable when I try to execute the code.
Often I get the errormessage: An unhandled exception of type 'System.OutOfMemoryException' occurred in Microsoft.SPOT.IO.dll and often the board stops responding.
If I change the frequency of the PWN from 3.333 Hz to 1.000 Hz, then it works more often, but still not every time.
Until now the eventhandler for the interrupt port does not contain any code at all.
I'm using SW version Version 4.3.1 on my Netduino plus 2 board
I hope anybody can help on this
Thanks
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
namespace NetduinoApplicationPwmInterrupt
{
public class Program
{
public static void Main()
{
Debug.Print("Trace #1");
OutputPort led = new OutputPort(Pins.GPIO_PIN_D5, false);
InterruptPort myInterruptPort = new InterruptPort(Pins.GPIO_PIN_D11, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
myInterruptPort.OnInterrupt += new NativeEventHandler(port_OnInterrupt); // Create an event handler
PWM led1 = new PWM(PWMChannels.PWM_PIN_D10, 3333, .5, false); //period time = 150 uS when triggering on both edges
led1.Start();
while (true)
{
led.Write(true);
Thread.Sleep(10);
led.Write(false);
Thread.Sleep(400);
}
}
private static void port_OnInterrupt(uint port, uint data, DateTime time)
{
//var myVar = Microsoft.SPOT.Hardware.Utility.GetMachineTime().Ticks;
}
}
}