shows the Initialization code. The first part is configured for conventional PWM. The second part
sets up the HRPWM resources.
Example 4-4. PWM DAC Function Initialization Code
void HrPwmDacDrvCnf(void)
{
// Config for conventional PWM first
EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE; // Set Immediate load
EPwm1Regs.TBPRD = 150; // Period set for 533 kHz PWM
hrDAC_period = 150; // Used for Q15 to Q0 scaling
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // EPWM1 is the Master
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
// Note: ChB is initialized here only for comparison purposes, it is not required
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; // optional
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW; // optional
EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;
EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;
EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET; // optional
EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR; // optional
// Now configure the HRPWM resources
EALLOW; // Note these registers are protected
// and act only on ChA.
EPwm1Regs.HRCNFG.all = 0x0; // Clear all bits first
EPwm1Regs.HRCNFG.bit.EDGMODE = HR_FEP; // Control falling edge position
EPwm1Regs.HRCNFG.bit.CTLMODE = HR_CMP; // CMPAHR controls the MEP.
EPwm1Regs.HRCNFG.bit.HRLOAD = HR_CTR_ZERO; // Shadow load on CTR=Zero.
EDIS;
MEP_ScaleFactor = 83*256; // Start with typical Scale Factor
// value for 80 MHz.
// Use SFO functions to update MEP_ScaleFactor
// dynamically.
}
shows an assembly example of run-time code that can execute in a high-speed ISR loop.
Example 4-5. PWM DAC Function Run-Time Code
EPWM1_BASE .set 0x6800
CMPAHR1 .set EPW0x8
;=================================================
HRPWM_DAC_DRV; (can execute within an ISR or loop)
;=================================================
MOVW DP, #_HRDAC_In
MOVL XAR2,@_HRDAC_In ; Pointer to input Q15 duty (XAR2)
MOVL XAR3,#CMPAHR1 ; Pointer to HRPWM CMPA reg (XAR3)
; Output for EPWM1A (HRPWM
MOV T,*XAR2 ; T <= duty
MPY ACC,T,@_hrDAC_period ; Q15 to Q0 scaling based on period
ADD ACC,@_HrDAC_period<<15 ; Offset for bipolar operation
MOV T,@_MEP_ScaleFactor ; MEP scale factor (from optimizer s/w)
MPYU P,T,@AL ; P <= T * AL, optimizer scaling
MOVH @AL,P ; AL <= P, move result back to ACC
ADD ACC, #0x080 ; MEP range and rounding adjustment
MOVL *XAR3,ACC ; CMPA:CMPAHR(31:8) <= ACC
; Output for EPWM1B (Regular Res) Optional - for comparison purpose only
MOV *+XAR3[2],AH ; Store ACCH to regular CMPB
High-Resolution Pulse Width Modulator (HRPWM)
396
TMS320x2806x Microcontrollers
SPRUH18I – JANUARY 2011 – REVISED JUNE 2022
Copyright © 2022 Texas Instruments Incorporated
Summary of Contents for TMS320 2806 Series
Page 2: ......