This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Measuring the frequency of an interript

Hello,

I was wondering what is the best way to measure the frquency of an interrupt?

I would like gather some statics on the running time of an ADC interrupt.

Thanks

  • Hi Daniel,

    If you have a logic analyzer, the less intrusive way to measure the frequency of your interrupt is to toggle a GPIO pin on/off when you enter the interrupt. You can even up a GPIO toggle at the beginning and end of the interrupt to profile how long your interrupt is taking. Alternatively, you can take a time stamp of when you enter the interrupt by getting the number of clock ticks have passed using Clock_getTicks(). If you store the previous tick count, then you can even get an approximate on how long since the interrupt triggered (careful with Clock rollover). Then, you can use a Log_write1() or System_printf() to show the data. A Log_write1() would be preferable since it is more lightweight, but you will have to make sure logs are enabled in your cfg file. It is also possible to create an array to store the ticks or tick differences and use a breakpoint to stop and look at the data.

    Regards,
    Gilbert
  • thanks Gilbert, so which one of these would be better?

    void testInterrupt(){

    PF2 ^= 0x04; //toggle PF2
    Stuff();
    }

    or

    void testInterrupt(){
    PF2 ^= 0x04; //toggle PF2
    Stuff();

    PF2 ^= 0x04; //toggle PF2

    }

    I am assuming the first one finds the time between interrupts and the second is how long it takes to execute the ISR?

  • With the second one, you can still measure how long until the next interrupt is service by seeing how long from the falling edge to the next rising edge (or rising to falling depending on how the GPIO is initially set). Otherwise, you can stick with the first one, but you would need to subtract the about of time it takes to execute Stuff().

    Regards,
    Gilbert
  • Hello Glibert, thanks for your reply.

    Please bear with me, as I am a student, just learning here.

    So, I want to measure the ADC interrupt frequency. Lets say I initialise PF2 to 0, and use the following:

    void testInterrupt(){
    PF2 ^= 0x04; //toggle PF2
    Stuff();

    PF2 ^= 0x04; //toggle PF2

    }

    .

    lets say this is the output. on the oscilloscope. 

    Between A and B, this corresponds to the running time of Stuff(). Is that right?

    Between B and C, is the time is take to re-enter the ISR. is that right?

    Between A and C, is one period of the ISR. So 1/period will be the frequency of the interrupt. is that right?

    Thanks
    Daniel

     

  • You are correct about both your first two assessments. The third one is slightly incorrect, but I will take the blame for that due to a misinterpretation on my part about your question. To take the measurement of the interrupt frequency, you would double the value between A and C to get the correct period (your previous option 1 would have been better for this since in includes A through C). Then, you would take 1/period to calculate the frequency.

    Regards,
    Gilbert