High level interface for interacting with the pulse width modulator (PWM) hardware resource.
The PWM driver can be used to generate periodic digital waveforms with configurable frequency and duty cycle. The driver allows assigning the PWM output and an optional inverted output to supplied pins. The driver supports interrupt generation on PWM terminal count and compare events.
See Snippet 1: Simple PWM initialization and output to pin for a code snippet that generates a signal with the specified frequency and duty cycle on the specified pin.
The clock parameter clk is optional and need not be provided (NULL), to generate and use an available clock resource with a default frequency.
The clock frequency and the duty cycle is set using mtb_hal_pwm_set_period.
mtb_hal_pwm_start starts the PWM output on the pin.
mtb_hal_pwm_start and mtb_hal_pwm_stop functions can be used after PWM initialization to start and stop the PWM output.
API Reference | |
PWM HAL Results | |
PWM specific return codes. | |
Functions | |
cy_rslt_t | mtb_hal_pwm_setup (mtb_hal_pwm_t *obj, const mtb_hal_pwm_configurator_t *config, const mtb_hal_clock_t *clock) |
Sets up a HAL instance to use the specified hardware resource. More... | |
cy_rslt_t | mtb_hal_pwm_set_period (mtb_hal_pwm_t *obj, uint32_t period_us, uint32_t pulse_width_us) |
Set the number of microseconds for the PWM period & pulse width. More... | |
cy_rslt_t | mtb_hal_pwm_start (mtb_hal_pwm_t *obj) |
Starts the PWM generation and outputs on pin and compl_pin. More... | |
cy_rslt_t | mtb_hal_pwm_stop (mtb_hal_pwm_t *obj) |
Stops the PWM generation and outputs on pin and compl_pin. More... | |
cy_rslt_t mtb_hal_pwm_setup | ( | mtb_hal_pwm_t * | obj, |
const mtb_hal_pwm_configurator_t * | config, | ||
const mtb_hal_clock_t * | clock | ||
) |
Sets up a HAL instance to use the specified hardware resource.
This hardware resource must have already been configured via the PDL.
[out] | obj | The HAL driver instance object. The caller must allocate the memory for this object, but the HAL will initialize its contents |
[in] | config | The configurator-generated HAL config structure for this peripheral instance |
[in] | clock | The HAL clock object that is connected to this peripheral instance |
cy_rslt_t mtb_hal_pwm_set_period | ( | mtb_hal_pwm_t * | obj, |
uint32_t | period_us, | ||
uint32_t | pulse_width_us | ||
) |
Set the number of microseconds for the PWM period & pulse width.
[in] | obj | The PWM object |
[in] | period_us | The period in microseconds |
[in] | pulse_width_us | The pulse width in microseconds |
cy_rslt_t mtb_hal_pwm_start | ( | mtb_hal_pwm_t * | obj | ) |
Starts the PWM generation and outputs on pin and compl_pin.
[in] | obj | The PWM object |
cy_rslt_t mtb_hal_pwm_stop | ( | mtb_hal_pwm_t * | obj | ) |
Stops the PWM generation and outputs on pin and compl_pin.
[in] | obj | The PWM object |