cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS : Inerrupts

AGHAZ
Associate II

I work with FreeRTOS and I have two interrupts that can be triggered at the same time: An interrupt on a Timer in Input Capture mode (because I'm working with an ultrasound sensor HCSR04) and a UART interrupt (which is the reception of 'a character ). The interrupt on the timer is still not functional which causes the loss of sensor information. How to handle both interrupts in this case?

5 REPLIES 5
Jack Peacock_2
Senior III

For simultaneous interrupts you will have to decide which has the higher priority by assigning NVIC priority levels to each request source. If you assign the same priority to both requests then one or the other will be handled first. You can use nested interrupts (supported in FreeRTOS) to immediately go from one ISR to the next without a stack pop/push (look up tailchaining in the NVIC).

If your design can't tolerate one interrupt waiting for the other to complete then you may have to look for a dual-core processor that can execute two instruction streams at the same time.

Jack Peacock

AGHAZ
Associate II

Thank you Jack 🙂

Piranha
Chief II

If the timer interrupt is not working at all, then either the expected event is not happening, you haven't enabled it or some other higher priority interrupt is stuck in a loop. If it's working but is executed after UART interrupt, it doesn't impact the measured data because the time value is captured by timer hardware independently.

Additional tip - use timer not only for input capture, but also use an another channel of the same timer for trigger signal generation. That way the whole trigger-capture process can be done by hardware and you will get the best accuracy unaffected by software timings.

I hope that was not a suggestion to use dual core because of that sensor... 😉

AGHAZ
Associate II

Thank you Piranha for your help