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: TMS320F28379D

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE, TIDA-010054, TMS320F28377D

Hi TI,

I want to implement the close loop control for my system by using TMS320F28379D MCU.

I am using the example code(C2000Ware_DigitalPower_SDK 4.04.00.00/development kit/TIDA-010054-Dual Active Bridge Reference Design/Example Projects/F28004x/dab.h) that was in the resource explorer.

i have shared the code with you for your reference.

Please suggest any probable way to resolve this issue.

.

//#############################################################################
//
// FILE:   dab.c
//
// TITLE: This is the solution file.
//
//#############################################################################
// $TI Release: TIDA_010054 v1.00.02.00 $
// $Release Date: Thu Jun 29 23:37:54 CDT 2023 $
// $Copyright:
// Copyright (C) 2023 Texas Instruments Incorporated - http://www.ti.com/
//
// ALL RIGHTS RESERVED
// $
//#############################################################################

//*****************************************************************************
// the includes
//
//*****************************************************************************

#include "dab.h"

//
//--- System Related Globals ---
// Put the variables that are specific to control in the below section
// For example SFRA cannot run on CLA hence it must not be placed
// in the below section, the control verification using SFRA can only
// be carried out on the C28x
// Control Variables
//
#pragma SET_DATA_SECTION("controlVariables")

DAB_buildLevel_enum DAB_buildLevel;

DAB_tripFlag_enum DAB_tripFlag;

DAB_pwmSwState_enum DAB_pwmSwStateActive, DAB_pwmSwState;

DAB_powerFlowState_enum DAB_powerFlowStateActive, DAB_powerFlowState;


DAB_GI DAB_gi;
float32_t DAB_giOut;
float32_t DAB_giError;
float32_t DAB_giPartialComputedValue;


DAB_GV DAB_gv;
float32_t DAB_gvOut;
float32_t DAB_gvError;
float32_t DAB_gvPartialComputedValue;

//
// Flags for clearing trips and closing the loop
//
#pragma RETAIN (DAB_closeGiLoop)
int32_t DAB_closeGiLoop;
#pragma RETAIN (DAB_closeGvLoop)
int32_t DAB_closeGvLoop;
#pragma RETAIN (DAB_clearTrip)
int32_t DAB_clearTrip;

//
// The below variable can be used by the user to enter value through
// the watch window and hence must be volatile
//
#pragma RETAIN (DAB_pwmFrequencyRef_Hz)
float32_t DAB_pwmFrequencyRef_Hz;
#pragma RETAIN (DAB_pwmFrequency_Hz)
float32_t DAB_pwmFrequency_Hz;
#pragma RETAIN (DAB_pwmFrequencyPrev_Hz)
float32_t DAB_pwmFrequencyPrev_Hz;
#pragma RETAIN (DAB_pwmPeriodRef_pu)
float32_t DAB_pwmPeriodRef_pu;

float32_t DAB_pwmPeriod_pu;
float32_t DAB_pwmPeriodMin_pu;
float32_t DAB_pwmPeriodMax_pu;
float32_t DAB_pwmPeriodMax_ticks;
uint32_t DAB_pwmPeriod_ticks;

//
// 1- Primary Side
//
float32_t DAB_iPrimSensed_Amps;
float32_t DAB_iPrimSensed_pu;
float32_t DAB_iPrimSensedOffset_pu;
float32_t DAB_iPrimSensedCalIntercept_pu;
float32_t DAB_iPrimSensedCalXvariable_pu;
EMAVG DAB_iPrimSensedAvg_pu;

float32_t DAB_iPrimTankSensed_Amps;
float32_t DAB_iPrimTankSensed_pu;
float32_t DAB_iPrimTankSensedOffset_pu;
float32_t DAB_iPrimTankSensedCalIntercept_pu;
float32_t DAB_iPrimTankSensedCalXvariable_pu;
EMAVG DAB_iPrimTankSensedAvg_pu;

float32_t DAB_vPrimSensed_Volts;
float32_t DAB_vPrimSensed_pu;
float32_t DAB_vPrimSensedOffset_pu;
float32_t DAB_vPrimSensedCalXvariable_pu;
float32_t DAB_vPrimRef_Volts;

#pragma RETAIN (DAB_pwmDutyPrimRef_pu)
float32_t DAB_pwmDutyPrimRef_pu;
float32_t DAB_pwmDutyPrim_pu;
uint32_t DAB_pwmDutyAPrim_ticks;
uint32_t DAB_pwmDutyBPrim_ticks;

#pragma RETAIN (DAB_pwmDeadBandREDPrimRef_ns)
float32_t DAB_pwmDeadBandREDPrimRef_ns;
uint32_t DAB_pwmDeadBandREDPrim_ticks;

#pragma RETAIN (DAB_pwmDeadBandFEDPrimRef_ns)
float32_t DAB_pwmDeadBandFEDPrimRef_ns;
uint32_t DAB_pwmDeadBandFEDPrim_ticks;

#pragma RETAIN (DAB_pwmPhaseShiftPrimSecRef_pu)
float32_t DAB_pwmPhaseShiftPrimSecRef_pu;

#pragma RETAIN (DAB_pwmPhaseShiftPrimSec_pu)
float32_t DAB_pwmPhaseShiftPrimSec_pu;
float32_t DAB_pwmPhaseShiftPrimSec_ns;
#pragma RETAIN (DAB_pwmPhaseShiftPrimSec_ticks)
int32_t DAB_pwmPhaseShiftPrimSec_ticks;
#pragma RETAIN (DAB_pwmPhaseShiftPrimSec_HiResticks)
uint16_t DAB_pwmPhaseShiftPrimSec_HiResticks;
int16_t DAB_pwmPhaseShiftPrimSec_countDirection;

//
// 2-Secondary side (Battery)
//
float32_t DAB_iSecSensed_Amps;
float32_t DAB_iSecSensed_pu;
float32_t DAB_iSecSensedOffset_pu;
float32_t DAB_iSecSensedCalIntercept_pu;
float32_t DAB_iSecSensedCalXvariable_pu;
EMAVG DAB_iSecSensedAvg_pu;

#pragma RETAIN (DAB_iSecRef_Amps)
float32_t DAB_iSecRef_Amps;
float32_t DAB_iSecRef_pu;
float32_t DAB_iSecRefSlewed_pu;

float32_t DAB_vSecSensed_Volts;
float32_t DAB_vSecSensed_pu;
float32_t DAB_vSecSensedOffset_pu;
float32_t DAB_vSecSensedCalXvariable_pu;

float32_t DAB_vSecRef_Volts;
float32_t DAB_vSecRef_pu;
float32_t DAB_vSecRefSlewed_pu;

float32_t DAB_iSecTankSensed_Amps;
float32_t DAB_iSecTankSensed_pu;
float32_t DAB_iSecTankSensedOffset_pu;
float32_t DAB_iSecTankSensedCalIntercept_pu;
float32_t DAB_iSecTankSensedCalXvariable_pu;
EMAVG DAB_iSecTankSensedAvg_pu;

#pragma RETAIN (DAB_pwmDutySecRef_pu)
float32_t DAB_pwmDutySecRef_pu;
float32_t DAB_pwmDutySec_pu;
uint32_t DAB_pwmDutyASec_ticks;
uint32_t DAB_pwmDutyBSec_ticks;

#pragma RETAIN (DAB_pwmDeadBandREDSecRef_ns)
float32_t DAB_pwmDeadBandREDSecRef_ns;
uint32_t DAB_pwmDeadBandREDSec_ticks;

#pragma RETAIN (DAB_pwmDeadBandFEDSecRef_ns)
float32_t DAB_pwmDeadBandFEDSecRef_ns;
uint32_t DAB_pwmDeadBandFEDSec_ticks;

#pragma RETAIN (DAB_phaseSyncPrimToSecCountDirection)
uint16_t DAB_phaseSyncPrimToSecCountDirection;

#pragma SET_DATA_SECTION()

//
// datalogger
//
DLOG_4CH DAB_dLog1;
float32_t DAB_dBuff1[100];
float32_t DAB_dBuff2[100];
float32_t DAB_dBuff3[100];
float32_t DAB_dBuff4[100];
float32_t DAB_dVal1;
float32_t DAB_dVal2;
float32_t DAB_dVal3;
float32_t DAB_dVal4;
float32_t DAB_dlogTrigger;

//
//--- SFRA Related Variables ---
//
#if DAB_SFRA_TYPE != DAB_SFRA_DISABLED
float32_t plantMagVect[SFRA_FREQ_LENGTH];
float32_t plantPhaseVect[SFRA_FREQ_LENGTH];
float32_t olMagVect[SFRA_FREQ_LENGTH];
float32_t olPhaseVect[SFRA_FREQ_LENGTH];
float32_t freqVect[SFRA_FREQ_LENGTH];
#endif

SFRA_F32 sfra1;

//
//TODO setupSFRA
//
#if DAB_SFRA_TYPE != DAB_SFRA_DISABLED
void DAB_setupSFRA(void)
{
    SFRA_F32_reset(&sfra1);
    SFRA_F32_config(&sfra1,
                    SFRA_ISR_FREQ,
                    SFRA_AMPLITUDE,
                    SFRA_FREQ_LENGTH,
                    SFRA_FREQ_START,
                    SFRA_FREQ_STEP_MULTIPLY,
                    plantMagVect,
                    plantPhaseVect,
                    olMagVect,
                    olPhaseVect,
                    NULL,
                    NULL,
                    freqVect,
                    1);

    SFRA_F32_resetFreqRespArray(&sfra1);

    SFRA_F32_initFreqArrayWithLogSteps(&sfra1,
                                        SFRA_FREQ_START,
                                        SFRA_FREQ_STEP_MULTIPLY);

    //
    //configures the SCI channel for communication with SFRA host GUI
    //to change SCI channel change #defines in the settings.h file
    //the GUI also changes a LED status, this can also be changed with #define
    //in the file pointed to above
    //
    SFRA_GUI_config(DAB_SFRA_GUI_SCI_BASE,
                   DAB_SCI_VBUS_CLK,
                   DAB_SFRA_GUI_SCI_BAUDRATE,
                   DAB_SFRA_GUI_SCIRX_GPIO,
                   DAB_SFRA_GUI_SCIRX_GPIO_PIN_CONFIG,
                   DAB_SFRA_GUI_SCITX_GPIO,
                   DAB_SFRA_GUI_SCITX_GPIO_PIN_CONFIG,
                   DAB_SFRA_GUI_LED_INDICATOR,
                   DAB_SFRA_GUI_LED_GPIO,
                   DAB_SFRA_GUI_LED_GPIO_PIN_CONFIG,
                   &sfra1,
                   1);
}
#endif


void DAB_initGlobalVariables(void)
{
    #if DAB_LAB == 5
        DAB_powerFlowStateActive.powerFlowState = powerFlow_BatteryDischarging;
        DAB_powerFlowState.powerFlowState = powerFlow_BatteryDischarging;
    #else
        DAB_powerFlowStateActive.powerFlowState = powerFlow_BatteryCharging;
        DAB_powerFlowState.powerFlowState = powerFlow_BatteryCharging;
    #endif

//Compensator parameters for voltage loop

        DCL_resetDF22(&DAB_gv);
        DAB_gv.a1 = DAB_GV_2P2Z_A1;
        DAB_gv.a2 = DAB_GV_2P2Z_A2;
        DAB_gv.b0 = DAB_GV_2P2Z_B0;
        DAB_gv.b1 = DAB_GV_2P2Z_B1;
        DAB_gv.b2 = DAB_GV_2P2Z_B2;

//Compensator parameters for current loop
        DCL_resetPI(&DAB_gi);
        DAB_gi.Ki = DAB_GI_KI;
        DAB_gi.Kp = DAB_GI_KP;
        DAB_gi.Umax = DAB_GI_UMAX;
        DAB_gi.Umin = DAB_GI_UMIN;
        DAB_gi.Imax = DAB_GI_IMAX;
        DAB_gi.Imin = DAB_GI_IMIN;


    DLOG_4CH_reset(&DAB_dLog1);
    DLOG_4CH_config(&DAB_dLog1,
                    &DAB_dVal1, &DAB_dVal2, &DAB_dVal3, &DAB_dVal4,
                    DAB_dBuff1, DAB_dBuff2, DAB_dBuff3, DAB_dBuff4,
                    100, 0.5, 1);
    DAB_dlogTrigger = 0;
// Unused functions
    EMAVG_reset(&DAB_iSecSensedAvg_pu);
    EMAVG_config(&DAB_iSecSensedAvg_pu, 0.01);
    EMAVG_reset(&DAB_iPrimSensedAvg_pu);
    EMAVG_config(&DAB_iPrimSensedAvg_pu, 0.01);
    EMAVG_reset(&DAB_iPrimTankSensedAvg_pu);
    EMAVG_config(&DAB_iPrimTankSensedAvg_pu, 0.01);

    //
    // Gui Variables
    //
    DAB_iPrimSensed_Amps = 0.0f;
    DAB_vPrimSensed_Volts = 0.0f;
    DAB_iSecSensed_Amps = 0.0f;
    DAB_vSecSensed_Volts = 0.0f;

    DAB_vSecRef_Volts = DAB_VSEC_NOMINAL;
    DAB_vSecRef_pu = DAB_VSEC_NOMINAL / DAB_VSEC_OPTIMAL_RANGE;
    DAB_vSecRefSlewed_pu = 0.0f;

    DAB_iSecRef_Amps = DAB_ISEC_NOMINAL;

    DAB_pwmPeriod_pu = (DAB_MIN_PWM_SWITCHING_FREQUENCY_HZ /
                        DAB_NOMINAL_PWM_SWITCHING_FREQUENCY_HZ);
    DAB_pwmPeriodRef_pu = DAB_pwmPeriod_pu;
    DAB_pwmPeriodMin_pu = (DAB_MIN_PWM_SWITCHING_FREQUENCY_HZ /
                           DAB_MAX_PWM_SWITCHING_FREQUENCY_HZ);
    DAB_pwmPeriodMax_ticks = DAB_PWMSYSCLOCK_FREQ_HZ /
                             DAB_MIN_PWM_SWITCHING_FREQUENCY_HZ;
    DAB_pwmFrequencyRef_Hz = DAB_NOMINAL_PWM_SWITCHING_FREQUENCY_HZ;
    DAB_pwmFrequency_Hz = DAB_NOMINAL_PWM_SWITCHING_FREQUENCY_HZ;
    DAB_pwmFrequencyPrev_Hz = DAB_pwmFrequency_Hz - 1.0f;
    DAB_pwmPhaseShiftPrimSec_pu = 0.032f;
    DAB_pwmPhaseShiftPrimSecRef_pu = 0.032f;
    DAB_pwmPhaseShiftPrimSec_ns = 0.0f;
    DAB_pwmDeadBandREDPrimRef_ns = DAB_PRIM_PWM_DEADBAND_RED_NS;
    DAB_pwmDeadBandFEDPrimRef_ns = DAB_PRIM_PWM_DEADBAND_FED_NS;

    DAB_pwmDeadBandREDSecRef_ns=DAB_SEC_PWM_DEADBAND_RED_NS;
    DAB_pwmDeadBandFEDSecRef_ns=DAB_SEC_PWM_DEADBAND_FED_NS;
    DAB_iPrimSensed_pu = 0.0f;
    DAB_iPrimTankSensed_pu = 0.0f;
    DAB_iPrimSensedOffset_pu = 0.5f;
    DAB_iPrimTankSensedOffset_pu = 0.5f;
    DAB_vPrimSensed_pu = 0.0f;
    DAB_vPrimSensedOffset_pu = 0.0f;
    DAB_iSecSensed_pu = 0.0f;
    DAB_iSecSensedOffset_pu = 0.5f;
    DAB_vSecSensed_pu = 0.0f;
    DAB_vSecSensedOffset_pu = 0.0f;
    DAB_vPrimSensedCalXvariable_pu = 1.024f;
    DAB_vSecSensedCalXvariable_pu = 1.01f;

    if(DAB_powerFlowState.powerFlowState == powerFlow_BatteryCharging)
    {
        DAB_pwmDutyPrim_pu = 0.5f;
        DAB_pwmDutyPrimRef_pu = 0.5f;
        DAB_pwmDutySec_pu = 0.5f;
        DAB_pwmDutySecRef_pu = 0.5f;
    }
    else if(DAB_powerFlowState.powerFlowState == powerFlow_BatteryDischarging)
    {
        DAB_pwmDutyPrim_pu = 0.5f;
        DAB_pwmDutyPrimRef_pu = 0.5f;
        DAB_pwmDutySec_pu = 0.5f;
        DAB_pwmDutySecRef_pu = 0.5f;
    }

    DAB_iSecSensedCalIntercept_pu = 0.0f;
    DAB_iSecSensedCalXvariable_pu = 1.0f;
    DAB_iPrimSensedCalIntercept_pu = 0.0f;
    DAB_iPrimSensedCalXvariable_pu = 1.0f;

    DAB_iPrimTankSensedCalIntercept_pu = 0.0f;
    DAB_iPrimTankSensedCalXvariable_pu = 1.0f;

    DAB_pwmSwState.pwmSwState = pwmSwState_singlePhaseShiftControl;
    DAB_pwmSwStateActive.pwmSwState = pwmSwState_singlePhaseShiftControl;

    DAB_tripFlag.tripFlag = noTrip;

    DAB_vPrimRef_Volts = 400.0f;

    DAB_closeGiLoop = 0;
    DAB_closeGvLoop = 0;
    DAB_clearTrip = 0;

}

//
//TODO updateBoardStatus()

void DAB_updateBoardStatus(void)
{
    int16_t tripStatusRead;
    tripStatusRead = DAB_HAL_readTripFlags();

 if(DAB_tripFlag.tripFlag == noTrip)
 {
        if(tripStatusRead == (int16_t) primOverCurrentTrip)
        {
            DAB_tripFlag.tripFlag = primOverCurrentTrip;
        }
        else if(tripStatusRead == (int16_t) secOverCurrentTrip)
        {
            DAB_tripFlag.tripFlag = secOverCurrentTrip;
        }
        else if(tripStatusRead == (int16_t) primTankOverCurrentTrip)
        {
            DAB_tripFlag.tripFlag = primTankOverCurrentTrip;
        }
        else if(tripStatusRead == (int16_t) secOverVoltageTrip)
                {
                    DAB_tripFlag.tripFlag = secOverVoltageTrip;
                }
        else
               {
                   DAB_tripFlag.tripFlag = noTrip;
               }
 }
}


void DAB_runSFRABackGroundTasks(void)
{
    //
    //    new_injection_amplitude=sfra1.freqVect[sfra1.freqIndex]
    //    SFRA_F32_updateInjectionAmplitude(&sfra1,new_injection_amplitude);
    //
    SFRA_F32_runBackgroundTask(&sfra1);
    SFRA_GUI_runSerialHostComms(&sfra1);
}



void DAB_setBuildLevelIndicatorVariable(void)
{
    #if DAB_INCR_BUILD == 1
        #if DAB_SEC_CONNECTED_IN_BATTERY_EMULATION_MODE == 0
            #if DAB_CONTROL_RUNNING_ON == CLA_CORE
                DAB_buildLevel.buildLevel = openLoopCheck_CLA;
            #else
                DAB_buildLevel.buildLevel = openLoopCheck;
            #endif
        #else
                DAB_buildLevel.buildLevel = undefinedState;
        #endif
    #elif DAB_INCR_BUILD == 2
        #if DAB_SFRA_TYPE == DAB_SFRA_VOLTAGE
            #if DAB_SEC_CONNECTED_IN_BATTERY_EMULATION_MODE == 0
                #if DAB_CONTROL_RUNNING_ON == CLA_CORE
                    DAB_buildLevel.buildLevel = closedLoopCheck_Voltage_CLA;
                #else
                    DAB_buildLevel.buildLevel = closedLoopCheck_Voltage;
                #endif
            #else
                DAB_buildLevel.buildLevel = undefinedState;
            #endif
        #elif DAB_SFRA_TYPE == DAB_SFRA_CURRENT
            #if DAB_SEC_CONNECTED_IN_BATTERY_EMULATION_MODE == 0
                #if DAB_CONTROL_RUNNING_ON == CLA_CORE
                    DAB_buildLevel.buildLevel = closedLoopCheck_Current_CLA;
                #else
                    DAB_buildLevel.buildLevel = closedLoopCheck_Current;
                #endif
            #else
                #if DAB_CONTROL_RUNNING_ON == CLA_CORE
                    DAB_buildLevel.buildLevel =
                            closedLoopCheck_Current_BatteryMode_CLA;
                #else
                    DAB_buildLevel.buildLevel =
                            closedLoopCheck_Current_BatteryMode_CLA;
                #endif
            #endif
        #endif
    #endif
}

//
// No more.
//

  • Hi SMPL,

    I did not get your query, do you want to know how to port to F28379D from F28004x which is used in the example?

    Do you plan to support other features/power converters along with this design in your implementation using the same MCU? For only supporting TIDA-010054 design the F28004x is sufficient.

    Thanks and regards, Pawan

  • Thank you for your replying.

    Yes, I want to port that code to F28379D from F28004x.

    I have port that code in F28379D but getting error while fetching the code in F28379D.

    I am trying to implement this code for close loop control of DAB DC-DC Converter using F28379D.

    Thanks and Regards,

    Nirakar Nayak

  • I have shared the error screen-shot while implementing the code in F28379D.

  • Please import the DAB solution project from digital power SDK and start the porting efforts from that project. You need to change the support driverlibs from F28004x to F28379D. It should be easier to port from that project.

    Thanks and regards, Pawan

  • can let me know from where i can get  "inc/hw_types.h" file

  • You can find it in \C2000Ware_5_00_00_00\driverlib\f2837xd\driverlib\inc. Recommend starting from empty driverlib project if you do not want to start from the DAB solution project. Empty project is available in \C2000Ware_5_00_00_00\driverlib\f2837xd\examples\cpu1. Note that you are currently using bitfield based project to start with but the TIDA-010054 is based on driverlibs. Using the driverlib empty example will have most required files already mapped.

    Thanks and regards, Pawan

  • I am geeting this error while importing the empty project.

  • You are importing the project using the projectspec file empty_driverlib_project.projectspec. Please check if the TMS320F28377D.ccxml file is located at the directory path mentioned in the project spec file. ../ means jump one folder level backwards wrt to location of project spec file.

        <file action="copy" path="../../../../../../device_support/f2837xd/common/targetConfigs/TMS320F28377D.ccxml" targetDirectory="targetConfigs" />

    Thanks and regards, Pawan