CCS News

TECH NOTE: Power PWM

Friday 10 February, 2023

These options lets the user configure the Pulse Width Modulation (PWM) pins. They are only available on devices equipped with PWM. The options for these functions vary depending on the chip and are listed in the device header file.

Relevant Functions:

  • setup_power_pwm(config) - Sets up the PWM clock, period, dead time etc.
  • setup_power_pwm_pins(module x) - Configure the pins of the PWM to be in Complementary, ON or OFF mod.
  • set_power_pwmx_duty(duty) - Stores the value of the duty cycle in the PDCXL/H register. This duty cycle value is the time for which the PWM is in active state.
  • set_power_pwm_override(pwm,override,value) - This function determines whether the OVDCONS or the PDC registers determine the PWM output.

Relevant Preprocessor:
None

Relevant Interrupts:
  • #INT_PWMTB - PWM Timebase Interrupt (Only available on PIC18XX31)

Relevant Include Files:
None, all functions are built-in

Relevant getenv() Parameters:
None

Example Code:
....
long duty_cycle, period;
...
// Configures PWM pins to be ON,OFF or in
// Complimentary mode.
setup_power_pwm_pins(PWM_COMPLEMENTARY ,PWM_OFF, PWM_OFF, PWM_OFF_;
// Sets up PWM clock , postscale and period. Here
// Here period is used to set the PWM Frequency as follows
// Frequency=Fosc/(4* (period+1)*postcae)
// *postscale)

setup_power_pwm(PWM_CLOCK_DIV_4|PWM_FREE_RUN,1,0,period,0,1,0);

set_power_pwm0_duty(duty_cycle)); // Sets the duty cycle of the PWM 0,1 in
// Complementary mode