MATLAB: When I profile a model running in a C2000 Interrupt Service Routine, the profiler data is blank, why is this and how to fix it

Embedded Coder

When I profile a model running in a C2000 Interrupt Service Routine, the profiler data is blank. Why are my blocks in the profiler data showing as zero ns execution time? Is there anything additional that I have to do to get the exact timings when running code in external mode?

Best Answer

Unfortunately, there is a limitation in profiling Interrupt Service Routines. The profiling data is not supported directly for Blocks, when there is task execution preemption.
The only way to measure the execution of the algorithms in the model is to disable the interrupts and measure just the algorithm timing. Alternatively, if you want to measure the timing of the ISR, then you do it using GPIO toggle.
You can add GPIO toggles before entry and after exit of ISR. and measure the time in between the toggles. For this you will need to add custom code in the model. In the attached model, we have initialized the required GPIO in 'Initialize Function' and using Custom code Output function to set and clear the GPIO. The set is done at function execution and clear is done at function exit which will put the code at the beginning and the end of the function (in this case step function).
You can use the same approach for ISR as well. If you want to measure the timings of the ADC block you may have to place the ADC inside a subsystem and make it atomic (right click on Subsystem -> Block Parameters) before placing the custom code for GPIO set and clear.