Applications to Power Topologies
769
SPRUHE8E – October 2012 – Revised November 2019
Copyright © 2012–2019, Texas Instruments Incorporated
C28 Enhanced Pulse Width Modulator (ePWM) Module
Example 7-15. Code Snippet for Configuration in
//=====================================================================
// Config
//===================================================================== //
Initialization Time
//======================== //
EPWMxA & EPWMxB config
EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;
// Set immediate load
EPwm1Regs.TBPRD = period;
// PWM frequency = 1 / period
EPwm1Regs.CMPA.half.CMPA = period/2;
// Set duty as 50%
EPwm1Regs.CMPB = period/4;
// Set duty as 25%
EPwm1Regs.TBPHS.half.TBPHS = 0;
// Set as master, phase =0
EPwm1Regs.TBCTR = 0;
// Time base counter =0
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
// Count-
up mode: used for asymmetric PWM
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;
// Disable phase loading
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;
// Used to sync EPWM(n+1) "down-
stream"
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
// Set the clock rate
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
// Set the clock rate
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_PRD;
// Load on CTR=PRD
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_PRD;
// Load on CTR=PRD
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
// Shadow mode. Operates as a
double buffer.
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
// Shadow mode. Operates as a
double buffer.
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.CAU = AQ_SET;
// Set PWM1B on event A, up count
EPwm1Regs.AQCTLB.bit.PRD = AQ_CLEAR;
// Clear PWM1B on PRD
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
// EPWMxA is the source for both
delays
EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
// Enable Dead-band module
EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
// Active High Complementary (AHC)
EPwm1Regs.DBRED = 30;
// RED = 30 TBCLKs initially
EPwm1Regs.DBFED = 30;
// FED = 30 TBCLKs initially
// Configure TZ1 for short cct
protection EALLOW;
EPwm1Regs.TZSEL.bit.OSHT1 = 1;
// one-
shot source EPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;
// set EPWM1A to low at fault
EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;
// set EPWM1B to low at fault
instant
EPwm1Regs.TZEINT.bit.OST = 1;
// Enable TZ interrupt EDIS;
// Enable HiRes option EALLOW;
EPwm1Regs.HRCNFG.all = 0x0;
EPwm1Regs.HRCNFG.bit.EDGMODE = HR_FEP;
EPwm1Regs.HRCNFG.bit.CTLMODE = HR_CMP;
EPwm1Regs.HRCNFG.bit.HRLOAD = HR_CTR_PRD; EDIS;
// Run Time (Note: Example
execution of one run-time instant)
//============================================================
EPwm1Regs.TBPRD = period_new value;
// Update new period
EPwm1Regs.CMPA.half.CMPA= period_new value/2;
// Update new CMPA EPwm1Regs.CMPB=
period_new value/4;
// Update new CMPB
// Update new CMPB