SLAAEC5 September   2024

 

  1.   1
  2. Description
  3. Required Peripherals
  4. Compatible Devices
  5. Design Steps
  6. Design Considerations
  7. Software Flow Chart
  8. Application Code
  9. Results
  10. Additional Resources
  11. 10E2E
  12. 11Trademarks

Application Code

This application makes use of the TI System Configuration tool (SysConfig) graphical interface to generate the configuration code for the device peripherals. Using a graphical interface to configure the device peripherals streamlines the application prototyping process.

This example application code uses an array of 128 samples to continuously change the duty cycle of a single PWM output. This creates a sinusoidal wave after filtering. The duty cycle is changed through timer interrupt and shadow registers. The interrupt is generated on a counter compare down event. During this interrupt, the next counter compare value in the array index is set and ready to be loaded on the next TIMCLK cycle after the timer reaches zero. This helps prevent the application from missing any PWM duty cycle changes, which can cause glitches in the final output.

void PWM_0_INST_IRQHandler(void){
    switch (DL_TimerG_getPendingInterrupt(PWM_0_INST)){
        case DL_TIMERG_IIDX_CC0_DN: /* Interrupt on CC0 Down Event */
            /*Set new Duty Cycle based on sine array sample value */
            DL_TimerG_setCaptureCompareValue(PWM_0_INST, gSine128[gSineCounter%128],
                DL_TIMER_CC_0_INDEX);

            /* Increment gSineCounter value */
            gSineCounter++;

            break;
        default:
            break;
    }
}