Skip to content

File syn_soft_pwm.c

FileList > output > syn_soft_pwm.c

Go to the source code of this file

Software PWM implementation.

  • #include "../drivers/syn_gpio.h"
  • #include "../util/syn_assert.h"
  • #include "syn_soft_pwm.h"
  • #include <string.h>

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 Functions Documentation

function syn_soft_pwm_init

Initialize a soft PWM channel.

void syn_soft_pwm_init (
    SYN_SoftPWM * pwm,
    SYN_GPIO_Pin pin,
    uint16_t resolution
) 

Parameters:

  • pwm PWM instance to initialize.
  • pin GPIO pin to drive.
  • resolution Number 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.

void syn_soft_pwm_service (
    SYN_SoftPWM * channels,
    size_t count
) 

Parameters:

  • channels Array of PWM instances.
  • count Number of channels in the array.

function syn_soft_pwm_set_duty

Set the duty cycle.

void syn_soft_pwm_set_duty (
    SYN_SoftPWM * pwm,
    uint16_t duty
) 

Parameters:

  • pwm PWM instance.
  • duty Duty cycle value (0 = off, resolution = 100% on).

function syn_soft_pwm_set_percent

Set duty cycle as a percentage (0–100).

void syn_soft_pwm_set_percent (
    SYN_SoftPWM * pwm,
    uint8_t percent
) 

Parameters:

  • pwm PWM instance.
  • percent Duty cycle percentage (0 to 100).

function syn_soft_pwm_tick

Advance the PWM phase by one tick.

void syn_soft_pwm_tick (
    SYN_SoftPWM * pwm
) 

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:

  • pwm PWM instance.


The documentation for this class was generated from the following file src/syntropic/output/syn_soft_pwm.c