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: DSP based SPWM for three phase inverter

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

Tool/software:

Hello Everyone. I'm a beginner trying to implement a DSP-based Sinusoidal Pulse Width Modulation (SPWM) for a three-phase inverter using Code Composer Studio, I am using TMS320F28379D ver: 2.0. I've watched a couple of YouTube videos and managed to write a code. However, when I implemented it, I didn't get any signal on the oscilloscope. If anyone has a reference code that can help me with this project, I would greatly appreciate it, as my deadline is approaching. Thank you in advance.

  • Part Number: TMS320F28379D

    Tool/software:

     I'm attempting to debug this code on CCS, but the debugger is not progressing past the "int main(void)" line. How can I resolve this issue?

    /*
    * pwm.c
    *
    * Created on: 23 May 2024
    * Author: QUDUS
    */
    #include "F28x_Project.h"
    #include <math.h> // Include math.h for sinf and M_PI
    #include "F2837xD_epwm.h"
    #include "F2837xD_pievect.h"
    #include "F2837xD_gpio.h"

    #define PWM_PERIOD 10000 // For 10 kHz carrier frequency with 100 MHz SYSCLK
    #define SINE_TABLE_SIZE 256
    #define PHASE_SHIFT (SINE_TABLE_SIZE / 3) // 120 degrees phase shift
    #define SINE_UPDATE_INTERVAL 78 // 78.125 microseconds for 50 Hz fundamental frequency

    // Sine wave lookup table
    float sine_table[SINE_TABLE_SIZE];

    // Function prototypes
    void InitEPwm1();
    void InitEPwm2();
    void InitEPwm3();
    void InitSineTable();

    int main(void)
    {
    InitSysCtrl(); // Initialize system control
    DINT; // Disable CPU interrupts
    InitPieCtrl(); // Initialize the PIE control registers
    IER = 0x0000; // Disable CPU interrupts and clear all CPU interrupt flags
    IFR = 0x0000; // Clear all CPU interrupt flags
    InitPieVectTable(); // Initialize the PIE vector table

    InitGpio(); // Initialize GPIO for ePWM

    InitSineTable(); // Initialize the sine table

    InitEPwm1(); // Initialize ePWM1
    InitEPwm2(); // Initialize ePWM2
    InitEPwm3(); // Initialize ePWM3

    while(1)
    {
    int i;
    for(i = 0; i < SINE_TABLE_SIZE; i++)
    {
    // Update ePWM1
    EPwm1Regs.CMPA.bit.CMPA = (PWM_PERIOD / 2) * (sine_table[i] + 1);

    // Update ePWM2 (phase-shifted by 120 degrees)
    int idx2 = (i + PHASE_SHIFT) % SINE_TABLE_SIZE;
    EPwm2Regs.CMPA.bit.CMPA = (PWM_PERIOD / 2) * (sine_table[idx2] + 1);

    // Update ePWM3 (phase-shifted by 240 degrees)
    int idx3 = (i + 2 * PHASE_SHIFT) % SINE_TABLE_SIZE;
    EPwm3Regs.CMPA.bit.CMPA = (PWM_PERIOD / 2) * (sine_table[idx3] + 1);

    DELAY_US(SINE_UPDATE_INTERVAL); // Delay to achieve the 50 Hz fundamental frequency
    }
    }
    }

    void InitEPwm1()
    {
    EALLOW;

    // Set up ePWM1
    EPwm1Regs.TBPRD = PWM_PERIOD - 1; // Set the PWM period
    EPwm1Regs.TBPHS.all = 0x00000000; // Phase is 0
    EPwm1Regs.TBCTR = 0x0000; // Clear counter

    // Set up compare values
    EPwm1Regs.CMPA.bit.CMPA = 0; // Set the initial compare A value

    // Set up the counter mode
    EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up and down
    EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
    EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
    EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;

    // Set up the action qualifier
    EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM1A on event A, up count
    EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; // Clear PWM1A on event A, down count

    EDIS;
    }

    void InitEPwm2()
    {
    EALLOW;

    // Set up ePWM2
    EPwm2Regs.TBPRD = PWM_PERIOD - 1; // Set the PWM period
    EPwm2Regs.TBPHS.all = PWM_PERIOD / 3; // Phase shift for 120 degrees
    EPwm2Regs.TBCTR = 0x0000; // Clear counter

    // Set up compare values
    EPwm2Regs.CMPA.bit.CMPA = 0; // Set the initial compare A value

    // Set up the counter mode
    EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up and down
    EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Enable phase loading
    EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; // Synchronize with ePWM1
    EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
    EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;

    // Set up the action qualifier
    EPwm2Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM2A on event A, up count
    EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR; // Clear PWM2A on event A, down count

    EDIS;
    }

    void InitEPwm3()
    {
    EALLOW;

    // Set up ePWM3
    EPwm3Regs.TBPRD = PWM_PERIOD - 1; // Set the PWM period
    EPwm3Regs.TBPHS.all = (2 * PWM_PERIOD) / 3; // Phase shift for 240 degrees
    EPwm3Regs.TBCTR = 0x0000; // Clear counter

    // Set up compare values
    EPwm3Regs.CMPA.bit.CMPA = 0; // Set the initial compare A value

    // Set up the counter mode
    EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up and down
    EPwm3Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Enable phase loading
    EPwm3Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; // Synchronize with ePWM1
    EPwm3Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
    EPwm3Regs.TBCTL.bit.CLKDIV = TB_DIV1;

    // Set up the action qualifier
    EPwm3Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM3A on event A, up count
    EPwm3Regs.AQCTLA.bit.CAD = AQ_CLEAR; // Clear PWM3A on event A, down count

    EDIS;
    }

    void InitSineTable()
    {
    int i;
    for(i = 0; i < SINE_TABLE_SIZE; i++)
    {
    sine_table[i] = sinf((2 * M_PI * i) / SINE_TABLE_SIZE);
    }
    }

  • Hello,

    Combined your two threads as they are related.

    the debugger is not progressing past the "int main(void)" line

    Which line of code within the main() are you seeing the program stop at? Please using the "step over" and "step into" buttons to step into the functions so we can determine which line is specifically causing some issue. Have you been referencing any of our C2000ware software examples? If yes, which?

    For SPWM guidance, please refer to these similar threads (there are likely many more that you can sift through in the E2E forum). While they reference different devices, the implementation would be analogous for F28379D:

    Best Regards,

    Allison