Hello All.
It seems a floating point division is treated differently inside a task context verses outside e.g.
portFLOAT var1 = 2.0;
portFLOAT var2 = var1 / 2.0;
gives var2 = 1.0 if implemented in main().
gives var2 = 1.999878 if implemented inside a task().
I’m currently using the MPLAB SIM with MPLAB 8.56
Can’t seem to nail down the issue so any ideas/help would be appreciated.
BR, Steve
PIC32MX360512L floating point division
PIC32MX360512L floating point division
Hi Steve,
I’m not sure how the PIC32 compiler / libraries deal with variables for the soft-float routines, but I know the PIC18 libraries use global variables that must be saved with the task’s context during every task switch. Are you running other tasks that could also be performing floating point operations? You might want to check if the same is true for the PIC32 parts and if so, if the port is in fact saving the math variables to each task’s stack.
Ken
PIC32MX360512L floating point division
Hi Ken.
Thx for the feedback.
At the moment, I have a single task (just starting out with MPLAB/freeRTOS).
Steve
PIC32MX360512L floating point division
One further point…
portFLOAT va2r = constant / constant works…. i.e. var2 = 4.0 / 2.0 = 2.0
PIC32MX360512L floating point division
I’m currently using the MPLAB SIM with MPLAB 8.56As a general rule I don’t like to try and support anything that is done on a simulator. You are testing a small piece of software (FreeRTOS) on a large piece of software (the simulator), and generally it is the large piece of software that is at fault. In this case, when I was developing the FreeRTOS, the MPLAB simulator definitely did not simulate any FreeRTOS applications correctly, although that was some time ago and maybe it is fixed now?
gives var2 = 1.0 if implemented in main().I would say the result was about as close to 1 as a 32bit CPU could get without actually being 1. I don’t see this as a particular issue (?).
gives var2 = 1.999878 if implemented inside a task().
‘m not sure how the PIC32 compiler / libraries deal with variables for the soft-float routines, but I know the PIC18 libraries use global variables that must be saved with the task’s context during every task switchThe PIC18 is a completely different type of processor, and the compiler does not generate re-entrant code, the PIC32 should do and I would be amazed if it used global memory areas. Despite which, the flop test tasks do not fail, and would if global memory was being used.
portFLOAT va2r = constant / constant works…. i.e. var2 = 4.0 / 2.0 = 2.0There you are dividing a const by a const, and most compilers (if not all) would do the calculation at compile time and not run time, so your result is not surprising to me. Have you checked the generated asm code to see if anything is being done by the PIC32 itself to get an answer to the division? Regards.
PIC32MX360512L floating point division
Hi Richard.
Thx for the great feedback. Good point about the compiler (probably) dealing with the const / const.
My example wasn’t the best to illustrate the issue from an accuracy point of view..i.e. if
portFLOAT var1 = 2.0;
portFLOAT var2 = var1 / 4.0; gives 0.9999390 so clearly a computation issue I have an evalutation board on the way so will continue with that…. Cheers, Steve
portFLOAT var2 = var1 / 4.0; gives 0.9999390 so clearly a computation issue I have an evalutation board on the way so will continue with that…. Cheers, Steve
PIC32MX360512L floating point division
Which version of FreeRTOS are you using?
There was a change made between V6.0.1 and V6.0.2 that could effect that (unlikely, but could). If your version is pre V6.0.2 could you update to the latest version and try it again?
Regards.
PIC32MX360512L floating point division
Hi Richard.
I’m using 6.1.0
Steve
PIC32MX360512L floating point division
Hi Richard and All.
Things are working nicely with the PIC32 starter kit…
Thx again for the feedback!
Cheers,
Steve
Steve