PWM Driver interface provides functionality to control frequency and duty of pulse-width modulation (PWM) signal.
To use this library
PWM driver controls underlying timer or dedicated hardware of a microcontroller to generate a PWM signal. User can configure signal frequency, duty cycle, output pin and channel.
In order to initialize the PWM driver, user must call the
before any other. It is required to specify signal frequency and output pin.
Example initialization procedure is shown below:
pwm_t pwm; pwm_config_t pwm_cfg; pwm_configure_default( &pwm_cfg ); pwm_cfg.pin = PA11; pwm_cfg.freq_hz = 1000; pwm_open( &pwm, &pwm_cfg );
The driver provides two functions:
pwm_stop() for enabling
and disabling PWM signal generation, respectively. To change duty cycle, user
can use the
Example procedure of controlling a PWM signal:
pwm_set_freq( &pwm, pwm_cfg.freq_hz ); pwm_start( &pwm ); pwm_set_duty( &pwm, 0.5 ); // 50% duty