Main Site Documentation

PANDA II : What is the Interrupt max frequency?


#1

I have a RPM sensor with 84 HZ to 840 Hz output (rpm from 850 - 8000).

port = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di0, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
port.OnInterrupt += port_OnInterrupt;
Thread.Sleep(Timeout.Infinite);

It work fine ( I measure the period) till 600 Hz , after
Failed allocation for 13 blocks, 156 bytes

The question

  • what is the max interrupt frequency?
    -is other way to measure the Period of (80 - 800 Hz) ?

I can measure the frequency of input Sensor , but I need 1 sec to measure, is to slow for me…


#2
Failed allocation for 13 blocks, 156 bytes

That is a memory issue, which makes me think that your event handler is way to complicated. You should do the bare minimum in the event handler and not create any new variables, etc.

You could also look at using input capture or doing this in RLP to see if either offers a better solution.


#3

The max is a factor of who busy is your system. There is PinCapture method to read frequencies that you can use.


#4

I did testing into interrupt rates a while ago.

Interrputs are queued in memory and then dispatched to your code. If interrupts occur faster than you can process them you will run out of memory.

When I did my testing I was able to handle in the 1200-1700 interrupts per second rate with no processing in the interrupt handler. I don’t remember the exact maximum rate.

You are handling interrupts on both edges, so at 600hz you are getting 1200 interrupts a second. Do you really need to handle both edges? Handling one edge will double you input range.

If you want higher rates, then you should look at RLP.


#5

Yes Mike is right, there is no need to handle both edges, which will slash your interrupts by half.


#6

it only this thre line + interrupt :
static void port_OnInterrupt(uint port, uint state, DateTime time)
{
if (state == 0)
{
// Falling edge - end of pulse

                      Debug.Print("*******");
        }
        else
        {
            // Rising edge - start of pulse 

                      Debug.Print("-----------");
        }

I try to reduce to frequency of interrupt - use
Port.InterruptMode.InterruptEdgeHigh ( I think it should reduce at least twice ?)

May be someone who has pullse generator - can confirm that…


#7

Debug.Print() is a high overhead function. It will make your interrupt processing very slow.

You have a pulse generator built into the hardware. Generate a PWM signal and connect it to you input.


#8

Yeah, I say it should be forbidden to use debug messages inside interrupts.

Please tag your code so it is readable. (see the notes before you click submit please)

static void port_OnInterrupt(uint port, uint state, DateTime time)
        {
            if (state == 0)
            {
                // Falling edge - end of pulse 

                          Debug.Print("*******");
            }
            else
            {
                // Rising edge - start of pulse 

                          Debug.Print("-----------");
            }


#9

THANKS!
Mike & Gus

I’ll try without Debug.Print

I have another device that I have to use the same time.(all this working fine - I 'm not add the RPM yest)
GPS 20 Hz com4
Accelerometer MMA7455L I2C
temperature max6675 -SPI

Xbee - com2

I’ll let you know when find out what is Max Interrupt frequency for Panda II


#10

I can only read under 300 Hz , if more just few second work and out of memory
whats wrong, Mike said that should work 1200 Hz
This is the code ,


using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;

namespace FEZ_Panda_II_Application1
{
    public class Program
    {
        static InterruptPort port;
        static long tiks = 0;
        static long v = 0;
        static long pulseWidth;

        public static void Main()
        {
            port = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di0, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
            port.OnInterrupt += port_OnInterrupt;
            while (true)
            {
            
            }
         }
        static void port_OnInterrupt(uint port, uint state, DateTime time)
        {
                                  
             pulseWidth = time.Ticks - tiks;
             v = pulseWidth;
             tiks =time.Ticks ;
        }
    }
}


#11

I need a example for PinCapture … NO on wiki , just promises …


#12
            while (true)
            {
 
            }

The above code is a big part of yoor problem, your burning all of your processor’s time running in a tight loop that does nothing… You should use a thrread.sleep(timeout.infinate) there instead.


#13

You mean that all program ( it’s not shown in the while loop) go to Interrupt code ?


#14

No replace the the while loop with a thread.sleep…


#15

Sorry , I don’t get it,
How I can for example output the value of the Period ?
send it to Serial port


#16

In cases like this, it may be a good idea to draft a plan. I.e.:

  • Do you need to sample continuously, or can you sample every few milliseconds?
  • How often do you plan to act on the information and how long does it take to do such processing?

With some careful management of timings you should be able to pull it off.

Also keep in mind that the .NET MF uses cooperative multitasking, that is, it will move from one thread to the next every 20ms or sooner depending on whether the current task yields its time slice once it is done. Thus the suggestion to put the [italic]while[/italic] statement to sleep it if is doing nothing, otherwise it will spin uselessly for 20ms. Invoking [italic]sleep[/italic] tells the CLR to pass the plate to the next thread. Your interruptions will run in a “separate thread” and are subject to scheduling.


#17

Do you need to sample continuously, or can you sample every few milliseconds?

Very interesting, how I can sample continuously ? I don’t have a tape .:). 100 ms will be fine
I got the point with while - sleep, so I can do in separate thread.

I will have the following Thread

  1. GPS update rate 50 ms (working fine I do not lost data)
  2. 3 axis Accelerometer rate 220 ms
  3. Temeprature 200 ms
  4. RPM 100 ms

All data goes to SD and out thru com2: Xbee


#18

THANKS !!! :smiley:

Now it works fine up to 2KHz!!!

Thanks again
Igor