MCPWM DMA Transfer
Brief
DMA table-mode transfer to MCPWM compare shadow registers with internal verification
Details
This example demonstrates DMA table-mode transfers to two independent MCPWM instances, with internal verification of both the compare register values and DMA trigger timing.
Each MCPWM instance has its own DMA channel triggered by its own SOCA event:
APP_DMA_CH0 writes 6 compare shadow registers of APP_MCPWM0 (CMPA/CMPB for PWM1, PWM2, PWM3)
APP_DMA_CH1 writes 6 compare shadow registers of APP_MCPWM1 (CMPA/CMPB for PWM1, PWM2, PWM3)
Both DMA channels share the DMA0 interrupt vector. Inside the ISR, per-channel flags are checked and each instance is validated independently.
Sequence
Main function builds DMA tables, initializes channel status, enables Time Base clock
DMA tables are built from compare config arrays
Each table entry is a (destination_address, value) pair - DMA table mode writes each value to its corresponding compare shadow register address
4 compare configurations are preloaded, cycled through on each DMA transfer
DMA transfers on each SOCA event
SOCA fires every 3rd PWM period (APP_SOCA_EVENT_PERIOD = 3)
Each SOCA trigger causes DMA to burst-write 6 compare shadow registers
New compare values take effect on the next PWM period boundary (shadow -> active)
DMA ISR validates and re-arms
Reads back active compare register values from the MCPWM instance
Timestamps each ISR using Arch_Counter to measure DMA trigger intervals
Advances to next configuration (modulo 4) and re-arms the DMA channel
Main loop waits for both channels to complete all 20 validation steps
Post-validation evaluates results
Compare values: exact match between expected and actual active register values
Timing intervals: measured DMA trigger interval vs. expected (PRD x SOCA prescale)
Compare Configurations (4 sets, cycled through):
Config P1A P1B P2A P2B P3A P3B
0 7500 3000 7000 2800 6500 2600
1 7000 2800 6500 2600 6000 2400
2 6500 2600 6000 2400 5500 2200
3 6000 2400 5500 2200 5000 2000
Test Cases:
Validation Steps: 20 per channel
Configurations: 4 compare sets cycled (step modulo 4)
SOCA Event Prescale: 3 (DMA triggered every 3rd PWM period)
Timing Tolerance: +/-5% error allowed
Validation:
Compare Error: Active compare register values must exactly match DMA-written values
Timing Error: DMA trigger interval within +/-5% of expected (PRD x SOCA prescale)
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 per channel
Peripherals used
MCPWM
Instance : APP_MCPWM0
Channels Enabled: 1A,1B,2A,2B,3A,3B
Time Base
TB Clk : 250MHz
Counter Mode : UpCount
PRD : 8000. Freq: 31.25KHz
PWM 1
CMPA (initial): 7200 cycles / 90%%
CMPB (initial): 7200 cycles / 90%%
Actions 1A : High on Zero. Low on CMPA hit
Actions 1B : High on Zero. Low on CMPB hit
PWM 2
CMPA (initial): 6400 cycles / 80%%
CMPB (initial): 6400 cycles / 80%%
Actions 2A : High on Zero. Low on CMPA hit
Actions 2B : High on Zero. Low on CMPB hit
PWM 3
CMPA (initial): 6000 cycles / 75%%
CMPB (initial): 6000 cycles / 75%%
Actions 3A : High on Zero. Low on CMPA hit
Actions 3B : High on Zero. Low on CMPB hit
Deadband : Unused
TripZone : Unused
Event Trigger
SOCA Source : Ctr=Zero event
SOCA Period : Every 3 events (set in app)
Instance : APP_MCPWM1
Channels Enabled: 1A,1B,2A,2B,3A,3B
Time Base
TB Clk : 250MHz
Counter Mode : UpCount
PRD : 8000. Freq: 31.25KHz
PWM 1
CMPA (initial): 7200 cycles / 90%%
CMPB (initial): 7200 cycles / 90%%
Actions 1A : High on Zero. Low on CMPA hit
Actions 1B : High on Zero. Low on CMPB hit
PWM 2
CMPA (initial): 6400 cycles / 80%%
CMPB (initial): 6400 cycles / 80%%
Actions 2A : High on Zero. Low on CMPA hit
Actions 2B : High on Zero. Low on CMPB hit
PWM 3
CMPA (initial): 6000 cycles / 75%%
CMPB (initial): 6000 cycles / 75%%
Actions 3A : High on Zero. Low on CMPA hit
Actions 3B : High on Zero. Low on CMPB hit
Deadband : Unused
TripZone : Unused
Event Trigger
SOCA Source : Ctr=Zero event
SOCA Period : Every 3 events (set in app)
DMA
Instance : APP_DMA_CH0
Mode : Table
Table size : 6
Src Addr Inc: Increment
Trigger : PWM0_SOCA
Interrupt : Enabled
Instance : APP_DMA_CH1
Mode : Table
Table size : 6
Src Addr Inc: Increment
Trigger : PWM4_SOCA
Interrupt : Enabled
GPIO
2 GPIOs connected to LEDs.
SoC
SYSCTL
TBCLK : Disabled. To be enabled in app
INTERRUPTS
Instance : DMA0_INT
Source : DMA
Handler : DMA0_INT_Handler
Priority: Default
External connections
No external connections required. Optionally, monitor 12 MCPWM channels on scope/logic analyzer
Connect: BoosterPack header J4 pin 31 (APP_MCPWM0_1A) to Scope/Logic analyzer
Connect: BoosterPack header J4 pin 32 (APP_MCPWM0_1B) to Scope/Logic analyzer
Connect: BoosterPack header J4 pin 3 (APP_MCPWM0_2A) to Scope/Logic analyzer
Connect: BoosterPack header J4 pin 23 (APP_MCPWM0_2B) to Scope/Logic analyzer
Connect: BoosterPack header J4 pin 4 (APP_MCPWM0_3A) to Scope/Logic analyzer
Connect: BoosterPack header J4 pin 26 (APP_MCPWM0_3B) to Scope/Logic analyzer
Connect: BoosterPack header J4 pin 40 (APP_MCPWM1_1A) to Scope/Logic analyzer
Connect: BoosterPack header J4 pin 39 (APP_MCPWM1_1B) to Scope/Logic analyzer
Connect: BoosterPack header J4 pin 38 (APP_MCPWM1_2A) to Scope/Logic analyzer
Connect: BoosterPack header J4 pin 37 (APP_MCPWM1_2B) to Scope/Logic analyzer
Connect: BoosterPack header J4 pin 36 (APP_MCPWM1_3A) to Scope/Logic analyzer
Connect: BoosterPack header J4 pin 35 (APP_MCPWM1_3B) to Scope/Logic analyzer
LED Details: PASS LED (LED5), FAIL LED (LED4)
Connect: HSEC PIN 80 (PA11) (APP_MCPWM0_1A) to Scope/Logic analyzer
Connect: HSEC PIN 82 (PA12) (APP_MCPWM0_1B) to Scope/Logic analyzer
Connect: HSEC PIN 34 (PA9) (APP_MCPWM0_2A) to Scope/Logic analyzer
Connect: HSEC PIN 21 (PA16) (APP_MCPWM0_2B) to Scope/Logic analyzer
Connect: HSEC PIN 94 (PC13) (APP_MCPWM0_3A) to Scope/Logic analyzer
Connect: HSEC PIN 23 (PA17) (APP_MCPWM0_3B) to Scope/Logic analyzer
Connect: HSEC PIN 58 (PB3) (APP_MCPWM1_1A) to Scope/Logic analyzer
Connect: HSEC PIN 12 (PA7) (APP_MCPWM1_1B) to Scope/Logic analyzer
Connect: HSEC PIN 30 (PA8) (APP_MCPWM1_2A) to Scope/Logic analyzer
Connect: HSEC PIN 85 (PA22) (APP_MCPWM1_2B) to Scope/Logic analyzer
Connect: HSEC PIN 53 (PB2) (APP_MCPWM1_3A) to Scope/Logic analyzer
Connect: HSEC PIN 71 (PA25) (APP_MCPWM1_3B) to Scope/Logic analyzer
LED Details: PASS LED (D4), FAIL LED (D3)