File syn_soft_pwm.h¶
FileList > output > syn_soft_pwm.h
Go to the source code of this file
Software PWM on any GPIO pin. More...
#include "../common/syn_defs.h"#include "../drivers/syn_gpio.h"#include <stdbool.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_SoftPWM Software PWM channel descriptor. |
Public Functions¶
| Type | Name |
|---|---|
| void | syn_soft_pwm_init (SYN_SoftPWM * pwm, SYN_GPIO_Pin pin, uint16_t resolution) Initialize a soft PWM channel. |
| void | syn_soft_pwm_service (SYN_SoftPWM * channels, size_t count) Service an array of PWM channels in one call. |
| void | syn_soft_pwm_set_duty (SYN_SoftPWM * pwm, uint16_t duty) Set the duty cycle. |
| void | syn_soft_pwm_set_percent (SYN_SoftPWM * pwm, uint8_t percent) Set duty cycle as a percentage (0–100). |
| void | syn_soft_pwm_tick (SYN_SoftPWM * pwm) Advance the PWM phase by one tick. |
Public Static Functions¶
| Type | Name |
|---|---|
| uint16_t | syn_soft_pwm_get_duty (const SYN_SoftPWM * pwm) Get the current duty cycle value. |
Detailed Description¶
When hardware PWM isn't available or you've run out of channels, this module generates PWM by toggling GPIO in a high-frequency tick ISR.
** **
static SYN_SoftPWM pwm;
syn_soft_pwm_init(&pwm, LED_PIN, 100); // 100 steps resolution
syn_soft_pwm_set_duty(&pwm, 75); // 75% duty cycle
// Call from a timer ISR at (desired_freq * resolution) Hz:
void TIM_IRQHandler(void) {
syn_soft_pwm_tick(&pwm);
}
Public Functions Documentation¶
function syn_soft_pwm_init¶
Initialize a soft PWM channel.
Parameters:
pwmPWM instance to initialize.pinGPIO pin to drive.resolutionNumber of steps per PWM period (e.g., 100 or 256). Higher = finer duty control, but requires faster tick.
function syn_soft_pwm_service¶
Service an array of PWM channels in one call.
Parameters:
channelsArray of PWM instances.countNumber of channels in the array.
function syn_soft_pwm_set_duty¶
Set the duty cycle.
Parameters:
pwmPWM instance.dutyDuty cycle value (0 = off, resolution = 100% on).
function syn_soft_pwm_set_percent¶
Set duty cycle as a percentage (0–100).
Parameters:
pwmPWM instance.percentDuty cycle percentage (0 to 100).
function syn_soft_pwm_tick¶
Advance the PWM phase by one tick.
Call this from a timer ISR or high-frequency polling loop. The tick rate determines the PWM frequency: PWM_freq = tick_rate / resolution
For example: 10 kHz tick with resolution=100 → 100 Hz PWM.
Parameters:
pwmPWM instance.
Public Static Functions Documentation¶
function syn_soft_pwm_get_duty¶
Get the current duty cycle value.
Parameters:
pwmPWM instance.
Returns:
Current duty cycle raw value.
The documentation for this class was generated from the following file src/syntropic/output/syn_soft_pwm.h