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
Hi Ken.
Thx for the feedback.
At the moment, I have a single task (just starting out with MPLAB/freeRTOS).
Steve
One further point...
portFLOAT va2r = constant / constant works.... i.e. var2 = 4.0 / 2.0 = 2.0
“I'm currently using the MPLAB SIM with MPLAB 8.56”
As 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().
gives var2 = 1.999878 if implemented inside a task().”
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 (?).
“'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”
The 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.0”
There 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.
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
Hi Richard.
I'm using 6.1.0
Steve
Hi Richard and All.
Things are working nicely with the PIC32 starter kit...
Thx again for the feedback!
Cheers,
Steve