PWM Asynchronous Driver

In the Pulse Width Modulation (PWM) asynchronous driver, a callback function can be registered in the driver by the application and triggered when errors and one PWM period is done.

The user can change the period or duty cycle whenever PWM is running. The function pwm_set_parameters is used to configure these two parameters. Note that these are raw register values and the parameter duty_cycle means the period of first half during one cycle, which should be not beyond the total period value.

In addition, the user can also get multiple PWM channels output from different peripherals at the same time, which is implemented more flexible by the function pointers.

Summary of the API's Functional Features

The API provides functions to:
  • Initialize and deinitialize the driver and associated hardware

  • Hookup callback handlers on errors and one PWM period

  • Enable or disable the PWM related hardware

  • Run-time control of PWM duty-cycle and period

Summary of Configuration Options

Below is a list of the main PWM parameters that can be configured in START. Many of these parameters are used by the pwm_init function when initializing the driver and underlying hardware.
  • The PWM waveform duty value

  • The PWM waveform period value

Driver Implementation Description

Limitations

The current driver doesn't support the features like recoverable, non-recoverable faults, dithering, and dead-time insertion.

Example of Usage

The following shows a simple example of using the PWM. The PWM must have been initialized by pwm_init. This initialization will configure the operation of the related PWM hardware, such as input pins, period, and duty cycle.

          /**
           * Example of using PWM_0.
           */
          void PWM_0_example(void)
          {
              pwm_set_parameters(&PWM_0, 10000, 5000);
              pwm_enable(&PWM_0);
          }
        

Dependencies

  • The peripheral which can perform waveform generation like frequency generation and pulse-width modulation, such as Timer/Counter.

  • The NVIC must be configured so that the peripheral interrupt requests are periodically serviced