Skip to content

File syn_stepper.h

FileList > motor > syn_stepper.h

Go to the source code of this file

Stepper motor driver — step/direction with acceleration ramps. More...

  • #include "../common/syn_defs.h"
  • #include "../drivers/syn_gpio.h"
  • #include "../motor/syn_motor_output.h"
  • #include "../port/syn_port_system.h"
  • #include <stdbool.h>

Classes

Type Name
struct SYN_Stepper
Stepper motor controller context.

Public Types

Type Name
enum SYN_StepperDir
Stepper motor direction.
enum SYN_StepperState
Stepper motor operational states for the ramp generator.

Public Functions

Type Name
void syn_stepper_enable (const SYN_Stepper * s, bool enable)
Enable or disable the motor driver.
void syn_stepper_init (SYN_Stepper * s, SYN_GPIO_Pin step_pin, SYN_GPIO_Pin dir_pin)
Initialize stepper motor driver.
void syn_stepper_move (SYN_Stepper * s, int32_t steps)
Start a relative move.
void syn_stepper_move_to (SYN_Stepper * s, int32_t position)
Start a move to an absolute position.
SYN_MotorOutput syn_stepper_output (SYN_Stepper * stepper)
Create a SYN_MotorOutput interface for this stepper.
void syn_stepper_set_enable_pin (SYN_Stepper * s, SYN_GPIO_Pin pin, bool active_low)
Set optional enable pin.
void syn_stepper_set_speed (SYN_Stepper * s, uint32_t max_sps, uint32_t accel_sps2)
Set maximum speed and acceleration.
void syn_stepper_stop (SYN_Stepper * s)
Emergency stop — immediately halt with no deceleration.
void syn_stepper_tick (SYN_Stepper * s)
Advance the stepper state machine by one tick.

Public Static Functions

Type Name
bool syn_stepper_is_moving (const SYN_Stepper * s)
Is a move in progress?
int32_t syn_stepper_position (const SYN_Stepper * s)
Get current position (steps).
void syn_stepper_set_position (SYN_Stepper * s, int32_t pos)
Set current position without moving.

Detailed Description

Generates step pulses for step/dir drivers (A4988, DRV8825, TMC2209, etc.). Supports trapezoidal acceleration profiles and non-blocking operation.

** **

static SYN_Stepper stepper;
syn_stepper_init(&stepper, STEP_PIN, DIR_PIN);
syn_stepper_set_speed(&stepper, 1000, 500);   // max 1000 sps, accel 500 sps²
syn_stepper_move(&stepper, 2000);               // move 2000 steps forward

// Call periodically (from timer ISR or fast loop):
syn_stepper_tick(&stepper);

Public Types Documentation

enum SYN_StepperDir

Stepper motor direction.

enum SYN_StepperDir {
    SYN_STEPPER_CW = 0,
    SYN_STEPPER_CCW = 1
};


enum SYN_StepperState

Stepper motor operational states for the ramp generator.

enum SYN_StepperState {
    SYN_STEPPER_IDLE = 0,
    SYN_STEPPER_ACCEL = 1,
    SYN_STEPPER_CRUISE = 2,
    SYN_STEPPER_DECEL = 3
};


Public Functions Documentation

function syn_stepper_enable

Enable or disable the motor driver.

void syn_stepper_enable (
    const SYN_Stepper * s,
    bool enable
) 

Parameters:

  • s Stepper instance.
  • enable true to enable, false to disable.

function syn_stepper_init

Initialize stepper motor driver.

void syn_stepper_init (
    SYN_Stepper * s,
    SYN_GPIO_Pin step_pin,
    SYN_GPIO_Pin dir_pin
) 

Parameters:

  • s Stepper instance.
  • step_pin Step pulse GPIO.
  • dir_pin Direction GPIO.

function syn_stepper_move

Start a relative move.

void syn_stepper_move (
    SYN_Stepper * s,
    int32_t steps
) 

Parameters:

  • s Stepper handle.
  • steps Number of steps (positive = forward, negative = reverse).

function syn_stepper_move_to

Start a move to an absolute position.

void syn_stepper_move_to (
    SYN_Stepper * s,
    int32_t position
) 

Parameters:

  • s Stepper.
  • position Target absolute position in steps.

function syn_stepper_output

Create a SYN_MotorOutput interface for this stepper.

SYN_MotorOutput syn_stepper_output (
    SYN_Stepper * stepper
) 

The set_output callback calls syn_stepper_tick(), coast/brake both call syn_stepper_stop(). The motor controller's output value is not used directly — stepper motion is driven by the stepper's own move/move_to commands.

Parameters:

  • stepper Stepper instance (must outlive the returned output).

Returns:

Motor output interface.


function syn_stepper_set_enable_pin

Set optional enable pin.

void syn_stepper_set_enable_pin (
    SYN_Stepper * s,
    SYN_GPIO_Pin pin,
    bool active_low
) 

Parameters:

  • s Stepper instance.
  • pin Enable signal GPIO pin.
  • active_low True if enabling requires driving pin LOW.

function syn_stepper_set_speed

Set maximum speed and acceleration.

void syn_stepper_set_speed (
    SYN_Stepper * s,
    uint32_t max_sps,
    uint32_t accel_sps2
) 

Parameters:

  • s Stepper.
  • max_sps Maximum speed in steps per second.
  • accel_sps2 Acceleration in steps per second².

function syn_stepper_stop

Emergency stop — immediately halt with no deceleration.

void syn_stepper_stop (
    SYN_Stepper * s
) 

Parameters:

  • s Stepper instance.

function syn_stepper_tick

Advance the stepper state machine by one tick.

void syn_stepper_tick (
    SYN_Stepper * s
) 

Call from a timer ISR or high-frequency loop. The tick rate should be at least 2× the maximum step rate for proper pulse generation.

Parameters:

  • s Stepper instance.

Public Static Functions Documentation

function syn_stepper_is_moving

Is a move in progress?

static inline bool syn_stepper_is_moving (
    const SYN_Stepper * s
) 

Parameters:

  • s Stepper.

Returns:

true if moving.


function syn_stepper_position

Get current position (steps).

static inline int32_t syn_stepper_position (
    const SYN_Stepper * s
) 

Parameters:

  • s Stepper.

Returns:

Position in steps.


function syn_stepper_set_position

Set current position without moving.

static inline void syn_stepper_set_position (
    SYN_Stepper * s,
    int32_t pos
) 

Parameters:

  • s Stepper.
  • pos New position.


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