PWM API
[PWM driver]
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. | |
Detailed Description
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
Enumeration Type Documentation
| enum PwmPolarity |
Enum describing PWM polarities.
- Enumerator:
Function Documentation
| void pwm_enable | ( | Pwm * | ctx, | |
| bool | enable | |||
| ) |
Enable/Disable the pwm channel linked to ctx.
The modification will be applied to the channel immediatly.
- Parameters:
-
ctx PWM channel context. enable if true the channel will be enabled, if false will be disabled.
- Note:
- When a PWM channel is disabled, the output level will be the same as if the duty would be set to 0%. So, if current polarity is positive, a disabled channel will be low, if polarity is negative will be high.
- See also:
- pwm_setPolarity
| 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.
- Parameters:
-
ctx PWM channel context. duty the new duty cycle value.
- See also:
- pwm_duty_t
| 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.
- Parameters:
-
ctx PWM channel context. freq the new frequency of the signal, in Hz.
- Note:
- Depending on the hardware implementation, this function may generate a glitch in the output signal upon frequency changing.
| 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.
- Parameters:
-
ctx PWM channel context. pol the new polarity of the signal.
- Note:
- if a channel is disabled, changing its polarity will change the current steady output level.
- See also:
- pwm_enable
- PwmPolarity
