4 months, 2 weeks ago.

Issue with rising edge interrupt delay in Nucleo F103RB

Hello, I was using this code for generating an interrupt on the rising edge of a pwm signal(which i also generated in this code). The pwm signal seems to work properly using fastpwm but as shown in the image, the interrupt tends to come more than 2 micro seconds later which is problematic for my project. Could anyone please tell me how to resolve this?


#include "mbed.h"
#include "FastPWM.h"
DigitalOut Pin1(PA_7);
FastPWM pwmPin1(PA_9,1);
InterruptIn interrupt1(PB_10); 
int flag =0;
void ISR0()
if(Pin1==0) Pin1=1;
else Pin1=0;
int main() {
    pwmPin1.period_ticks (1800); 
    pwmPin1.pulsewidth_ticks(90);//setup duty cycle to 5%

      while(1) {

Note that the delay is definitely not due to digitalout since i checked it by running a code which constantly toggles the digitalout pin and the time delay was less than half a microsecond.

How does this compare if you run the same code on the Mbed LPC1768 ?

posted by Paul Staron 07 Apr 2019

Unfortunately I don't have that device with me.

posted by Bajrangi Bhaijaan 07 Apr 2019

You should time just the code in the body of the ISR function and see how long that actually takes to run. It's possibly more clock ticks than you might expect. Elsewhere people recommend skipping HAL layer and setting bits in registers directly for fastest response times.

posted by Graham S. 08 Apr 2019

Okay I'll try that because I think i read somewhere than interrupt acknowledge on nucleo takes somewhere around 200ns. So the delay is probably due yo HAL layer itself

posted by Bajrangi Bhaijaan 08 Apr 2019
Comment on this question

1 Answer

4 months, 2 weeks ago.

The same result on the LPC1768, 2.64uS to be exact.

This issue has been asked before and is basically due to the time taken to check and service the interrupt, see info here:

You need to log in to post a question