Skip to content

File syn_servo.h

FileList > motor > syn_servo.h

Go to the source code of this file

Hobby servo controller — pulse-width positioning. More...

  • #include "../port/syn_port_system.h"
  • #include <stdbool.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_Servo
Hobby servo instance — pulse range, position, smooth movement.

Public Functions

Type Name
void syn_servo_init (SYN_Servo * servo, uint16_t pulse_min, uint16_t pulse_max, uint16_t angle_range)
Initialize a servo.
void syn_servo_move_to (SYN_Servo * servo, uint16_t angle, uint16_t duration)
Start a smooth move to an angle.
void syn_servo_set_angle (SYN_Servo * servo, uint16_t angle)
Set servo position by angle (immediate).
void syn_servo_set_pulse (SYN_Servo * servo, uint16_t us)
Set servo position by raw pulse width (immediate).
void syn_servo_update (SYN_Servo * servo)
Update servo position for smooth movement.

Public Static Functions

Type Name
bool syn_servo_at_target (const SYN_Servo * servo)
Is the servo at its target position?
uint16_t syn_servo_get_angle (const SYN_Servo * servo)
Get the current angle.
uint16_t syn_servo_get_pulse_us (const SYN_Servo * servo)
Get the current pulse width in microseconds.

Detailed Description

Standard hobby servos expect a 50 Hz PWM signal with a pulse width of 1000–2000 µs (center = 1500 µs). This module provides angle-based and microsecond-based positioning with optional smooth movement.

Requires a hardware timer or syn_soft_pwm for pulse generation. The module computes pulse width; you connect it to your PWM output.

** **

SYN_Servo servo;
syn_servo_init(&servo, 1000, 2000, 180); // 1000–2000µs, 180° range

syn_servo_set_angle(&servo, 90);   // center
uint16_t pw = syn_servo_get_pulse_us(&servo);  // → 1500µs

// Smooth move:
syn_servo_move_to(&servo, 0, 500);  // move to 0° over 500ms
while (!syn_servo_at_target(&servo)) {
    syn_servo_update(&servo);       // call periodically
    set_pwm_us(syn_servo_get_pulse_us(&servo));
}

Public Functions Documentation

function syn_servo_init

Initialize a servo.

void syn_servo_init (
    SYN_Servo * servo,
    uint16_t pulse_min,
    uint16_t pulse_max,
    uint16_t angle_range
) 

Parameters:

  • servo Servo instance.
  • pulse_min Minimum pulse width in µs (0° position).
  • pulse_max Maximum pulse width in µs (max angle position).
  • angle_range Full angular range in degrees.

function syn_servo_move_to

Start a smooth move to an angle.

void syn_servo_move_to (
    SYN_Servo * servo,
    uint16_t angle,
    uint16_t duration
) 

Parameters:

  • servo Servo.
  • angle Target angle.
  • duration Movement duration in milliseconds.

function syn_servo_set_angle

Set servo position by angle (immediate).

void syn_servo_set_angle (
    SYN_Servo * servo,
    uint16_t angle
) 

Parameters:

  • servo Servo handle.
  • angle Angle in degrees (0 to angle_range).

function syn_servo_set_pulse

Set servo position by raw pulse width (immediate).

void syn_servo_set_pulse (
    SYN_Servo * servo,
    uint16_t us
) 

Parameters:

  • servo Servo handle.
  • us Pulse width in microseconds.

function syn_servo_update

Update servo position for smooth movement.

void syn_servo_update (
    SYN_Servo * servo
) 

Call periodically (e.g., every 10–20ms) while a smooth move is active.

Parameters:

  • servo Servo instance.

Public Static Functions Documentation

function syn_servo_at_target

Is the servo at its target position?

static inline bool syn_servo_at_target (
    const SYN_Servo * servo
) 

Parameters:

  • servo Servo.

Returns:

true if at target.


function syn_servo_get_angle

Get the current angle.

static inline uint16_t syn_servo_get_angle (
    const SYN_Servo * servo
) 

Parameters:

  • servo Servo.

Returns:

Angle in degrees.


function syn_servo_get_pulse_us

Get the current pulse width in microseconds.

static inline uint16_t syn_servo_get_pulse_us (
    const SYN_Servo * servo
) 

Parameters:

  • servo Servo.

Returns:

Pulse width in µs.



The documentation for this class was generated from the following file src/syntropic/motor/syn_servo.h