PebbleOS
Loading...
Searching...
No Matches
Functions

Pulse-width modulation outputs. More...

Functions

void pwm_init (const PwmConfig *pwm, uint32_t resolution, uint32_t frequency)
 Initialize a PWM channel.
 
void pwm_set_duty_cycle (const PwmConfig *pwm, uint32_t duty_cycle)
 Set the duty cycle.
 
void pwm_enable (const PwmConfig *pwm, bool enable)
 Start or stop the output.
 

Detailed Description

Pulse-width modulation outputs.

A channel is described by a board-defined PwmConfig. The period is resolution counts of a counter running at frequency, so the output frequency is frequency / resolution.

// 256 Hz output with 1024 steps
pwm_init(&BACKLIGHT_PWM.pwm, 1024, 1024 * 256);
pwm_enable(&BACKLIGHT_PWM.pwm, true);
pwm_set_duty_cycle(&BACKLIGHT_PWM.pwm, 512);
void pwm_enable(const PwmConfig *pwm, bool enable)
Start or stop the output.
void pwm_init(const PwmConfig *pwm, uint32_t resolution, uint32_t frequency)
Initialize a PWM channel.
void pwm_set_duty_cycle(const PwmConfig *pwm, uint32_t duty_cycle)
Set the duty cycle.

Function Documentation

◆ pwm_enable()

void pwm_enable ( const PwmConfig *  pwm,
bool  enable 
)

Start or stop the output.

Parameters
pwmChannel.
enabletrue to start, false to stop.

◆ pwm_init()

void pwm_init ( const PwmConfig *  pwm,
uint32_t  resolution,
uint32_t  frequency 
)

Initialize a PWM channel.

Parameters
pwmChannel.
resolutionCounts per period; duty cycles range from 0 to this value.
frequencyCounter frequency in Hz.

◆ pwm_set_duty_cycle()

void pwm_set_duty_cycle ( const PwmConfig *  pwm,
uint32_t  duty_cycle 
)

Set the duty cycle.

The channel must be enabled first.

Parameters
pwmChannel.
duty_cycleHigh time in counts, 0 to the resolution given to pwm_init().