cancel
Showing results for 
Search instead for 
Did you mean: 

Floating point calculation in ISRs

YWang.15
Associate II

Hi there,

I am using an STM32 G4 MCU for my project, and the FPU is enabled for this project. I need to implement complex floating point calculations in different ISRs with different priorities. Are there any potential risks associated with doing this? If so, are there any solutions to mitigate the problem?
A short code snippet is shown below:
#incldue <math.h>

float a;

float b;
float k = const_float_value;
float c;
float d = const_float_valued;
float e;


void isr_adc_high_handler(void)
{
a = some_float_value; //ADC value converted to a

b = some_other_float_value // ADC value converted to b
c = k * (a + b)/(a-b);
}


void isr_sys_tick_low_handler(void)
{
e = c * d; //Convert ADC sample result to e every 1ms
}

Thanks!

1 REPLY 1

> Are there any potential risks associated with doing this?

The ISR execution will last longer than if you wouldn't use floating point, because the processor needs to stack (and unstack at ISR exit) the FPU registers. Whether this is a risk or not depends on your particular needs (e.g. required minimal latencies for interrupts of the same or lower priority).

JW