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.

TMS320F28379D: Structure of variable

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

I have a long struct as below

#ifndef __DAB_DATAINTERFACE_H
#define __DAB_DATAINTERFACE_H
#include "dab_settings.h"
#include "dab_varsExtern.h"
#include "dab_user_macro.h"
#include "dab_debug.h"

typedef enum  {
    DIAGNOSTIC = 0,
    DIAGNOSTIC_2_BROWN_OUT,
    BROWN_OUT,
    BROWN_OUT_2_BROWN_IN,
    BROWN_IN,
    BROWN_IN_2_PRE_CHARGE,
    PRE_CHARGE,
    PRE_CHARGE_2_DAB_OFF,
    DAB_OFF,
    DAB_OFF_2_DAB_RAMP,
    DAB_RAMP,
    DAB_RAMP_2_DAB_OFF,
    DAB_ON,
    DAB_ON_2_DAB_OFF,
    DAB_FAULT
} DABSTATEMACHINE;

typedef enum  {
    RELAY_OPEN = 0,
    RELAY_CLOSE
} RELAYCONTROL;

typedef enum  {
    POWER_OFF = 0,
    POWER_ON
} CONVERTERCONTROL;

struct DATAINTERFACE
{
    struct CAN
    {
        struct LINUXREQUEST
        {
            struct LINUXOUTPUT
            {
                float32_t Vout_Volt;
                float32_t Iout_Amp;
                CONVERTERCONTROL PowerOnOff;
            } output;
            union LINUXRELAY
            {
                uint32_t all;
                struct LINUXRELAYCONTROLBITS {
                    uint32_t inputRelayPosNegOpenClose     : 1;
                    uint32_t outputRelayPosOnOpenClose     : 1;
                    uint32_t outputRelayNegOnOpenClose     : 1;
                    uint32_t revd                          : 29;
                } bits;
            } relay;
        } Linuxrequest;

        struct DABRESPOND
        {
            float32_t vSec_Volt;
            float32_t iSec_Amp;
            float32_t vPrim_Volt;
            float32_t iPrim_Amp;

            float32_t temperature_DegreeC;
            union DABFAULTSTATUS
            {
                uint32_t all;
                struct BITS
                {
                    uint32_t inputOVP               : 1;            //1 bit
                    uint32_t inputOCP               : 1;            //2
                    uint32_t outputOVP              : 1;            //3
                    uint32_t outputOCP              : 1;            //4
                    uint32_t outputSCP              : 1;            //5
                    uint32_t relay10Error           : 1;            //6
                    uint32_t relay11Error           : 1;            //7
                    uint32_t relay12Error           : 1;            //8
                    uint32_t ramError               : 1;            //9
                    uint32_t flashError             : 1;            //10
                    uint32_t adcError               : 1;            //11
                    uint32_t canBusHeatbeatLoss     : 1;            //12
                    uint32_t interruptError         : 1;            //13
                    uint32_t pcError                : 1;            //14
                    uint32_t timerError             : 1;            //15
                    uint32_t addressError           : 1;            //16
                    uint32_t revd                   : 14;           //17-30
                    uint32_t requestedVoltInvalid   : 1;            //31
                    uint32_t brownOut               : 1;            //32 bit
                } bits;
            } dab_faultStatus;
            DABSTATEMACHINE dabState;
        } Dabrespond;
    } can;
    struct INTERNALINTERFACE
    {
        struct CONVERTER
        {
            float32_t DAB_vSecRef_Volt;
            float32_t DAB_iSecRef_Amp;

            CONVERTERCONTROL PowerOnOff;
        } converter;
        uint32_t stateMachineTransit_Counter;
        struct AVG
        {
            float32_t vSecSensed_Volt;
            float32_t iSecSensed_Amp;
            float32_t vPrimSensed_Volt;
            float32_t iPrimSensed_Amp;
        }avg;
        union DABRELAYCONTROL
        {
            uint32_t all;
            struct DABRELAYCONTROLBITS
            {
                uint32_t inputRelayPosNegOpenClose     : 1;
                uint32_t outputRelayPosOnOpenClose     : 1;
                uint32_t outputRelayNegOnOpenClose     : 1;
                uint32_t revd                          : 29;
            } bits;
        }relay;
        union INTERNALFAULTSTATUS
        {
            uint32_t all;
            struct INTERNALFAULTSTATUSBITS
            {
                uint32_t inputOVP               : 1;            //1 bit
                uint32_t inputOCP               : 1;            //2
                uint32_t outputOVP              : 1;            //3
                uint32_t outputOCP              : 1;            //4
                uint32_t outputSCP              : 1;            //5
                uint32_t relay10Error           : 1;            //6
                uint32_t relay11Error           : 1;            //7
                uint32_t relay12Error           : 1;            //8
                uint32_t ramError               : 1;            //9
                uint32_t flashError             : 1;            //10
                uint32_t adcError               : 1;            //11
                uint32_t canBusHeatbeatLoss     : 1;            //12
                uint32_t interruptError         : 1;            //13
                uint32_t pcError                : 1;            //14
                uint32_t timerError             : 1;            //15
                uint32_t addressError           : 1;            //16
                uint32_t revd                   : 14;           //17-30
                uint32_t requestedVoltInvalid   : 1;
                uint32_t brownOut               : 1;            //32 bit
            } bits;
        } dab_faultStatus;
        struct REFERDATA
        {
            float32_t iSec_Amp;
            float32_t vSec_Volt;
        }outputRef;
        DABSTATEMACHINE dabState;
    } InternalInterface;
    struct debugVars
    {
        float32_t floating[10];
        uint32_t  unsignedInt[10];
#ifdef DEDUG_SIMULATION
        struct PU
        {
            float32_t vSec;
            float32_t iSec;
            float32_t vPrim;
            float32_t iPrim;
            float32_t vSec_limit;
            float32_t iSec_limit;
        }pu;
#endif
    } debugVars;
};
extern volatile struct DATAINTERFACE g_data;
#endif

I define object using "volatile struct DATAINTERFACE g.data" in main loop. I got a unexpected result in code.

1. In "if statement" below. program flow can enter Code area. g_data.data.InternalInterface.converter.DAB.vSecRef_Volt = 0.0 (In debeg expression veiw) and the value DAB_MINSEC_VOLTAGE = 300.0f. It does not make send to me.

                if ((g_data.InternalInterface.converter.DAB_vSecRef_Volt > DAB_MINSEC_VOLTAGE))
                {

                    Code area.

2. In floating point calculation, the result will be very very small sometime ( < 0.00000000000xxxx). Below is the code of calculation where g_data.debugVars.pu.iPrim = 0.5, DAB_IPRIM_MAX_SENSE = 30.0f.

    g_data.InternalInterface.avg.iPrimSensed_Amp = (float32_t)(g_data.debugVars.pu.iPrim * DAB_IPRIM_MAX_SENSE);

  

 I am using opt_level = 0. To me the problem should not due to optimization. I am not sure my structure is correct or not? Please advise.

  • For the first query I would recommend looking at the disassembly window and check what is happening at the assembly instruction level. For the second query do you mean to say that iPrimSensed_Amp is 0.000000xxx instead of 15.0f?

    Best regards, Pawan

  • 1. I am not familiar in Assembly. I do know how to debug it in assemble

    2. No, iPrimSensed_Amp is result of g_data.debugVars.pu.iPrim * DAB_IPRIM_MAX_SENSE) where g_data.debugVars.pu.iPrim is 0.5f and DAB_IPRIM_MAX_SENSE defined as 1230.0f. In theory, iPrimSensed should be 615.0. Howerver, it is because 0.xxE-XX.

    I am located in Asia. Is it possible to have on-line call, so that TI can tell me how to debug it.

  • The below reference will show how to debug in assembly.

    7.1. Debug Overview — Code Composer Studio 10.1.0 Documentation

    Meaning of assembly instructions can be found in https://www.ti.com/lit/ug/spru430f/spru430f.pdf

    You can try doing assembly stepping and check which variable address location is being accessed and whether proper values are getting used.

  • I still cannot figure out the root cause. I am thinking about possibly due to cmd file. Please find attached file for your referencef2837xd_flash_cpu1_lnk.zip

  • Please check with the latest command file in C2kware. If there are any changes, try the latest one.

    Did you try the assembly step I suggested.

    Best regards, Pawan

  • 1. What do you mean latest command file in C2Kware?

    2. I tried, but no idea what is going on

  • Check the command file 2837xD_FLASH_lnk_cpu1 in C2000Ware_5_02_00_00\device_support\f2837xd\common\cmd

    For the assembly debug please refer to the assembly user guide and check the CPU registers to understand what is happening and if it is as expected.

  • Actually, I did some experiment. I modified the code to use single variable float32_t instead of structure in if statement. it is found that the same problem is happened.

    I don't see this problem before for F280025C/F280049C. It is first time I see this problem in F28379D.

  • Which memory is the variable placed in? Is it initialized?

  • I found other problem

    I declared a local variable for debug

        float32_t DAB_vSecSensedAvgOVP_ThersholdVolt = 460.0f;
        float32_t DAB_iSecSensedAvgOCP_ThersholdAmp = 30.0f;

                if (!(obj->dabFault.all & 0xFFFFFFFF))
                {
                    if (output_avgVolt > DAB_vSecSensedAvgOVP_ThersholdVolt)
                    {
                        obj->dabFault.bits.outputOVP = TRUE;
                    } else if (output_avgAmp> DAB_iSecSensedAvgOCP_ThersholdAmp)       

    Value of variable of the variable become 0.0, in my code there is no place to change it

  • Please find screenshot for my debug code below

    #pragma FUNCTION_OPTIONS(dac_outputProtectDiag, "--opt_level=off")
    void dac_outputProtectDiag(InternalVarsHandle handler)
    {
    #define OVP_THRESHOLDFACTOR 1.15f
    #define OCP_THRESHOLDFACTOR 1.15f
    #define RAMPFINISH_VOLT_HYSTERESIS 20.0f


        InvVars_t *obj = (InvVars_t *)handler;
        static float32_t DAB_vSecSensedPrevAvg_Volts = 0.0f;
        float32_t deltaVolts = 0.0f;
        float32_t DAB_vSecSensedAvgOVP_ThersholdVolt = 460.0f;
        float32_t DAB_iSecSensedAvgOCP_ThersholdAmp = 30.0f;
    //    DAB_iSecSensedAvgOCP_ThersholdAmp = (float32_t) * OCP_THRESHOLDFACTOR);
    //    DAB_vSecSensedAvgOVP_ThersholdVolt = (float32_t)(obj->setSecOutput.voltage * OVP_THRESHOLDFACTOR);
        if (0.4f > DAB_iSecSensedAvgOCP_ThersholdAmp )
        {
            DAB_iSecSensedAvgOCP_ThersholdAmp = 0.0f;
        }
        if (0.4f > DAB_vSecSensedAvgOVP_ThersholdVolt)
        {
            DAB_vSecSensedAvgOVP_ThersholdVolt = 0.0f;
        }



        switch (g_internalVars->dabState)
        {
            case DAB_OFF_2_DAB_RAMP:
                DAB_vSecSensedPrevAvg_Volts = 0;
            break;
            case DAB_RAMP:
    #define DELTA_VOLTS 5.0
                if (g_internalVars->avg.vSec_Volt < (g_internalVars->avg.vSec_Volt - RAMPFINISH_VOLT_HYSTERESIS))
                {
                    deltaVolts = g_internalVars->avg.vSec_Volt - DAB_vSecSensedPrevAvg_Volts;
                    g_internalVars->dabFault.bits.outputSCP = (deltaVolts < DELTA_VOLTS) ? TRUE: FALSE;
                    DAB_vSecSensedPrevAvg_Volts = g_internalVars->avg.vSec_Volt;
                }
            break;
            case DAB_ON:
                if (!(obj->dabFault.all & 0xFFFFFFFF))
                {
                    if (output_avgVolt > DAB_vSecSensedAvgOVP_ThersholdVolt)
                    {
                        obj->dabFault.bits.outputOVP = TRUE;
                    } else if (output_avgAmp> DAB_iSecSensedAvgOCP_ThersholdAmp)
                    {
                        obj->dabFault.bits.outputOCP = TRUE;
                    }
    //                g_data.InternalInterface.dab_faultStatus.bits.outputOVP = (g_data.InternalInterface.avg.vSecSensed_Volt > DAB_vSecSensedAvgOVP_ThersholdVolts) ? \
    //                        TRUE : FALSE;
    //                g_data.InternalInterface.dab_faultStatus.bits.outputOCP = (g_data.InternalInterface.avg.iSecSensed_Amp > DAB_iSecSensedAvgOCP_ThersholdAmp) ? \
    //                        TRUE : FALSE;
                }
            break;
        }

        //InOutPut_Protection_Task_Ptr = &dac_inputProtectDiag;
    }

    1. You can see that value of these 2 variable should not change to 0.

    2. It will change to 0 after sometime of execute the code. I don't understand.

  • I need to have TI support on this problem. It affects any our schedule on our product development.

    Thanks

  • Which 2 variables are you referring to getting changed to 0? I previously asked you where are the variables being placed in memory? Could you help with that.

  • 1. DAB_vSecSensedAvgOVP_ThersholdVolt and DAB_iSecSensedAvgOCP_ThersholdAmp become 0

    2. Above 2 variables are defined inside the function. It is local variable.  I don't know where section of memory is being used.

  • I really want to have a on-line call

  • I do other experiment with below code

        output_avgVolt = (float32_t)(0.3f * DAB_VSEC_MAX_SENSE);
        output_avgAmp  = (float32_t)(0.04f * DAB_ISEC_MAX_SENSE);
        input_avgVolt  = (float32_t)(0.6f * DAB_VPRIM_MAX_SENSE);
        input_avgAmp   = (float32_t)(0.01f * DAB_IPRIM_MAX_SENSE);
        if (input_avgVolt < 500.0f)
        {
            ESTOP0;
        }

    where  DAB_VPRIM_MAX_SENSEdefined as (float32_t)1323.0)

    The result is unbelievable. ESTOP is triggered and the value of input_avgVolt show 4.132xxxxe-41 (DEN) in  Why?

  • I use disassembly view. Please find attached

    ESTOP0 is trigger. I use a mouse point to variable input_avgVolt and value is 798.xxxx and DAB_INPUT_VOLTAGE_BROWN_OUT_LEVEL is 740.0.

    I am total lose

  • Hi

    I commended 3 line in link file which I provided before. My code is running ok now

    However, this link file is from TI digital power SDK TIDA_010054 and it is our reference design. I don't know what is side effect if the lines are removed.

    Please advise.

  • Hello Hung,

    I don't know what is side effect if the lines are removed.

    You can refer to the Memory Model - Sections chapter of the C28x Optimization User's guide for what the .scratchpad and .bss_cla are used for. The controlVariables section looks like it's its own unique section, so there may be something allocated to it in a #pragma statement somewhere in the application code(otherwise it's unused). If you uncomment these lines and view the Memory Allocations window after compiling your code you can see what gets placed in these sections and that will let you know what possible effect there is. I believe if these sections aren't present, the default related sections are used for memory.

  • Hi Omer

    Thanks for your information. I will take a look the document. However, I wish TI tplain that why these 3 lines removed and the problem is fixed. I am new to this MCU, All logic control is program flow is unexpected.I am afraid of a wrong link cmd file declaration.

    I used 25c/49c, I don't see this kind of problem.

    Is it possible to seek an advance from  owner who write a code for the application. It is because I don't see these 3 lines in TI C2000Ware example link cmd file

  • Hello Hung,

    I have not seen these sections used in any template linker command file provided in C2000Ware for this or any other device, therefore my thought is that this is either from an example not within the C2000Ware SDK or this is something custom to you application (whether it was developed by you or someone else). If this is from an existing example, please cite which SDK it's in and the path to get to it. Based on what I've read through this thread, you have not mentioned any name for this software example.

    I cannot say for certain what is causing this error, this will need to be further debugged by you as there is no similar issue that occurs with linker command files provided in C2000Ware as far as I've seen. Unless you can narrow down what memory is changed by these sections' removal or find out how the code you indicated above executes differently and find the exact root cause (i.e. some disassembly code which is compiled differently, etc.), there is not much more we can assist with.

  • I do more test today. My change doesn't help the problem

  • I have a question about the address of my object. Please attached screen shot. Address of variable under g_internalVars   is started from 0x000000@Data. Is it correct? I used DATA_SECTION to specification obj g_internalVars 

    #pragma DATA_SECTION(g_internalVars, "structVars")
    #pragma RETAIN (g_internalVars)

    volatile InternalVarsHandle   g_internalVars;

  • Hello Hung,

    I don't believe this is correct, the address 0x0 to 0x3FF on this device is for M0 RAM; M0/M1 RAM are RAMs with specialized uses, you should be using LS or GS RAM for something like storing a variable.

    1. Actually I specified structVas in RAMGs15
  • Hello Hung,

    Actually I specified structVas in RAMGs15

    Your Expressions window is showing that your pointers are pointing to M0 RAM. Your variable g_internalVars may be pointing to RAMGS15, but none of the fields within this struct are stored there.

  • How to make the sub element of g_internalVars do not use RAMMO/M1?

  • Hello Hung,

    To correct my previous statement, RAMM0 is okay to use here. I looked deeper into this and RAMM0 is typically used for global variables, switch statements, etc. while RAMM1 is used for the stack. Outside of this, they should not be used (i.e. program memory should not be used in RAMM0/1)

    Seeing as this shouldn't be a problem, what exactly is the issue you're still seeing? Your previous posts mentioned removing three lines of code fixed your issue, is there still a problem you're seeing?