EPWM Basic PWM Generation
Brief
EPWM generation and modulation
Details
This example demonstrates EPWM generation and modulation using the EPWM peripheral, with internal verification. The example generates EPWM signal on channel 1A, modulates the duty cycle and measures the output using ECAP (Enhanced Capture module) to verify accuracy.
Sequence
Main function enables Time Base clock for EPWM
Lets the channel of PWM to get generated for few seconds
Main loop advances to next test case
Updates a shared variable (App_Status.currentTestCase) to advance to next test case
Waits few seconds (sufficient settling time) for modulation and measurement to complete
EPWM modulates
EPWM ISR handler fires at start of PWM period, snapshots the shared variable and modulates the PWM
Uses shadow registers to ensure glitch-free updates.
New values take effect on next PWM period boundary
ECAP measures
ECAP ISR handler fires at event 3 (rising-falling-rising), calculates period and duty
Snapshots the shared variable. Populates the test status array with measured values
Main loop verifies the result
Compares measured vs set period and duty
Signal Routing:
The PWM output is internally looped back to the ECAP module. PWM1A -> Internal loopback -> GPIO -> INPUTXBAR -> ECAP
Test Cases:
Steps: 20 modulation steps
Duty Cycle Sweep: From 5% (APP_DUTY_MIN) to 95% (APP_DUTY_MAX)
Fixed Frequency: 100 kHz throughout all tests
Tolerance: ±3% error allowed
Validation:
Period Error: Measured vs. set period within ±3%
Duty Cycle Error: Measured vs. set duty within ±3%
Status Indicators:
PASS LED turns on if no errors
FAIL LED turns on if errors detected
Detailed log shows results for all 20 test cases
Peripherals used
EPWM
Instance : EPWM4
Channel Enabled : 1A
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
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
External connections
Monitor EPWM4 channel 1A on scope/logic analyzer
Connect: BoosterPack header J1 pin 6 (EPWM4_1A) to Scope/Logic analyzer
LED Details: PASS LED (LED8), FAIL LED (LED7)