7
\$\begingroup\$

I have been developing control software and I need to know how much time it takes to execute an interrupt service routine (ISR).

I have decided to use a dedicated GPIO pin of my microcontroller and an oscilloscope for that purpose. I set the pin to high at the beginning of the ISR execution and then reset it to low at the end of the ISR. I have configured my oscilloscope in such a manner that the trace record is triggered by the rising edge of the specified channel.

My idea was that, in case I measure the pulse duration via the oscilloscope, I will have the actual execution time of the ISR. This method works but I have found that the execution time fluctuates due to the internal logic in the ISR.

I would like to measure the worst case execution time but I am not sure how to set the trigger on my oscilloscope to be able to record the longest pulse. How can I do that?

Oscilloscope: Tektronix TDS2014

\$\endgroup\$
5
  • 3
    \$\begingroup\$ It would depend on the oscilloscope make and model obviously. What make/model it is? Have you read the oscilloscope manual how to do that if it is even possible? Also, which MCU make/model you have? It might contain features such as CPU cycle counters or timers so you can just read timestamps at entry and exit to find out difference. \$\endgroup\$
    – Justme
    Commented Jun 26, 2020 at 13:25
  • 1
    \$\begingroup\$ @Justme, thank you for your reaction. As far as my oscilloscope. I have been working with the Tektronix TDS 2014. \$\endgroup\$
    – Steve
    Commented Jun 26, 2020 at 13:34
  • 1
    \$\begingroup\$ 'Old skool' storage 'scopes could overlay successive images, and it would be easy to trigger on the leading edge of the pulse, and pick out the longest by eye. Many digital 'scopes have an 'infinite persistence' mode to emulate this facility. Unfortunately, a quick look at the TDS2014 data sheet suggests it does not. Your next best bet is to simply look at the traces as they whizz past, and estimate where the rightmost trailing edge gets drawn. \$\endgroup\$
    – Neil_UK
    Commented Jun 26, 2020 at 13:46
  • \$\begingroup\$ What is the interrupt frequency? Is it regular? Do the interrupts come in bursts (if so, what is the period and the number in each burst)? Or is it something you can provoke, e.g. by external inputs under your control (for testing it). \$\endgroup\$ Commented Jun 27, 2020 at 11:21
  • \$\begingroup\$ This can also be a place where a USB logic analyzer feeding into something scriptable like sigrok really shines - you can actually create and examine a record, do histograms, see the pattern of long vs. short execution, etc. \$\endgroup\$ Commented Jun 27, 2020 at 22:33

2 Answers 2

11
\$\begingroup\$

On TDS2014, the DISPLAY button menu includes persistence, which can be set to infinite. It should be able to capture the pulse-width of the GPIO signal.
If the ISR duration was constant, you should see a single pulse-fall, and a constant pulse-width assuming that trigger was set to start on the GPIO's rising edge.

Do ensure that your target ISR is not pre-empted by a different higher-priority ISR.

\$\endgroup\$
3
\$\begingroup\$

Why not use a software solution ... start a timer (if you have a free timer available) at the beginning of the ISR, stop it at the end, and maximize its value with all previous results. So you have the maximum (longest duration) of many ISR calls.

Than at some time print it via UART (or another way) to check the value, or use a breakpoint.

If you want to use an oscilloscope: I only have a fairly simple oscilloscope myself, and what you want seems like quite advanced for an oscilloscope. However, some oscilloscopes have a feature to store all measured data to USB or to a PC, where you can write a program (or use some spreadsheet) to calculate the longest duration.

\$\endgroup\$
5
  • 3
    \$\begingroup\$ thank you for your reaction. I have originally chosen the software approach but the results were weird. So I have decided to use the approach with the oscilloscope. It seems to me to be the simplest way how to do that. \$\endgroup\$
    – Steve
    Commented Jun 26, 2020 at 13:46
  • 3
    \$\begingroup\$ Sometimes you don't even have a decent timer to dedicate to this, although if you have, it may be a more flexible solution \$\endgroup\$
    – pipe
    Commented Jun 26, 2020 at 14:07
  • \$\begingroup\$ @Steve sometimes indeed a hardware solution is better as it rules out any software error (on the other hand, a software solution sometimes is more accurate or easier). Both ways should work. \$\endgroup\$ Commented Jun 28, 2020 at 20:53
  • \$\begingroup\$ @pipe Yes, the answer works assuming there is a free timer. \$\endgroup\$ Commented Jun 28, 2020 at 20:53
  • 1
    \$\begingroup\$ Using a timer is fine if you're sure about your clocks, both system clock an peripheral bus clocks. \$\endgroup\$ Commented Jun 29, 2020 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.