LAUNCHXL-F28379D: PSIM C CODE FOR THE CCS 20.0.1

Part Number: LAUNCHXL-F28379D
Other Parts Discussed in Thread: TMS320F28379D

Tool/software:

How can i  import a PSIM C Code generated project under the  CCS  20.0.1 Code Composer Studio  used to flash,download and debug  on the Dev board LAUNCHXL-F28379D ?

Thanks for you help.

Aldo

  • Hi Aldo,

    Is the PSIM code publicly available? Can you link to it if so?

    If you have C code but it isn't yet in a C2000/CCS project structure, what you can do is import an empty project (something like an LED blinky project) from our TI Resource explorer and attach the generated C code into your project. TIREX should be available through the file menu in the CCS v20 application and you can point directly to the specific microcontroller device you are using (TMS320F28379D). The example project will all of the necessary linker command files and target connection config files to connect to the LaunchPad. You can use the FLASH build of the project to enable flashing to your device

    Regards,

    Peter

  • HI Peter,

    Thank you for your advice.

    I copied below  the ( esoteric )PSIM generated code, it is basically the configuration of  standard and phase shifted  Pwm modules and ADC .The algorithm code is still to be developped. I guess the include files  have to be imported under the CCS project in some way but I have no knowledge on this.

    I finally installed the previous CCS version 8.3.1 which recognizes the PSIM Simcoder generated project and succeeded to import it. and could flash and run the code .

    Best Regards

    Aldo

    /*********************************************************************************
    // This code is created by SimCoder Version 2024b12.251 for F2837x Hardware Target
    //
    // SimCoder is copyright by Powersim Inc., 2009-2021
    //
    // Date: February 20, 2025 09:08:47
    **********************************************************************************/
    #include <math.h>
    #include "PS_bios.h"
    #define GetCurTime() PS_GetSysTimer()
    #define iif(a, b, c) ((a) ? (b) : (c))
    #define PWM_IN_CHECK // To lower PWM value setting time, comment out this line if PWM duty cycle values are strictly limited in the range.


    interrupt void Task();

    #ifdef _FLASH
    #pragma DATA_SECTION(PSK_SysClk, "copysections")
    #endif
    const Uint16 PSK_SysClk = 200; // MHz
    extern DefaultType fGblV1;
    extern DefaultType fGblDutyCycle;
    extern DefaultType fGblPhaseShift;
    extern DefaultType fGblcarrierfreq;
    extern DefaultType fGblvarint;
    extern DefaultType fGblvarint2;
    extern DefaultType fGblCarrierSource;
    extern DefaultType fGblVsadc;
    extern DefaultType fGbladc1;
    extern DefaultType fGbladc2;
    extern DefaultType fGblVeadc;
    extern DefaultType fGbladc2b;
    extern DefaultType fGbladc1b;

    #define PSM_VRefHiA 3.3 // ADC-A VREFHIA
    #define PSM_VRefLowA 0 // ADC-A VREFLOA
    #define PSM_VRefHiB 3.3 // ADC-B VREFHIB
    #define PSM_VRefLowB 0 // ADC-B VREFLOB
    #define PSM_VRefHiC 3.3 // ADC-C VREFHIC
    #define PSM_VRefLowC 0 // ADC-C VREFLOC
    #define PSM_VRefHiD 3.3 // ADC-D VREFHID
    #define PSM_VRefLowD 0 // ADC-D VREFLOD

    // Parameter list for main subcircuit
    #define DAB_ControlLaw_carrierfreq 0.5
    // Parameters in parameter file _ParamFile1
    #define switchfreq 10000.0
    DefaultType carrierfreq = 0.5;
    #define sourcefreq 0.5
    #define Fsw 10000.0
    #define RTHTIM 0.22058824
    #define Td (1e-6)
    #define Th 80.0
    #define N 1.0
    #define mtr 1.9
    #define Np 1.0
    #define Ns 1.0
    #define BUS_DC_AVAL 950.0
    #define BUS_DC_AMONT 1200.0
    #define Ps 17750.0
    #define RLOAD 50.84507
    #define Iout 18.684211
    DefaultType fGblV1 = 0;
    DefaultType fGblDutyCycle = 0;
    DefaultType fGblPhaseShift = 0;
    DefaultType fGblcarrierfreq = 0;
    DefaultType fGblvarint = 0;
    DefaultType fGblvarint2 = 0;
    DefaultType fGblCarrierSource = 0;
    DefaultType fGblVsadc = 0;
    DefaultType fGbladc1 = 0;
    DefaultType fGbladc2 = 0;
    DefaultType fGblVeadc = 0;
    DefaultType fGbladc2b = 0;
    DefaultType fGbladc1b = 0;
    interrupt void Task()
    {
    DefaultType fDAB_ControlLaw_4, fDAB_ControlLaw_3, fDAB_ControlLaw_2, fDAB_ControlLaw_1;
    DefaultType fDAB_ControlLaw, fZOH4, fP2, fF2837x_ADC2_2, fZOH1, fP1, fADCA_2;
    DefaultType fV2;

    ADC_CLR(0) = 1<<(1-1);
    CPU_PIEACK |= M__INT1;

    {
    static DefaultType wt = 3.14159265 * (0 / 180.);
    static DefaultType dwt = (3.14159265 * 2 * sourcefreq / 10000);
    fV2 = sin(wt);
    wt += dwt;
    if (wt >= 2 * 3.14159265) wt -= 2 * 3.14159265;
    fV2 *= 0.45;
    fV2 += 0.5;
    }
    #ifdef _DEBUG
    fGblV1 = fV2;
    #endif

    fADCA_2 = ADC_RESULT(0, 0) * (1.0 * (PSM_VRefHiA - PSM_VRefLowA) / 4096.0);
    fP1 = fADCA_2;
    fZOH1 = fP1;
    fF2837x_ADC2_2 = ADC_RESULT(1, 0) * (1.0 * (PSM_VRefHiB - PSM_VRefLowB) / 4096.0);
    fP2 = fF2837x_ADC2_2;
    fZOH4 = fP2;
    {
    //ENTER YOUR CODE HERE
    // fDAB_ControlLaw = 2 * sin(fV2);
    //start of control law variables declarations
    float var1=0;
    float svm=0;
    float var2=0;
    float var3=0;
    float var4=0;
    float varint=0;
    float varint2=0;
    //end of control law variables declarations
    var1=fV2;
    var2=fZOH1;
    var3=fZOH4;
    varint=var2/2;
    varint2=var3/2;
    //this implements Dual Active Bridge Control,Phase shift is used to transfer energy from the primary side to the secondary side
    // start of control law
    svm=DAB_ControlLaw_carrierfreq;
    //end of control law
    fDAB_ControlLaw=0.5;
    fDAB_ControlLaw_1=180;
    //fDAB_ControlLaw_2=DAB_ControlLaw_carrierfreq;
    fDAB_ControlLaw_2=svm;
    fDAB_ControlLaw_3=varint;
    fDAB_ControlLaw_4=varint2;
    }
    #ifdef _DEBUG
    fGblDutyCycle = fDAB_ControlLaw;
    #endif

    #ifdef _DEBUG
    fGblPhaseShift = fDAB_ControlLaw_1;
    #endif

    #ifdef _DEBUG
    fGblcarrierfreq = fDAB_ControlLaw_2;
    #endif

    #ifdef _DEBUG
    fGblvarint = fDAB_ControlLaw_3;
    #endif

    #ifdef _DEBUG
    fGblvarint2 = fDAB_ControlLaw_4;
    #endif

    #ifdef _DEBUG
    fGblCarrierSource = fV2;
    #endif
    #ifdef _DEBUG
    fGblVsadc = fZOH1;
    #endif
    #ifdef _DEBUG
    fGbladc1 = fADCA_2;
    #endif
    #ifdef _DEBUG
    fGbladc2 = fP1;
    #endif
    #ifdef _DEBUG
    fGblVeadc = fZOH4;
    #endif
    #ifdef _DEBUG
    fGbladc2b = fP2;
    #endif
    #ifdef _DEBUG
    fGbladc1b = fF2837x_ADC2_2;
    #endif
    // Start of changing PWM2(phase shift) registers
    // Set Duty Cycle
    {
    static Uint16 oldTBPHS2Up = 0, oldTBPHS2Dn = 65535;
    Uint16 reg, _cmpA;
    DefaultType _val;
    _val = __fsat(fDAB_ControlLaw, 1 + 0, 0);
    _val = PWM_TBPRD(2) * ((1 + 0) - _val) * (1.0 / 1);
    _cmpA = (int)(_val);
    _val = __fracf32(__fracf32(fDAB_ControlLaw_1 * (1.0/360.0)) + 1.0);
    _val *= 2.0;
    if (_val < 1.0) {
    reg = (Uint16)(PWM_TBPRD(2) * _val);
    if ((_cmpA > oldTBPHS2Up) && (_cmpA <= reg)) {
    _cmpA = reg; // We add this to ensure PWM counting up action
    }
    PWM_TBPHS(2) = oldTBPHS2Up = reg;
    PWM_TBCTL(2) |= 1 << 13; // Up
    oldTBPHS2Dn = 0;
    } else {
    reg = (Uint16)(PWM_TBPRD(2) * (2.0 - _val));
    if ((oldTBPHS2Dn >= _cmpA) && (_cmpA > reg)) {
    _cmpA = oldTBPHS2Dn + 1; // We add this to ensure PWM counting down action
    }
    PWM_TBPHS(2) = oldTBPHS2Dn = reg;
    PWM_TBCTL(2) &= ~(1 << 13); // Down
    oldTBPHS2Up = PWM_TBPRD(2);
    }
    PWM_CMPA(2) = _cmpA;
    }
    // End of changing PWM2(phase shift) registers
    // Start of changing PWM1(1ph) registers
    // Set Duty Cycle
    {
    DefaultType _val = __fsat(fDAB_ControlLaw, 1 + 0, 0);
    _val = PWM_TBPRD(1) * (((1 + 0) - _val) * (1.0 / 1));
    PWM_CMPA(1) = (int)_val;
    }
    // End of changing PWM1(1ph) registers
    }


    void Initialize(void)
    {
    PS_SysInit(2, 10);
    PS_PwmStartStopClock(0); // Stop Pwm Clock
    PS_TimerInit(0, 0);
    {
    int i, preAdcNo = -1;
    /* PST_AdcAttr: Adc No., DiffMode, Channel No., Soc No., Trig Src, SampleTime(clock) */
    const PST_AdcAttr aryAdcInit[2] = {
    {0, 0, 2, 0, ADCTRIG_PWM1, 20000}, // Single-end mode: AdcNo=0, ChnNo=2, SocNo=0, SampClk=20000
    {1, 0, 2, 0, ADCTRIG_PWM1, 64} // Single-end mode: AdcNo=1, ChnNo=2, SocNo=0, SampClk=64
    };
    const PST_AdcAttr *p = aryAdcInit;
    for (i = 0; i < 2; i++, p++) {
    if (preAdcNo != p->nAdcNo) {
    PS_AdcInit(p->nAdcNo, p->nDiff);
    preAdcNo = p->nAdcNo;
    }
    PS_AdcSetChn(p->nAdcNo, p->nChnNo, p->nSocNo, p->nTrigSrc, p->nWindSz);
    }
    }

    PS_PwmInit(1, 0, 1, 1.e6/(switchfreq*1.0), ePwmUseAB, ePwmStartLow1, ePwmComplement, HRPWM_DISABLE); // pwmNo, pinSel, waveType, period, outtype, PwmA, PWMB, UseHRPwm
    PS_PwmSetDeadBand(1, 0, 2, 3, 0, 0.2, 0.2);
    PS_PwmSetIntrType(1, ePwmIntrAdc, 1, 0);
    PS_AdcSetIntr(0, 1, 0, Task); // AdcNo, IntrNo, SocNo, Interrupt Vector
    PS_PwmSetTripAction(1, eTzHiZ, eTzHiZ);
    PWM_CMPA(1) = (1 + 0 - 0) / (1.0 * 1) * PWM_TBPRD(1);
    PSM_PwmStart(1);

    PS_PwmInit(2, 0, 1, 1.e6/(switchfreq*1.0), ePwmUseAB, ePwmStartLow1, ePwmComplement, HRPWM_DISABLE); // pwmNo, pinSel, wave type, period, outtype, PwmA, PWMB, UseHRPwm
    PS_PwmSetDeadBand(2, 0, 2, 3, 0, 4, 4);
    PS_PwmSetPhaseDelay(2, 1, 0);
    PS_PwmSetIntrType(2, ePwmNoAdc, 1, 0);
    PS_PwmSetTripAction(2, eTzHiZ, eTzHiZ);
    PWM_CMPA(2) = (1 + 0 - 0) / (1.0 * 1) * PWM_TBPRD(2);
    PSM_PwmStart(2);

    PS_PwmStartStopClock(1); // Start Pwm Clock
    }


    void main()
    {
    Initialize();
    PSM_EnableIntr(); // Enable Global interrupt INTM
    PSM_EnableDbgm();
    for (;;) {
    }
    }

  • Hi Aldo,

    For the files reference in the #include, you want to make sure that their file location is included in the include paths in the project properties. This way the compiler and linker can find the file and correctly compile the code. CCS may be able to find the file when you ctrl+click the file name but this may give a false impression if the file isn't found in the project's include paths

    Regards,

    Peter