BeRTOS
|
With this driver you can control a device with multiple PWM channels. More...
Data Structures | |
struct | Pwm |
PWM context structure. More... | |
Enumerations | |
enum | PwmPolarity { PWM_POL_HIGH_PULSE, PWM_POL_POSITIVE = PWM_POL_HIGH_PULSE, PWM_POL_LOW_PULSE, PWM_POL_NEGATIVE = PWM_POL_LOW_PULSE } |
Enum describing PWM polarities. More... | |
Functions | |
void | pwm_setDuty (Pwm *ctx, pwm_duty_t duty) |
Set the duty cycle of the PWM channel linked to ctx . | |
void | pwm_setFrequency (Pwm *ctx, pwm_freq_t freq) |
Set PWM frequency of channel linked to ctx . | |
void | pwm_setPolarity (Pwm *ctx, PwmPolarity pol) |
Set PWM polarity of pwm channel linked to ctx . | |
void | pwm_enable (Pwm *ctx, bool state) |
Enable/Disable the pwm channel linked to ctx . | |
void | pwm_init (Pwm *ctx, unsigned channel) |
Initialize PWM driver. |
With this driver you can control a device with multiple PWM channels.
You can enable/disable each channel indipendently and also set frequency and duty cycle.
API usage example:
Pwm pwm; // declare a context structure pwm_init(&pwm, 0); // init pwm channel 0 pwm_setFrequency(&pwm, 1000); // Set frequency of channel 0 to 1000Hz pwm_setDuty(&pwm, 0x7FFF); // Set duty to 50% (0xFFFF/2) pwm_enable(&pwm, true); // Activate the output
enum PwmPolarity |
Enum describing PWM polarities.
void pwm_enable | ( | Pwm * | ctx, |
bool | enable | ||
) |
Enable/Disable the pwm channel linked to ctx
.
The modification will be applied to the channel immediatly.
ctx | PWM channel context. |
enable | if true the channel will be enabled, if false will be disabled. |
void pwm_init | ( | Pwm * | ctx, |
unsigned | channel | ||
) |
void pwm_setDuty | ( | Pwm * | ctx, |
pwm_duty_t | duty | ||
) |
Set the duty cycle of the PWM channel linked to ctx
.
The modification will be applied to the channel immediatly. The current frequency of the channel will be maintained.
ctx | PWM channel context. |
duty | the new duty cycle value. |
void pwm_setFrequency | ( | Pwm * | ctx, |
pwm_freq_t | freq | ||
) |
Set PWM frequency of channel linked to ctx
.
The modification will be applied to the channel immediatly. The duty cycle of the channel will be maintained.
ctx | PWM channel context. |
freq | the new frequency of the signal, in Hz. |
void pwm_setPolarity | ( | Pwm * | ctx, |
PwmPolarity | pol | ||
) |
Set PWM polarity of pwm channel linked to ctx
.
The modification will be applied to the channel immediatly.
ctx | PWM channel context. |
pol | the new polarity of the signal. |