File syn_pwm.h¶
FileList > drivers > syn_pwm.h
Go to the source code of this file
Hardware PWM (Pulse Width Modulation) driver. More...
#include "../common/syn_defs.h"#include "../port/syn_port_pwm.h"#include <stdbool.h>#include <stdint.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_PWM PWM channel handle. Caller allocates; zero heap. |
Public Functions¶
| Type | Name |
|---|---|
| SYN_Status | syn_pwm_enable (const SYN_PWM * pwm, bool enable) Enable or disable the PWM output. |
| SYN_Status | syn_pwm_init (SYN_PWM * pwm, uint8_t channel, uint32_t freq_hz) Initialize a hardware PWM channel. |
| SYN_Status | syn_pwm_set_duty (const SYN_PWM * pwm, uint8_t duty_pct) Set the PWM duty cycle as a percentage (0–100%). |
| SYN_Status | syn_pwm_set_duty_raw (const SYN_PWM * pwm, uint16_t duty_u16) Set the PWM duty cycle with 16-bit raw resolution (0–65535). |
| SYN_Status | syn_pwm_set_freq (SYN_PWM * pwm, uint32_t freq_hz) Change the PWM frequency at runtime. |
Detailed Description¶
Provides a high-level, object-oriented wrapper around the platform's hardware PWM port interface (syn_port_pwm.h). Mirrors the pattern of syn_dac.h.
Usage:
SYN_PWM pwm;
syn_pwm_init(&pwm, 0, 1000); // Channel 0 @ 1 kHz
syn_pwm_set_duty(&pwm, 75); // 75% duty cycle
syn_pwm_enable(&pwm, true);
Public Functions Documentation¶
function syn_pwm_enable¶
Enable or disable the PWM output.
Parameters:
pwmInitialized PWM handle.enabletrue to enable, false to disable.
Returns:
SYN_OK on success, SYN_INVALID_PARAM if handle is invalid.
function syn_pwm_init¶
Initialize a hardware PWM channel.
Parameters:
pwmHandle to initialize. Must not be NULL.channelPlatform PWM channel index.freq_hzDesired PWM frequency in Hz (must be > 0).
Returns:
SYN_OK on success, SYN_INVALID_PARAM or SYN_ERROR on failure.
function syn_pwm_set_duty¶
Set the PWM duty cycle as a percentage (0–100%).
Parameters:
pwmInitialized PWM handle.duty_pctDuty cycle percentage (0 = 0%, 100 = 100%).
Returns:
SYN_OK on success, SYN_INVALID_PARAM if handle is invalid.
function syn_pwm_set_duty_raw¶
Set the PWM duty cycle with 16-bit raw resolution (0–65535).
Parameters:
pwmInitialized PWM handle.duty_u1616-bit duty value (0 = off, 65535 = 100%).
Returns:
SYN_OK on success, SYN_INVALID_PARAM if handle is invalid.
function syn_pwm_set_freq¶
Change the PWM frequency at runtime.
Parameters:
pwmInitialized PWM handle.freq_hzNew frequency in Hz (must be > 0).
Returns:
SYN_OK on success, SYN_INVALID_PARAM if handle is invalid.
The documentation for this class was generated from the following file src/syntropic/drivers/syn_pwm.h