MCPWM Basic PWM Generation

Brief

6 channel PWM generation and modulation

Details

This example demonstrates 6-channel PWM generation and modulation using the MCPWM peripheral, with internal verification. The example generates PWM signals on 6 channels (1A, 1B, 2A, 2B, 3A, 3B), modulates the duty cycle and measures one of the output using ECAP (Enhanced Capture module) to verify accuracy.

Block diagram Block diagram (pins applicable for LaunchPad)

Sequence

  • Main function enables Time Base clock for MCPWM

    • Lets the 6 channels of PWMs 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

  • MCPWM modulates

    • MCPWM ISR handler fires at start of PWM period, snapshots the shared variable and modulates all 6 PWMs

    • 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: 10 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

Output waveform

Peripherals used

MCPWM
  Instance          : APP_MCPWM
     Channels Enabled: 1A,1B,2A,2B,3A,3B

     Time Base
       TB Clk        : 250MHz
       Counter Mode  : UpCount
       PRD (initial) : 19999. Freq: 12.5KHz

     PWM 1
       CMPA (initial): 5000 cycles / 25%%
       CMPB (initial): 5000 cycles / 25%%
       Actions 1A    : High on Zero. Low on CMPA hit
       Actions 1B    : High on Zero. Low on CMPB hit
     PWM 2
       CMPA (initial): 5000 cycles / 25%%
       CMPB (initial): 5000 cycles / 25%%
       Actions 2A    : High on Zero. Low on CMPA hit
       Actions 2B    : High on Zero. Low on CMPB hit
     PWM 3
       CMPA (initial): 5000 cycles / 25%%
       CMPB (initial): 5000 cycles / 25%%
       Actions 3A    : High on Zero. Low on CMPA hit
       Actions 3B    : High on Zero. Low on CMPB hit

     Deadband        : Unused
     TripZone        : Unused
     Event Trigger
       ET1 Source    : Ctr=Zero event
       ET1 Period    : Every 1 event
       Interrupt src : ET1
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 APP_MCPWM 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  : APP_MCPWM_INT
         Source  : MCPWM
         Handler : APP_MCPWM_INT_Handler
         Priority: Default

External connections

Monitor 6 channels of APP_MCPWM on scope/logic analyzer

  • Connect: BoosterPack header J4 pin 40 (APP_MCPWM_1A) to Scope/Logic analyzer

  • Connect: BoosterPack header J4 pin 39 (APP_MCPWM_1B) to Scope/Logic analyzer

  • Connect: BoosterPack header J4 pin 38 (APP_MCPWM_2A) to Scope/Logic analyzer

  • Connect: BoosterPack header J4 pin 37 (APP_MCPWM_2B) to Scope/Logic analyzer

  • Connect: BoosterPack header J4 pin 36 (APP_MCPWM_3A) to Scope/Logic analyzer

  • Connect: BoosterPack header J4 pin 35 (APP_MCPWM_3B) to Scope/Logic analyzer

LED Details: PASS LED (LED5), FAIL LED (LED4)