Crash in timer interupt when data type "float" is used

JoaoLopesF
Posts: 59
Joined: Thu Aug 17, 2017 5:40 pm

Re: Crash in timer interupt when data type "float" is used

Postby JoaoLopesF » Tue May 22, 2018 5:29 pm

Hans Dorn, Very good hacking, this save my day, I trying avoid to use FreeRTOS notify in my timer of 1ms to not overload the system.
Your code works very well

Thaks a lot

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: Crash in timer interupt when data type "float" is used

Postby Deouss » Wed May 23, 2018 12:24 pm

ESP_igrr wrote:Floats use the FPU while doubles are calculated in software. For reasons, using the FPU inside an interrupt handler is currently not supported.
Oh that is quite disappointing...
So when and how we can use floats? How soon you can add that FPU functionality?
Does this pertain only to Arduino framework or FreeRTOS in general when using bare esp-idf?
This is like one of the major features of ESP32 - like a super huge thing about fast FPU
Should be priority number one to implement it. Please do that asap )

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Crash in timer interupt when data type "float" is used

Postby ESP_Angus » Wed May 23, 2018 11:56 pm

Deouss wrote: So when and how we can use floats? How soon you can add that FPU functionality?
Does this pertain only to Arduino framework or FreeRTOS in general when using bare esp-idf?
This is like one of the major features of ESP32 - like a super huge thing about fast FPU
Should be priority number one to implement it. Please do that asap )
You can already use floats (with the FPU) in both Arduino & ESP-IDF. You can't do floating point calculations in an interrupt handler.

The solution is to restructure your code so that floating point calculations happen outside the interrupt handler. This is a good idea anyhow, as even with an FPU floating point math (especially division) can take more cycles than you may want to otherwise spend in the interrupt handler.

If you have code which does floating point math in an interrupt handler and you can't find a good way to structure it so that the math happens outside the interrupt handler, feel free to post it and we can probably make some suggestions.

Deouss
Posts: 425
Joined: Tue Mar 20, 2018 11:36 am

Re: Crash in timer interupt when data type "float" is used

Postby Deouss » Thu May 24, 2018 1:39 am

Yes now when I see how this is normally done it makes sense. Interrupts should be as short as possible when it comes to instruction cycles. I was first thinking to calculate values on interrupts but that could slow down whole measurement process.

JoaoLopesF
Posts: 59
Joined: Thu Aug 17, 2017 5:40 pm

Re: Crash in timer interupt when data type "float" is used

Postby JoaoLopesF » Mon May 28, 2018 9:20 pm

ESP_igrr wrote:Floats use the FPU while doubles are calculated in software. For reasons, using the FPU inside an interrupt handler is currently not supported.
The sin() and cos() functions of math.h, is for double (as ESP_igrr said -> its is calculated by software and not FPU)

Has anyone ever used fastmath.h?
These use float instead of double.
Can I replace sin and cos by sinf and cosf?

Who is online

Users browsing this forum: Baidu [Spider] and 147 guests