EPWM HRDUTY
Brief
EPWM generation and HR modulation
Details
This example demonstrates EPWM high-resolution (HRPWM) duty cycle generation using the EPWM peripheral, with internal verification. The example generates an EPWM signal on channels 1A and 1B, sweeps the CMPAHR high-resolution compare value, and measures the resulting on-time using HRCAP (High-Resolution Capture) to verify accuracy beyond the coarse TBCLK period.
Sequence
Main function runs HRPWM SFO (Scale Factor Optimizer) calibration once at startup
Main function runs HRCAP calibration once at startup, continuously retried on overflow
Main function enables Time Base clock for EPWM
Main loop advances to next sweep step
Updates a shared variable (App_Status.currentTestCase) to advance to the next CMPAHR value
Waits sufficient settling time for modulation and measurement to complete
EPWM modulates
EPWM4_IRQHandler fires at start of PWM period, snapshots the shared variable and updates CMPAHR
HRCAP measures
APP_ECAP_PWMA_CAPTURE_INT_Handler fires at event 3 (rising-falling-rising), calculates on-time/period
Snapshots the shared variable. Populates the test status array with measured values
Main loop verifies the result
Compares measured vs expected on-time
Signal Routing:
The PWM output is internally looped back to the ECAP module. PWM4 1A -> Internal loopback -> GPIO -> INPUTXBAR -> ECAP (HRCAP2)
Observe EPWM4 1A and 1B on the scope: 1A carries the HRPWM (CMPAHR) sweep, 1B does not
Test Cases:
Steps: 25 CMPAHR sweep steps
Sweep: CMPAHR from 0 to 240 in steps of 10
Fixed Frequency: 100 kHz throughout all tests
Tolerance: +/-3% error allowed
Peripherals used
EPWM
Instance : EPWM4
Channel Enabled : 1A, 1B
Time Base
TB Clk : 250MHz
Counter Mode : UpCount
PRD (initial) : 2499. Freq: 100KHz
CMPA (initial) : 624 cycles / 25%%
Actions 1A : High on Zero. Low on CMPA hit
HRPWM (1A)
SFO Calibration : Run once at startup, MEP scale factor written to HRMSTEP
Deadband : Unused
TripZone : Unused
Interrupt
Source : Ctr=Zero event
Period : Every 1 event
ECAP
Instance : APP_ECAP_PWMA_CAPTURE
Input : APP_INPUTXBAR
Mode : Capture
Clk : 250MHz
Edges : R F R
Interrupt : On event3
INPUTXBAR
Instance : APP_INPUTXBAR
Src : GPIO - of EPWM4 1A
Dest : ECAP - APP_ECAP_PWMA_CAPTURE
SoC
SYSCTL
TBCLK : Disabled. To be enabled in app
INTERRUPTS
Instance : APP_ECAP_PWMA_CAPTURE_INT
Source : ECAP
Handler : APP_ECAP_PWMA_CAPTURE_INT_Handler
Priority: Default
Instance : EPWM4_INT
Source : EPWM4
Handler : EPWM4_IRQHandler
Priority: Default
Instance : HRCAP2_INT
Source : HRCAP2 calibration done/overflow
Handler : HRCAP2_IRQHandler
Priority: Default
External connections
Monitor EPWM4 channel 1A and 1B on scope/logic analyzer
Connect: BoosterPack header J1 pin 6 (EPWM4_1A) to Scope/Logic analyzer
Connect: BoosterPack header J1 pin 7 (EPWM4_1B) to Scope/Logic analyzer
LED Details: PASS LED (LED8), FAIL LED (LED7)