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.

ezdsp f28335 4 pwm generation(different angle)

Other Parts Discussed in Thread: CONTROLSUITE

hello there,

I am currently doing my project using this board to control MOSFETs and IGBTs through 4 PWM with different angles

I have no experience in using this board and the programming,but I already have the ePWM examples from controlsuite(example_2833xEPWMTimerInt)

I think I should edit from the example to perform the task but I have no idea where to start

MY PWM specs

frequency=20kHz

duty cycle = 50%

1st PWM start at 0-90 degree

2nd PWM start at 180-360 degree

3rd PWM start at 45-225 degree

4th PWM start at 225-405 degree

 

pls help,

Thank you,

Faizal

  • Hi Faizal,

    Before starting with coding I would like you to refer the ePWM user guide that can be downloaded from here:

    http://www.ti.com/lit/ug/sprug04a/sprug04a.pdf

    and for other peripherals from here:

    http://www.ti.com/product/TMS320F28335/technicaldocuments

    Regards,

    Gautam

  • Ok..

    I got this code from the example as mention before,it is refering to the phase control of the signal if I am not mistaken.Should I change this to 0,45,180 and 225?

    EPwm1Regs.TBPHS.half.TBPHS = 100;
    EPwm2Regs.TBPHS.half.TBPHS = 200;
    EPwm3Regs.TBPHS.half.TBPHS = 300;
    EPwm4Regs.TBPHS.half.TBPHS = 400;
    EPwm5Regs.TBPHS.half.TBPHS = 500;
    EPwm6Regs.TBPHS.half.TBPHS = 600;

    If i want the period to be 20kHz,I should change this value to 0x4E20 right?

    #define PWM1_TIMER_TBPRD 0x1FFF
    #define PWM2_TIMER_TBPRD 0x1FFF
    #define PWM3_TIMER_TBPRD 0x1FFF
    #define PWM4_TIMER_TBPRD 0x1FFF
    #define PWM5_TIMER_TBPRD 0x1FFF
    #define PWM6_TIMER_TBPRD 0x1FFF

    EPwm1Regs.TBPRD = PWM1_TIMER_TBPRD;
    EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
    EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
    EPwm1Regs.ETSEL.bit.INTEN = PWM1_INT_ENABLE; // Enable INT
    EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 1st event

    Btw,in the coding,I cant fine the TB_COUNT_UP variable define here.The same goes as ET_CTR_ZERO and ET_1st.is it refering to other source code related?

  • Mohamad Faizal Romli said:
    Btw,in the coding,I cant fine the TB_COUNT_UP variable define here.The same goes as ET_CTR_ZERO and ET_1st.is it refering to other source code related?

    Refer this sample code for up count configuration:

    0652.Example_2833xEPwmUpAQ.c
    //###########################################################################
    //
    // FILE:    Example_2833xEPwm3UpAQ.c
    //
    // TITLE:   Action Qualifier Module Upcount mode.
    //
    // ASSUMPTIONS:
    //
    //     This program requires the DSP2833x header files.
    //
    //     Monitor the ePWM1 - ePWM3 pins on a oscilloscope as
    //     described below.
    //
    //        EPWM1A is on GPIO0
    //        EPWM1B is on GPIO1
    //
    //        EPWM2A is on GPIO2
    //        EPWM2B is on GPIO3
    //
    //        EPWM3A is on GPIO4
    //        EPWM3B is on GPIO5
    //
    //     As supplied, this project is configured for "boot to SARAM"
    //     operation.  The 2833x Boot Mode table is shown below.
    //     For information on configuring the boot mode of an eZdsp,
    //     please refer to the documentation included with the eZdsp,
    //
    //       $Boot_Table:
    //
    //         GPIO87   GPIO86     GPIO85   GPIO84
    //          XA15     XA14       XA13     XA12
    //           PU       PU         PU       PU
    //        ==========================================
    //            1        1          1        1    Jump to Flash
    //            1        1          1        0    SCI-A boot
    //            1        1          0        1    SPI-A boot
    //            1        1          0        0    I2C-A boot
    //            1        0          1        1    eCAN-A boot
    //            1        0          1        0    McBSP-A boot
    //            1        0          0        1    Jump to XINTF x16
    //            1        0          0        0    Jump to XINTF x32
    //            0        1          1        1    Jump to OTP
    //            0        1          1        0    Parallel GPIO I/O boot
    //            0        1          0        1    Parallel XINTF boot
    //            0        1          0        0    Jump to SARAM	    <- "boot to SARAM"
    //            0        0          1        1    Branch to check boot mode
    //            0        0          1        0    Boot to flash, bypass ADC cal
    //            0        0          0        1    Boot to SARAM, bypass ADC cal
    //            0        0          0        0    Boot to SCI-A, bypass ADC cal
    //                                              Boot_Table_End$
    //
    // DESCRIPTION:
    //
    //    This example configures ePWM1, ePWM2, ePWM3 to produce an
    //    waveform with independant modulation on EPWMxA and
    //    EPWMxB.
    //
    //    The compare values CMPA and CMPB are modified within the ePWM's ISR
    //
    //    The TB counter is in upmode for this example.
    //
    //    View the EPWM1A/B, EPWM2A/B and EPWM3A/B waveforms
    //    via an oscilloscope
    //
    //
    //###########################################################################
    // $TI Release: 2833x/2823x Header Files and Peripheral Examples V133 $
    // $Release Date: June 8, 2012 $
    //###########################################################################
    
    
    #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    
    
    typedef struct
    {
       volatile struct EPWM_REGS *EPwmRegHandle;
       Uint16 EPwm_CMPA_Direction;
       Uint16 EPwm_CMPB_Direction;
       Uint16 EPwmTimerIntCount;
       Uint16 EPwmMaxCMPA;
       Uint16 EPwmMinCMPA;
       Uint16 EPwmMaxCMPB;
       Uint16 EPwmMinCMPB;
    }EPWM_INFO;
    
    
    // Prototype statements for functions found within this file.
    void InitEPwm1Example(void);
    void InitEPwm2Example(void);
    void InitEPwm3Example(void);
    interrupt void epwm1_isr(void);
    interrupt void epwm2_isr(void);
    interrupt void epwm3_isr(void);
    void update_compare(EPWM_INFO*);
    
    // Global variables used in this example
    EPWM_INFO epwm1_info;
    EPWM_INFO epwm2_info;
    EPWM_INFO epwm3_info;
    
    // Configure the period for each timer
    #define EPWM1_TIMER_TBPRD  2000  // Period register
    #define EPWM1_MAX_CMPA     1950
    #define EPWM1_MIN_CMPA       50
    #define EPWM1_MAX_CMPB     1950
    #define EPWM1_MIN_CMPB       50
    
    #define EPWM2_TIMER_TBPRD  2000  // Period register
    #define EPWM2_MAX_CMPA     1950
    #define EPWM2_MIN_CMPA       50
    #define EPWM2_MAX_CMPB     1950
    #define EPWM2_MIN_CMPB       50
    
    #define EPWM3_TIMER_TBPRD  2000  // Period register
    #define EPWM3_MAX_CMPA      950
    #define EPWM3_MIN_CMPA       50
    #define EPWM3_MAX_CMPB     1950
    #define EPWM3_MIN_CMPB     1050
    
    
    // To keep track of which way the compare value is moving
    #define EPWM_CMP_UP   1
    #define EPWM_CMP_DOWN 0
    
    
    
    void main(void)
    {
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the DSP2833x_SysCtrl.c file.
       InitSysCtrl();
    
    // Step 2. Initalize GPIO:
    // This example function is found in the DSP2833x_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    // InitGpio();  // Skipped for this example
    
    // For this case just init GPIO pins for ePWM1, ePWM2, ePWM3
    // These functions are in the DSP2833x_EPwm.c file
       InitEPwm1Gpio();
       InitEPwm2Gpio();
       InitEPwm3Gpio();
    
    
    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts
       DINT;
    
    // Initialize the PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared.
    // This function is found in the DSP2833x_PieCtrl.c file.
       InitPieCtrl();
    
    // Disable CPU interrupts and clear all CPU interrupt flags:
       IER = 0x0000;
       IFR = 0x0000;
    
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    // This will populate the entire table, even if the interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in DSP2833x_DefaultIsr.c.
    // This function is found in DSP2833x_PieVect.c.
       InitPieVectTable();
    
    // Interrupts that are used in this example are re-mapped to
    // ISR functions found within this file.
       EALLOW;  // This is needed to write to EALLOW protected registers
       PieVectTable.EPWM1_INT = &epwm1_isr;
       PieVectTable.EPWM2_INT = &epwm2_isr;
       PieVectTable.EPWM3_INT = &epwm3_isr;
       EDIS;    // This is needed to disable write to EALLOW protected registers
    
    // Step 4. Initialize all the Device Peripherals:
    // This function is found in DSP2833x_InitPeripherals.c
    // InitPeripherals();  // Not required for this example
    
    // For this example, only initialize the ePWM
    
       EALLOW;
       SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
       EDIS;
    
       InitEPwm1Example();
       InitEPwm2Example();
       InitEPwm3Example();
    
       EALLOW;
       SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
       EDIS;
    
    
    // Step 5. User specific code, enable interrupts:
    
    // Enable CPU INT3 which is connected to EPWM1-3 INT:
       IER |= M_INT3;
    
    // Enable EPWM INTn in the PIE: Group 3 interrupt 1-3
       PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
       PieCtrlRegs.PIEIER3.bit.INTx2 = 1;
       PieCtrlRegs.PIEIER3.bit.INTx3 = 1;
    
    // Enable global Interrupts and higher priority real-time debug events:
       EINT;   // Enable Global interrupt INTM
       ERTM;   // Enable Global realtime interrupt DBGM
    
    // Step 6. IDLE loop. Just sit and loop forever (optional):
       for(;;)
       {
           asm("          NOP");
       }
    
    }
    
    interrupt void epwm1_isr(void)
    {
       // Update the CMPA and CMPB values
       update_compare(&epwm1_info);
    
       // Clear INT flag for this timer
       EPwm1Regs.ETCLR.bit.INT = 1;
    
       // Acknowledge this interrupt to receive more interrupts from group 3
       PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
    }
    
    
    interrupt void epwm2_isr(void)
    {
    
       // Update the CMPA and CMPB values
       update_compare(&epwm2_info);
    
       // Clear INT flag for this timer
       EPwm2Regs.ETCLR.bit.INT = 1;
    
       // Acknowledge this interrupt to receive more interrupts from group 3
       PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
    }
    
    interrupt void epwm3_isr(void)
    {
    
       // Update the CMPA and CMPB values
       update_compare(&epwm3_info);
    
       // Clear INT flag for this timer
       EPwm3Regs.ETCLR.bit.INT = 1;
    
       // Acknowledge this interrupt to receive more interrupts from group 3
       PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
    }
    
    void InitEPwm1Example()
    {
    
       // Setup TBCLK
       EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
       EPwm1Regs.TBPRD = EPWM1_TIMER_TBPRD;       // Set timer period
       EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;    // Disable phase loading
       EPwm1Regs.TBPHS.half.TBPHS = 0x0000;       // Phase is 0
       EPwm1Regs.TBCTR = 0x0000;                  // Clear counter
       EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV2;   // Clock ratio to SYSCLKOUT
       EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV2;
    
       // Setup shadow register load on ZERO
       EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
       EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
       EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
       EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
    
       // Set Compare values
       EPwm1Regs.CMPA.half.CMPA = EPWM1_MIN_CMPA;    // Set compare A value
       EPwm1Regs.CMPB = EPWM1_MIN_CMPB;              // Set Compare B value
    
       // Set actions
       EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;            // Set PWM1A on Zero
       EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;          // Clear PWM1A on event A, up count
    
       EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET;            // Set PWM1B on Zero
       EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR;          // Clear PWM1B on event B, up count
    
       // Interrupt where we will change the Compare Values
       EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;     // Select INT on Zero event
       EPwm1Regs.ETSEL.bit.INTEN = 1;                // Enable INT
       EPwm1Regs.ETPS.bit.INTPRD = ET_3RD;           // Generate INT on 3rd event
    
       // Information this example uses to keep track
       // of the direction the CMPA/CMPB values are
       // moving, the min and max allowed values and
       // a pointer to the correct ePWM registers
       epwm1_info.EPwm_CMPA_Direction = EPWM_CMP_UP; // Start by increasing CMPA & CMPB
       epwm1_info.EPwm_CMPB_Direction = EPWM_CMP_UP;
       epwm1_info.EPwmTimerIntCount = 0;             // Zero the interrupt counter
       epwm1_info.EPwmRegHandle = &EPwm1Regs;        // Set the pointer to the ePWM module
       epwm1_info.EPwmMaxCMPA = EPWM1_MAX_CMPA;      // Setup min/max CMPA/CMPB values
       epwm1_info.EPwmMinCMPA = EPWM1_MIN_CMPA;
       epwm1_info.EPwmMaxCMPB = EPWM1_MAX_CMPB;
       epwm1_info.EPwmMinCMPB = EPWM1_MIN_CMPB;
    
    }
    
    
    void InitEPwm2Example()
    {
       // Setup TBCLK
       EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
       EPwm2Regs.TBPRD = EPWM2_TIMER_TBPRD;       // Set timer period
       EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE;    // Disable phase loading
       EPwm2Regs.TBPHS.half.TBPHS = 0x0000;       // Phase is 0
       EPwm2Regs.TBCTR = 0x0000;                  // Clear counter
       EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV2;   // Clock ratio to SYSCLKOUT
       EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV2;
    
       // Setup shadow register load on ZERO
       EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
       EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
       EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
       EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
    
       // Set Compare values
       EPwm2Regs.CMPA.half.CMPA = EPWM2_MIN_CMPA;       // Set compare A value
       EPwm2Regs.CMPB = EPWM2_MAX_CMPB;                 // Set Compare B value
    
       // Set actions
       EPwm2Regs.AQCTLA.bit.PRD = AQ_CLEAR;             // Clear PWM2A on Period
       EPwm2Regs.AQCTLA.bit.CAU = AQ_SET;               // Set PWM2A on event A, up count
    
       EPwm2Regs.AQCTLB.bit.PRD = AQ_CLEAR;             // Clear PWM2B on Period
       EPwm2Regs.AQCTLB.bit.CBU = AQ_SET;               // Set PWM2B on event B, up count
    
       // Interrupt where we will change the Compare Values
       EPwm2Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;        // Select INT on Zero event
       EPwm2Regs.ETSEL.bit.INTEN = 1;                   // Enable INT
       EPwm2Regs.ETPS.bit.INTPRD = ET_3RD;              // Generate INT on 3rd event
    
       // Information this example uses to keep track
       // of the direction the CMPA/CMPB values are
       // moving, the min and max allowed values and
       // a pointer to the correct ePWM registers
       epwm2_info.EPwm_CMPA_Direction = EPWM_CMP_UP;    // Start by increasing CMPA
       epwm2_info.EPwm_CMPB_Direction = EPWM_CMP_DOWN;  // and decreasing CMPB
       epwm2_info.EPwmTimerIntCount = 0;                // Zero the interrupt counter
       epwm2_info.EPwmRegHandle = &EPwm2Regs;           // Set the pointer to the ePWM module
       epwm2_info.EPwmMaxCMPA = EPWM2_MAX_CMPA;         // Setup min/max CMPA/CMPB values
       epwm2_info.EPwmMinCMPA = EPWM2_MIN_CMPA;
       epwm2_info.EPwmMaxCMPB = EPWM2_MAX_CMPB;
       epwm2_info.EPwmMinCMPB = EPWM2_MIN_CMPB;
    
    }
    
    
    void InitEPwm3Example(void)
    {
    
    
       // Setup TBCLK
       EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
       EPwm3Regs.TBPRD = EPWM3_TIMER_TBPRD;       // Set timer period
       EPwm3Regs.TBCTL.bit.PHSEN = TB_DISABLE;    // Disable phase loading
       EPwm3Regs.TBPHS.half.TBPHS = 0x0000;       // Phase is 0
       EPwm3Regs.TBCTR = 0x0000;                  // Clear counter
       EPwm3Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;   // Clock ratio to SYSCLKOUT
       EPwm3Regs.TBCTL.bit.CLKDIV = TB_DIV1;
    
       // Setup shadow register load on ZERO
       EPwm3Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
       EPwm3Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
       EPwm3Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
       EPwm3Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
    
      // Set Compare values
       EPwm3Regs.CMPA.half.CMPA = EPWM3_MIN_CMPA; // Set compare A value
       EPwm3Regs.CMPB = EPWM3_MAX_CMPB;           // Set Compare B value
    
       // Set Actions
       EPwm3Regs.AQCTLA.bit.CAU = AQ_SET;         // Set PWM3A on event B, up count
       EPwm3Regs.AQCTLA.bit.CBU = AQ_CLEAR;       // Clear PWM3A on event B, up count
    
       EPwm3Regs.AQCTLB.bit.ZRO = AQ_TOGGLE;      // Toggle EPWM3B on Zero
    
       // Interrupt where we will change the Compare Values
       EPwm3Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;     // Select INT on Zero event
       EPwm3Regs.ETSEL.bit.INTEN = 1;                // Enable INT
       EPwm3Regs.ETPS.bit.INTPRD = ET_3RD;           // Generate INT on 3rd event
    
       // Start by increasing the compare A and decreasing compare B
       epwm3_info.EPwm_CMPA_Direction = EPWM_CMP_UP;
       epwm3_info.EPwm_CMPB_Direction = EPWM_CMP_DOWN;
       // Start the cout at 0
       epwm3_info.EPwmTimerIntCount = 0;
       epwm3_info.EPwmRegHandle = &EPwm3Regs;
       epwm3_info.EPwmMaxCMPA = EPWM3_MAX_CMPA;
       epwm3_info.EPwmMinCMPA = EPWM3_MIN_CMPA;
       epwm3_info.EPwmMaxCMPB = EPWM3_MAX_CMPB;
       epwm3_info.EPwmMinCMPB = EPWM3_MIN_CMPB;
    }
    
    
    void update_compare(EPWM_INFO *epwm_info)
    {
    
    
       // Every 10'th interrupt, change the CMPA/CMPB values
       if(epwm_info->EPwmTimerIntCount == 10)
       {
           epwm_info->EPwmTimerIntCount = 0;
    
           // If we were increasing CMPA, check to see if
           // we reached the max value.  If not, increase CMPA
           // else, change directions and decrease CMPA
    	   if(epwm_info->EPwm_CMPA_Direction == EPWM_CMP_UP)
    	   {
    	       if(epwm_info->EPwmRegHandle->CMPA.half.CMPA < epwm_info->EPwmMaxCMPA)
    	       {
    	          epwm_info->EPwmRegHandle->CMPA.half.CMPA++;
    	       }
    	       else
    	       {
    	          epwm_info->EPwm_CMPA_Direction = EPWM_CMP_DOWN;
                  epwm_info->EPwmRegHandle->CMPA.half.CMPA--;
    	       }
    	   }
    
    	   // If we were decreasing CMPA, check to see if
           // we reached the min value.  If not, decrease CMPA
           // else, change directions and increase CMPA
    	   else
    	   {
    	       if(epwm_info->EPwmRegHandle->CMPA.half.CMPA == epwm_info->EPwmMinCMPA)
    	       {
    	          epwm_info->EPwm_CMPA_Direction = EPWM_CMP_UP;
    	          epwm_info->EPwmRegHandle->CMPA.half.CMPA++;
    	       }
    	       else
    	       {
    	          epwm_info->EPwmRegHandle->CMPA.half.CMPA--;
    	       }
    	   }
    
    	   // If we were increasing CMPB, check to see if
           // we reached the max value.  If not, increase CMPB
           // else, change directions and decrease CMPB
    	   if(epwm_info->EPwm_CMPB_Direction == EPWM_CMP_UP)
    	   {
    	       if(epwm_info->EPwmRegHandle->CMPB < epwm_info->EPwmMaxCMPB)
    	       {
    	          epwm_info->EPwmRegHandle->CMPB++;
    	       }
    	       else
    	       {
    	          epwm_info->EPwm_CMPB_Direction = EPWM_CMP_DOWN;
    	          epwm_info->EPwmRegHandle->CMPB--;
    	       }
    	   }
    
    	   // If we were decreasing CMPB, check to see if
           // we reached the min value.  If not, decrease CMPB
           // else, change directions and increase CMPB
    
    	   else
    	   {
    	       if(epwm_info->EPwmRegHandle->CMPB == epwm_info->EPwmMinCMPB)
    	       {
    	          epwm_info->EPwm_CMPB_Direction = EPWM_CMP_UP;
    	          epwm_info->EPwmRegHandle->CMPB++;
    	       }
    	       else
    	       {
    	          epwm_info->EPwmRegHandle->CMPB--;
    	       }
    	   }
       }
       else
       {
          epwm_info->EPwmTimerIntCount++;
       }
    
       return;
    }
    
    
    //===========================================================================
    // No more.
    //===========================================================================
    

    This can be found here: C:\ti\controlSUITE\device_support\f2833x\v133\DSP2833x_examples_ccsv4\epwm_up_aq

    Regards,

    Gautam

  • PieCtrlRegs.PIEIER3.bit.INTx1 = PWM1_INT_ENABLE;

    EPwm1Regs.TBPHS.half.TBPHS = 100;

    what is the different between .bit and .half and for .bit.INTx1,what does it mean?

    I know that the TBPHS is the register for time-base-phase register in Epwm

  • Mohamad Faizal Romli said:
    what is the different between .bit and .half and for .bit.INTx1,what does it mean?

    You use .bit to configure the respective bit in a register. For eg. EPWM1_INT belongs to INTx1. This is very well mentioned in the document "System Control and Interrupts" present in the user guides section. Hence please go through all the documents & peripheral user guides before/while coding.

    For .half:

    EPwm1Regs.CMPA.half.CMPA = Duty1A; // adjust duty for output EPWM1A
    EPwm1Regs.CMPB = Duty1B; // adjust duty for output EPWM1B

    Both mean the same and will decide the duty parameter. There's no proper significance of the term half. Though so many members including me keep wondering why "half" but still no "to the point" answer.


    Regards,

    Gautam

  • OK..will do

    I will try to edit  this part and see the result..

    #define PWM1_TIMER_TBPRD 0x1FFF
    #define PWM2_TIMER_TBPRD 0x1FFF
    #define PWM3_TIMER_TBPRD 0x1FFF
    #define PWM4_TIMER_TBPRD 0x1FFF
    #define PWM5_TIMER_TBPRD 0x1FFF
    #define PWM6_TIMER_TBPRD 0x1FFF

    EPwm1Regs.TBPHS.half.TBPHS = 100;
    EPwm2Regs.TBPHS.half.TBPHS = 200;
    EPwm3Regs.TBPHS.half.TBPHS = 300;
    EPwm4Regs.TBPHS.half.TBPHS = 400;
    EPwm5Regs.TBPHS.half.TBPHS = 500;
    EPwm6Regs.TBPHS.half.TBPHS = 600;

    The board is still at my lecturer and I will start to do it next 2 weeks..

    Btw,do you have any suggestion where I should study more before I start my project other than mentioned topic?

    Thx for helping though

  • Mohamad Faizal Romli said:
    Btw,do you have any suggestion where I should study more before I start my project other than mentioned topic?

    You can go through this workshop meant for F28335 mcu: http://processors.wiki.ti.com/index.php/C2000_Archived_Workshops#F28335_Workshop

    Regards,

    Gautam

  • Hello there...

    I am back here and I have tested the DSP board with the example of PWM

    I manage to get the PWM with the frequency of 20kHz as desired

    but different example have different value setup for the TBPRD register

    I use the formula found in the training slide

    1/2 x (Ftbclk/Fpwm) = a

    a is the value we write at the program...

    how to edit the Ftbclk at the first place?

    one more thing

    is it safe to debug and stop for the DSP board?..I keep doing that before when I want to edit the code..

  • Mohamad Faizal Romli said:
    how to edit the Ftbclk at the first place?

    Here's how you can do it:

    EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // TBCLK = SYSCLK

    So, you can alter TB_DIV2 etc... Check out the options in the header file.

    Mohamad Faizal Romli said:
    is it safe to debug and stop for the DSP board?

    There should not be any issue while stopping & debugging; but at higher power levels one should be cautious.

    Regards,

    Gautam

  • I think for now I will try to get the output pwm first..

    How high power level do you refer to?Because later on I will connect it to the switches of my DC-DC converter of 1 Kw..

    Btw..I refer to the slide about the HSPCLKDIV..

    the period refer to the prescale value that we set as below.

    000 = /1

    001= /2

    002 = /4

    I choose TB_DIV4=0x2 =/4 ..but when try it,i need to set it the TBPRD to 235,to produce a 20khz signal..

    it seems like the Ftbclk for this setting is divided by 2^4 instead of 4..my board has 150Mhz Speed...

    but on another example when it is set at TB_DIV2=0x1 = /2..it is now purely divide by 2 instead of 2^2...

  • Mohamad Faizal Romli said:
    How high power level do you refer to?Because later on I will connect it to the switches of my DC-DC converter of 1 Kw..

    Yup above 1kW one has to be cautious ie we've to switch of the battery breaker and Solar PV breaker (if applicable) and then program the controller. You might be aware that while programming the controller's GPIOs behave differently which might affect the power devices.

    Mohamad Faizal Romli said:

    I choose TB_DIV4=0x2 =/4 ..but when try it,i need to set it the TBPRD to 235,to produce a 20khz signal..

    it seems like the Ftbclk for this setting is divided by 2^4 instead of 4..my board has 150Mhz Speed...

    but on another example when it is set at TB_DIV2=0x1 = /2..it is now purely divide by 2 instead of 2^2...

    Please check the Sysctrl user guide for limitations and exceptions.

    Regards,

    Gautam

  • Ok..I will be really careful when I connect it to my device later on..

    you mentioned that the GPIOs behave differently?what do you mean by that actually?

    As well as I know..

    The power switches like MOSFET/IGBT required +-15V to turn on their gates..So later on,I will connect it amplifier IC before connecting it the the gate of the switches

    For the signal frequency,I already manage to understand it now..The Ftbclk depend on 2 register in EPWMxRegs.TBCTL which is CLKDIV & HSPCLKDIV

    Now I need to adjust 3 of my signals angle to start at 30 degree ,180 degree and 210 degree

    it seems like that this 3 signals need another extra signal  connected to their SyncIn to do the delay.

    Is it ok if I connect my EPWM1A output to SynIn directly..but the Vp-p of this signal is more than 3.3V

  • Mohamad Faizal Romli said:
    you mentioned that the GPIOs behave differently?what do you mean by that actually?

    Check this: http://processors.wiki.ti.com/index.php/General_Purpose_IO_%28GPIO%29_FAQ_for_C2000#Q:_What_is_the_status_of_the_GPIO_after_reset.3F

    Mohamad Faizal Romli said:
    Now I need to adjust 3 of my signals angle to start at 30 degree ,180 degree and 210 degree

    These delays can be introduces by configuring TBCTR register too. Just try and let me know.

    Regards,

    Gautam

  • I don't get much the idea from the link given

    What i found during testing is that the ePWM that I configure still produce signal eventhough i stop the debugging process

    If I unplug the usb,it still produce signal but not a square wave anymore

    Is this what you mean?

    For the delay,i will try it later on

     

    Thanks,

    Faizal

  • Mohamad Faizal Romli said:
    Is this what you mean?

    Nope, its like when you press the debug button...it starts erasing the sectors first and then programming it. During these events GPIO status are as shown in the above link.

    If your board is live with the PWM drivers still functional, during this reset, erase & flash conditions there's a possibility that all your switches might turn ON at the same time which is not desirable.

    Regards,

    Gautam

  • so..about the PULL UP things at the link given,

    I am using the GPIO output as PWM output,it is disabled at reset..

    Should I worry about it?

    about the status during the board reset,

    can I do anything so that my board will not send any PWMs output when I stop the debugging process?

  • Mohamad Faizal Romli said:
    Should I worry about it?

    Not required.

    Mohamad Faizal Romli said:
    can I do anything so that my board will not send any PWMs output when I stop the debugging process?

    When you stop the debug, the mcu will continue to deliver the same. You'll have to disconnect the power to stop the PWMs. Btw this should not be an issue, only during the start of debug you need to be careful.

    Regards,

    Gautam

  • Thanks to you,

    I manage to do the shift angle using the TBCTR

    But i still working on how to calculate exactly the delay for the TBCTR

    I set my prescale to full @ 150MHz

    so my TBPRD = 3750 to get 20kHz PWMs

    I should get the 30 degree shift when I set the TBCTR value @

    (3750/360)* 30 =  313


    but when I test it,the delay is much less when I put this value

    I need to increase to TBCTR = 450 to get 30 angle shift.

    I just wonder how the exact method to calculate the value correctly and how it works.

    1 more things..

    When I do the testing for the EPWM1 and EPWM2

    I get the waveform exactly as I want (EPWM1 off --> EPWM2 on)without delay

    but for EPWM3 and EPWM4 with the same code as EPWM1 and EPWM 2

    There is a little bit delay for the signal

    EPWM4 on not exactly after EPWM3 off..I just wonder why...

  • I've observed the same too... it seems to have an offset. Didn't dig deeper as in why!

    Regards,

    Gautam

  • Hi MFR,

    Got the answer.... I'd to dig in :)

    Mohamad Faizal Romli said:

    I set my prescale to full @ 150MHz

    so my TBPRD = 3750 to get 20kHz PWMs

    I should get the 30 degree shift when I set the TBCTR value @

    (3750/360)* 30 =  313

    This is because the PWM clocks are not in sync! All you need to do is turn off the clk during pwm configuration and the start the clock only after pwm1 & pwm2 configurations are done.

    eg.

    Eallow;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC=0;
    EDIS;
    
    //All your ePWM configurations
    
    Eallow;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC=1;
    EDIS;

    Regards,

    Gautam

  • Ok...i will try it tomorrow

    About the epwm3 and epwm4 delays

    Do you observe it as well?

     

    Thank you,

    Faizal

  • I think I already test it with the sync option 

    The code is something like this

    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
    EDIS;

    InitEPwm1Example();
    InitEPwm2Example();
    InitEPwm3Example();
    InitEPwm4Example();

    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
    EDIS;

    BTW i will try it again tomorrow and update the result

  • Will check this tomorrow while in office and revert.

    Regards,

    Gautam

  • Hello there,

    It has been awhile seen the last post

    I think the signals should do just fine for my project

    Thank you so much for your help,

    Hope to learn more about the Texas Instrument Product..

    Any suggestion product?

    Maybe a lower price compare the one that I am using?


    Thanks,
    Faizal
  • Hi Faizal,

    You can use the part number F28027 ie used in C2000 Launchpad. Check the description site and the datasheet for more info. If you want a floating point controller then you can use F28069 part number.

    Regards,

    Gautam

  • Hello there,

    Thank you for the suggestion :D
    BTW,there are few things that I need to adjust for my project,

    I need to introduce the dead time of the signals between S1(0degree-180degree ) and S2 (180-360degree) , S3(45degree-225degree) and S4(225degree-405degree)

    The dead time is when the S1 and S2 OFF,and the same goes as S3 and S4,
    because the real switches has on/off delays..Without this dead time my circuit will be short circuit

    Can you suggest a method to that,
    I am thinking of adjusting the duty cycle of the S2 and S4

    Thank you,
    Faizal
  • Faizal, if you refer the ePWM userguide of the device you'll be able to find different configurations of the PWMs with respective codes.

    Regards,
    Gautam
  • Thank you Mr Gautam
    I manage to do the delay

    But now I am having problem with the board
    I have tested my circuit this evening.The PWM output is working fine,the same goes of the amplified signal from the gate driver IC,I connect the amplified signal to IGBT in my dc-dc converter(gate terminal)
    But then when I am about to increase the dc-dc converter circuit input voltage(around 20V-30V)
    My laptop start to refresh like it is detecting the DSP board just being connected,
    but I plugged it to my laptop long time before that.
    I notice it because of the sound similar to when we plugged in thumbdrive/ext hard drive.
    Then I disconnect everything and test back the PWM output

    Now the board does not produce any PWM output anymore,just the noise from all the PWM output
    I restarted my laptop,disconnected the DSP board but it is still not working
    The Code Composer Studio detect the board as usual like before.Debugging the code just work fine,but no output

    Any suggestion why?
  • Did you try with any pwm sample code?
  • Yes,I do try some it,It still does not work..
    I have read some of the post regarding the JTAG and the USB cable.

    e2e.ti.com/.../82599

    Is it possible?
  • You can try changing the cable but you should also check the health of your board. Check the voltage levels, overheats if any.

    Regards,
    Gautam
  • How do I check the voltage level?
  • I mean voltage levels on the board using DSO or multimeter and verify the same values present in the schematics.

    Regards,
    Gautam