I am seeing a floating point rounding condition (error??) that I do not expect. It causes a problem when two floats are added together and the resultant value is assigned to an integer. Here's the code snippet from my pwm configuration routine...
#define CLK_RATE_US 0.010 // 10 ns
float totalPrdTm_us; // pwm period
float t1Tm_us; // transistor 1 active time
float t2Tm_us; // transistor 2 active time
Uint16 totalPrdClks; // clocks in pwm period
t1Tm_us = .20;
t2Tm_us = .40;
totalPrdTm_us = t1Tm_us + t2Tm_us; // total period = 0.60 in watch window (float format)
// totalPrdTm_us as displayed in watch window in hex format is 0x3F199999
totalPrdClks = totalPrdTm_us / (float)CLK_RATE_US ; // result = 59, expect 60
totalPrdTm_us = 0.60; // total period
// totalPrdTm_us as displayed in watch window in hex format is 0x3F19999A
totalPrdClks = totalPrdTm_us / (float)CLK_RATE_US ; // result = 60, as expected
I can work around this by adding some very small value as follows:
totalPrdClks = totalPrdTm_us / (float)CLK_RATE_US + 0.0001;
This is annoying. I have checked this on another processor / compiler and the result of the addition results in the correct hex value of 0x3F19999A, and hence the correct final value of 60.
Is this the expected behavior of the CCS compiler?
This is a DSP/BIOS project running on the F28335 experimenter's kit.
CCS 3.3.82.13
Integrated Develpment 5.98.0.34
BIOS 5.33.04
Codgen 5.14
Silicon Rev 00.00.02
Regards,
Scott
