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.

TMS320F28069: Driving gate pulse of three SCR's of three phase halfwave bridge rectifier using PWM.

Part Number: TMS320F28069

Hi,

I am using TMS320F28069 and studying EPWM module of the TMS320F28069, I want to fire gate pulse for the three SCR's of three phase half-wave bridge rectifier.

so,will be using "Zero crossing detector", and based on the output of the ZCD i will fire the gate pulses.

please ,suggest me the correct flow to drive gate pulses and which ePWM module to use to accomplish it.

Thank you 

Your Faithfully

Mihir Dave

  • Well, Mihir unfortunately you're going to have to determine what outputs and control scheme that you would like to use to control your system. 

    On the topic of which PWM modules to use I may be able to provide some helpful input. The sync chain for this device is pretty simple, ePWM1 connects to ePWM2 to and then to ePWM3 and so on sequentially. If you would like to synchronize 3 different PWM modules I would suggest choosing 3 in a row, for example 1,2,3 or 4,5,6. If you choose 1,3,4 that is possible to sync, but PWM 2 will never be able to synchronize to any other PWMs other than PWM1 thus reducing the chance to fix bugs in your system later on.

    Additionally when choosing a 'master' PWM module, which sends the synchronization pulse, you want to choose the slowest PWM signal. This will avoid the issue where your sync pulses reset the slave PWM modules before their cycle has completed.

    Best of luck.
    Regards,
    Cody 

  • Hi,

    So, I want to generate ePWM of 7 milli seconds to fire scr gate pulse.

    is it possible?

    Thank yo

    Your Faithfully 

    Mihir Dave

  • Yes, you can. That is a very long pulse, so you should understand that the PWM's counters and compare registers are only 16 bits wide. Running TBCLK at 90MHz you would need nearly 700,000 clock ticks, which does not fit within a 16b register.

    You have 2 options.

    1. Use the eCAP module's APWM mode which supports 32bit registers.
    2. Slow down the input clock to TBCTR.

    I would suggest that you read the section on the Action Qualifier in this document. http://www.ti.com/lit/pdf/spruh18 

    Watching the video in my signature below may also help you to get a better understanding of the PWM module in general.

    Regards,
    Cody 

  • Hi,

    Thank you so much i will go through it and let you the status.

  • Hi, 

    I have generated three pwm's on 1,2,3.

    but,I am not receiving interupt ,I have attached the code please go through it and let me khow where i am wrong.

    Thank you

    Your faithfully 

    Mihir Dave

    //----------------------------------------------------------------------------------
    //	FILE:	DeadBandPWM-Main.c
    //			(DeadBand is applied to Up, Single Edge Asymmetric Waveform, With Independent 
    //			Modulation on EPWM2A and EPWM2B)
    //
    //	Description:	This program sets up the EV TIMER2 to generate complimentary 
    //			PWM waveforms with certain amount of dead bands .Observe
    //			the waveforms comparatively using a scope from ePWM2A and ePWM2B pins.
    
    //			-In order to change the PWM frequency, the user should change 
    //			the value of"period". 
    //			-The PWM waveforms can be re-configured by registers under 'set actions'. 
    //			-To observe other PWM pins, the related PWM clocks and GPIO MUX configuration
    //			 settings (in ePWM_Sym-DevInit_F28xxx.c)should be set properly.
    //          For further details, please search for the SPRU791.PDF (TMS320x28xx,
    //			28xxx Enhanced Pulse Width Modulator Module) at ti.com.
    //
    //  Target:  		TMS320F2806x or TMS320F2803x families (F28069)
    //
    //----------------------------------------------------------------------------------
    //  $TI Release:$ 	V1.0
    //  $Release Date:$ 11 Jan 2010 - VSC
    //----------------------------------------------------------------------------------
    //
    // PLEASE READ - Useful notes about this Project
    
    // Although this project is made up of several files, the most important ones are:
    //	    - "DeadBandPWM.c",	this file
    //		- Application Initialization, Peripheral config
    //		- Application management
    //		- Slower background code loops and Task scheduling
    //	 "DeadBandPWM-DevInit_F28xxx.c"
    //		- Device Initialization, e.g. Clock, PLL, WD, GPIO mapping
    //		- Peripheral clock enables
    // The other files are generally used for support and defining the registers as C
    // structs. In general these files will not need to be changed.
    //   "F2806x_RAM_DeadBandPWM.CMD" or "F2806x_FLASH_DeadBandPWM.CMD"
    //		- Allocates the program and data spaces into the device's memory map.
    //   "F2806x_Headers_nonBIOS.cmd" and "F2806x_GlobalVariableDefs.c"
    //		- Allocate the register structs into data memory.  These register structs are
    //		  defined in the peripheral header includes (F2806x_Adc.h, ...) 
    //
    //----------------------------------------------------------------------------------
    
    #include "PeripheralHeaderIncludes.h"
    #include "F2806x_EPwm_defines.h" 	    // useful defines for initialization
    #include "F2806x_Examples.h"   // F2806x Examples Include File
    #include "F2806x_Device.h"     // F2806x Headerfile Include File
    #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    #include "piccolo_lcd.h"
    
    #define busvoltage 1240
    																		 
    
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    // FUNCTION PROTOTYPES
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    void DeviceInit(void);
    void InitFlash(void);
    void MemCopy(Uint16 *SourceAddr, Uint16* SourceEndAddr, Uint16* DestAddr);
    //void initpwm34();
    unsigned int VVL=0;
    //*******************************************************************************************
    void InitEPwm1Gpio(void);
    void InitEPwm2Gpio(void);
    void InitEPwm3Gpio(void);
    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;
    
    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*);
    unsigned int jooj=0;
    
    // 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
    //********************************************************************************************
    
    
    
    
    //#define DELAY_US(A)  DSP28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L)
    
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    // MAIN CODE - starts here
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    void main(void)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    {
    
    //=================================
    //	INITIALISATION - General
    //=================================
    
    	DeviceInit();	// Device Life support & GPIO mux settings
    
    
    // Only used if running from FLASH
    // Note that the variable FLASH is defined by the compiler (-d FLASH)
    #ifdef FLASH		
    // Copy time critical code and Flash setup code to RAM
    // The  RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
    // symbols are created by the linker. Refer to the linker files. 
    	MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
    
    // Call Flash Initialization to setup flash wait states
    // This function must reside in RAM vcxz
    	InitFlash();	// Call the flash wrapper init function
    #endif //(FLASH)
    
    
    	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 F2806x_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 F2806x_DefaultIsr.c.
    	// This function is found in F2806x_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 register
    	   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
    
    
    	   EALLOW;
    	      SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
    	      EDIS;
    
    	      InitEPwm1Example();
    	      DELAY_US(500);
    	      InitEPwm2Example();
    	      DELAY_US(500);
    	      InitEPwm3Example();
    
    	      EALLOW;
    	      SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
    	      EDIS;
    
    	// Step 4. Initialize all the Device Peripherals:
    	// This function is found in F2806x_InitPeripherals.c
    	// InitPeripherals(); // Not required for this example
    
    
    	// Step 5. User specific code, enable interrupts:
    
    	// Enable ADCINT1 in PIE
    	      PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
    	         PieCtrlRegs.PIEIER3.bit.INTx2 = 1;
    	         PieCtrlRegs.PIEIER3.bit.INTx3 = 1;
    	   IER |=M_INT3; 						// Enable CPU Interrupt 1
    	   EINT;          						// Enable Global interrupt INTM
    	   ERTM;          						// Enable Global realtime interrupt DBGM
    	   while(1)
    	      {
    	       VVL=EPwm1Regs.TBCTR;
    	       jooj=VVL;
    	       if(jooj<40000){
    
    
    	           GpioDataRegs.GPBSET.bit.GPIO58 = 1;
    
    
    
    	       }else{
    	           EALLOW;
    	           GpioDataRegs.GPBCLEAR.bit.GPIO58 = 1;
    
    
    	       }
    
    
    
    	      }
    
    
    
    
    
    }
    
    
    
    
    __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 = 0xFFFF;       // 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 = 0x00;   // Clock ratio to SYSCLKOUT
       EPwm1Regs.TBCTL.bit.CLKDIV = 0x04;
    
       // 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 = 0xFFFE;      // Setup min/max CMPA/CMPB values
       epwm1_info.EPwmMinCMPA = 0x50;
       epwm1_info.EPwmMaxCMPB = 0xFFFE;
       epwm1_info.EPwmMinCMPB = 0x50;
    
    }
    
    void InitEPwm2Example()
    {
       // Setup TBCLK
       EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
       EPwm2Regs.TBPRD =0xFFFF;       // 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 = 0x00;   // Clock ratio to SYSCLKOUT
       EPwm2Regs.TBCTL.bit.CLKDIV = 0x05;
    
       // 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 = 0xFFFE;         // Setup min/max CMPA/CMPB values
       epwm2_info.EPwmMinCMPA = 0x50;
       epwm2_info.EPwmMaxCMPB = 0xFFFE;
       epwm2_info.EPwmMinCMPB = 0x50;
    
    }
    
    void InitEPwm3Example()
    {
    
    
       // Setup TBCLK
       EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
       EPwm3Regs.TBPRD = 0xFFFF;       // 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 = 0x00;   // Clock ratio to SYSCLKOUT
       EPwm3Regs.TBCTL.bit.CLKDIV = 0x06;
    
       // 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 = 0xFFFE;
       epwm3_info.EPwmMinCMPA = 0x50;
       epwm3_info.EPwmMaxCMPB = 0xFFFE;
       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;
    }
    
    
    

  • Mihir,

    In a nut shell:

    1. Setup the interrupt vector table
    2. Configure the PIE
    3. Enable the PWM interrupts you wish to use
    4. Enable global interrupts
    5. After receiving an interrupt you need to acknowledge it

    The following workshop covers this in more detail.

    https://training.ti.com/c2000-f2806x-microcontroller-workshop?cu=1137791

    If you would like to understand the interrupt vectors on this device you should look at the TRM and it discusses this topic at length.

    Regards,
    Cody 

  • Hi,

    Thank you ,I will try that and revert you back with result.

  • Mihir,

    have you had any luck?

    Thanks,
    Cody