Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

PIC32MX360512L floating point division

Posted by steveb on October 10, 2010
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

RE: PIC32MX360512L floating point division

Posted by Ken Pettit on October 11, 2010
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

RE: PIC32MX360512L floating point division

Posted by steveb on October 11, 2010
Hi Ken.

Thx for the feedback.

At the moment, I have a single task (just starting out with MPLAB/freeRTOS).

Steve


RE: PIC32MX360512L floating point division

Posted by steveb on October 11, 2010
One further point...

portFLOAT va2r = constant / constant works.... i.e. var2 = 4.0 / 2.0 = 2.0




RE: PIC32MX360512L floating point division

Posted by Richard on October 11, 2010
“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.

RE: PIC32MX360512L floating point division

Posted by steveb on October 12, 2010
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



RE: PIC32MX360512L floating point division

Posted by Richard on October 12, 2010
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.

RE: PIC32MX360512L floating point division

Posted by steveb on October 13, 2010
Hi Richard.

I'm using 6.1.0

Steve

RE: PIC32MX360512L floating point division

Posted by steveb on October 16, 2010
Hi Richard and All.

Things are working nicely with the PIC32 starter kit...

Thx again for the feedback!

Cheers,
Steve


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner