Interrupt speed

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!

I don’t know why yours is coming out this way, but I do know that I have been able to do about 8000/second with similar code. i will take a look at yours.

[quote] while (i < 500)
{
outPutPort.Write(false);
outPutPort.Write(true);
}
[/quote]

This is using 100% processor not leaving any room for anything to run reasonably!

Indeed, you are measuring the time it takes to switch the output port 500 times on/off instead.

You could connect a PWM pin to the input and set up PWM to run at 1kHz, then see if your code can follow.

I wil try a pwm signal. Thanks!