This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F280025C: Float conversion compiler bug / silicon errata issue?

Part Number: TMS320F280025C

Tool/software:

Hi there,

I have discovered a strange issue where during a float calculation the expected values fluctuate when the result is expected to be around 3328.0f (millivolts measured from an ADC). I am fairly certain this is a silicon / errata issue as no matter where I do this calculation in my code and no matter which variables I use to store the result it continues to fluctuate. (I tried doing this calculation in main() versus in a timer triggered interrupt and the result was the same).

To demonstrate the issue, I did the same calculation using uint32_t and I did not see this fluctuation. I then cast the result to a float (and divide by 10.0f) and I again see the fluctuations.

ch3_voltage_average_dmV is type uint32_t.

ch3_voltage_average_mV[1] is type float

To preserve accuracy when using uint32_t, ch3_voltage_average_dmV is 10x the size of ch3_voltage_average_mV.

You can see the first line where the uint32_t calculation is performed:

 ch3_voltage_average_dmV = (sense_voltage_dmV *625)/ 1000; // The fluctuations are between 33281 and 33268. This is a total fluctiation of 1.3mV (when you divide dmV by 10 to get mV).

In the second line where the float cast and divide by 10.0f occurs: 

 ch3_voltage_average_mV[1] = ((float)ch3_voltage_average_dmV)/10.0f; // The fluctuation is now between 3311 and 3344. This is a total fluctuation of 33 mV. 

The relevant code section is circled in red:

I went through the errata for : TMS320F28002x Real-Time MCUs Silicon Errata Silicon Revisions A, 0 

I discovered a section titled:  FPU-to-CPU Register Move Operation Preceded by Any FPU 2p Operation on pg 14. 

Is it possible that this bug is somehow the cause of my issues? I am using the most recent compiler V22.6.1 so I am not sure how this can be possible?

Many thanks in advance for your support with this.

Dissassembly for this section can also be found below:

  • Please help me understand this a bit better. Are you saying that even if you provide a constant input to your formulae, the outputs fluctuate? If my understanding is correct, please let me know which variables you are holding "constant".

    And please clarify what the input values are, what the output values, and what the expected values are.

  • Hi Sira,

    The fluctions for some reason only occur when I take the real input value. When I hold them constant they stop fluctuating which is a very perplexing phenomena. 

    They seem to occur only when I cast to float and it doesn't matter whether there is a further mathematical operation or not. This is a large piece of code where I have used floats in many locations but for some reason I only have an issue here with this calculation and this specific value - again very perplexing. 

    To better demonstrate the issue I have created a switch where I can manually modify the input value to test how it behaves with a fixed value versus the adc read value but the behaviour dissapears with a fixed value. 

    The demonstration code is as follows:

    if (test_switch == 0)
    {
    sense_voltage_dmV = 10*((uint32_t)(8192 + ch3_voltage_raw[1]-ch2_voltage_raw[1])); //sense_voltage_dmV is the adc resulting value and all these variables are uint32_t;
    ch3_voltage_average_dmV = (sense_voltage_dmV *625)/ 1000; //no issue here yet
    ch3_voltage_average_dmV_cast_to_float = (float)ch3_voltage_average_dmV; //issue occurs!
    }
    else
    {
    //if test_switch == 1 here we can manually set sense_voltage_dmV to the problematic value but the fluctuations dissapear.
    ch3_voltage_average_dmV = (sense_voltage_dmV *625)/ 1000;
    ch3_voltage_average_dmV_cast_to_float = (float)ch3_voltage_average_dmV;

    }

    When sense_voltage_dmV gets to be between 53240 and 53250 (these are real adc readings which are fluctuating slightly which as expected) the issue starts to occur on the float cast.

    With test_switch set to zero I get the following graph data - note how ch3_voltage_average_dmV_cast_to_float does not fluctuate when sense_voltage_dmV is slightly lowered at the beginning of the test (on the x-axis before sample 65):

    In the above (after sample 65 on the x-axis)you can see the large jumps in ch3_voltage_average_dmV_cast_to_float which do not occur before sense_voltage_dmV is increased.

    I then tried the same test with a fixed value for sense_voltage_dmV by setting test_switch  to 1 (at around sample 85 in the x-axis). sense_voltage_dmV  was then initially manually set to the problematic value of 53250, then 53240, then again to 53250 but if you look at the ch3_voltage_average_dmV_cast_to_float  it shows the correct value and the fluctuations have gone. I tried changing the value by hand a few times but this phenomenon has dissapeared. 

    Let me know if this helps with your understanding - thanks again for your help with this.