Hi,
In an earlier post Gus told me I could easily capture 500 pulses per second using an interrupt port.
http://www.tinyclr.com/forum/10/1974/
However if I run the following code counting 500 pulses takes 1674 ms. This is more than I expected. Is there a better/faster way of counting pulses?
public class Program
{
static int i = 0;
public static void Main()
{
InterruptPort interruptPort = new InterruptPort((Cpu.Pin)17, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
interruptPort.OnInterrupt += new NativeEventHandler(_interruptPort_OnInterrupt);
OutputPort outPutPort = new OutputPort((Cpu.Pin)18, true);
Stopwatch s = new Stopwatch();
s.Start();
while (i < 500)
{
outPutPort.Write(false);
outPutPort.Write(true);
}
s.Stop();
Debug.Print(s.ElapsedMilliseconds.ToString());
Thread.Sleep(-1);
}
static void _interruptPort_OnInterrupt(uint data1, uint data2, DateTime time)
{
i++;
}
}
Thanx!