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.

TMS320F28069: float variables are overwritten automatically

Part Number: TMS320F28069

Hello everyone,

I am using C2000 microcontroller in my application of power electronics. Recently, I have started facing a problem where some of the float variables sets to infinity. Due to this the whole system looses the control and everntually shuts down.

I am sure about one thing that there is no problem in hardware, since the previous version of the code runs perfectly well in the same hardware setup. There is somewhere a problem into the program which makes the variable value infinity. This problem is only seen in float variables. 

Earlier I didn't took this problem so seriously but now its becoming grave one.

I am urgently looking forward for a recommendation or any kind of suggestions. 

Thank you!

  • Hi,

    You can setup an interrupt to trigger when the LVF (Latched over flow) is set. LUF is set whenever the result of a float calculation is +Inf. In you ISR you can put in a __asm(" ESTOP0"), a software breakpoint, so that you can then inspect the call stack and see in which function the interrupt occured; you will also get the approximate address at which the overflow occured. You can then reset and set a HW breakpoint a couple lines prior to that point, single step until the LUF is set - that will tell you where the overflow occured.
  • The trouble with infinite values is that once one variable get set to + or -inf, any other variable derived from it also gets set to +inf.

    Usually this is happens when you have a division by zero. Bind all division operations the following way:

    float a, b, c

    #include "float.h"

    if (fabs(b) < FLT_MIN) )

    {

    if ((fabs(c) > FLT_MIN)

    {

    c = MAX_VALUE_FOR_YOUR_SYSTEM; // or FLT_MAX

    }

    else

    {

    c = 0;

    }

    }

    else

    {

    c = a/b;

    }

  • Hi Vishal!

    Hi Mitja;

    Thank you for your suggestion. Since I am not an expert and I have a limited understanding about the subject, it will take some time for me to implement your idea. But I will surely get back to you in next week.

    Regards,
    Karan

  • Hello Mitja,

    Please excuse me for my late response.
    Finally, I was trying to implement the code you had suggeted. But I have a question regarding that. Could you please explain me why in the first condition you have taked float variable b??
  • Hello Mitja,

    Thanks for the code. I tried to execute this code similar to yours for a specific variables, which would try to bind a variable within a specific limits. Therefore, if variable exceeds min or max range, then the value of that variable will be equal to that of min and max range respectively.

    But the problem is, in my control loop there are so many variables which are involved in division operation and it is not possile for me to keep the same min and max range. So if I execute the same code for all the variable again and again, then the code size will be very long and code won't be so efficient.

    Could you suggest me an idea where I can bind all the variables, for ex 50 float variables, in one loop?

    Thanks in advance

    Karan
  • Firstly, there is a typo in my code. Second if should be if ((fabs(a) > FLT_MIN).

    Now to your question:

    Could you please explain me why in the first condition you have taked float variable b??


    b is divisor. And if the divisor is zero obviously the result should be either maximum value that your system supports unless the dividend is also zero.

    But the problem is, in my control loop there are so many variables which are involved in division operation and it is not possile for me to keep the same min and max range. So if I execute the same code for all the variable again and again, then the code size will be very long and code won't be so efficient.

    Could you suggest me an idea where I can bind all the variables, for ex 50 float variables, in one loop?


    You need only as many checks as there are the division operations. If the divisor is complex expression, you only need to check the expression an not the individual parts of the expression.

    You could also get away with something like this:

    if (0 < (b) < FLT_MIN) b = FLT_MIN

    if (0 > (b) > -FLT_MIN) b = -FLT_MIN

    which you can write with ternary operator and the compiler might optimize.

    Also, do you really need to worry about performance in advance?