File syn_dc_motor.c¶
FileList > motor > syn_dc_motor.c
Go to the source code of this file
DC motor controller implementation.
#include "../util/syn_assert.h"#include "../util/syn_ramp.h"#include "syn_dc_motor.h"#include <string.h>
Public Functions¶
| Type | Name |
|---|---|
| void | syn_dc_motor_brake (SYN_DCMotor * motor) Brake the motor (both pins high, if driver supports it). |
| void | syn_dc_motor_coast (SYN_DCMotor * motor) Stop the motor (coast — both pins low). |
| void | syn_dc_motor_init (SYN_DCMotor * motor, SYN_GPIO_Pin pin_a, SYN_GPIO_Pin pin_b, SYN_DCMotorMode mode) Initialize DC motor controller. |
| SYN_MotorOutput | syn_dc_motor_output (SYN_DCMotor * motor) Create a SYN_MotorOutput interface for this DC motor. |
| void | syn_dc_motor_ramp_to (SYN_DCMotor * motor, int32_t speed, uint16_t duration) Ramp to a target speed over a duration. |
| void | syn_dc_motor_set_duty_callback (SYN_DCMotor * motor, void(*)(SYN_GPIO_Pin, uint16_t, void *) cb, void * ctx) Set the PWM duty callback. |
| void | syn_dc_motor_set_duty_max (SYN_DCMotor * motor, int32_t duty_max) Set the maximum duty cycle value. |
| void | syn_dc_motor_set_speed (SYN_DCMotor * motor, int32_t speed) Set motor speed immediately. |
| void | syn_dc_motor_update (SYN_DCMotor * motor) Update motor ramp. Call periodically. |
Public Static Functions¶
| Type | Name |
|---|---|
| void | apply_speed (SYN_DCMotor * m) Apply the current speed to the motor outputs. |
| int32_t | clamp_speed (const SYN_DCMotor * motor, int32_t speed) Clamp speed to the valid range [-duty_max, +duty_max]. |
| void | dc_output_brake (void * ctx) Brake adapter for SYN_MotorOutput . |
| void | dc_output_coast (void * ctx) Coast adapter for SYN_MotorOutput . |
| void | dc_output_set (void * ctx, int32_t output) Set output adapter for SYN_MotorOutput . |
Public Functions Documentation¶
function syn_dc_motor_brake¶
Brake the motor (both pins high, if driver supports it).
Parameters:
motorMotor instance.
function syn_dc_motor_coast¶
Stop the motor (coast — both pins low).
Parameters:
motorMotor instance.
function syn_dc_motor_init¶
Initialize DC motor controller.
void syn_dc_motor_init (
SYN_DCMotor * motor,
SYN_GPIO_Pin pin_a,
SYN_GPIO_Pin pin_b,
SYN_DCMotorMode mode
)
Sets duty_max to SYN_DC_MOTOR_DUTY_MAX_DEFAULT (1000).
Parameters:
motorMotor instance.pin_aPWM pin (or IN_A).pin_bDirection pin (or IN_B).modeControl mode.
function syn_dc_motor_output¶
Create a SYN_MotorOutput interface for this DC motor.
Returns a motor output vtable that maps set_output() to syn_dc_motor_set_speed(), coast() to syn_dc_motor_coast(), etc. The output range maps directly to [-duty_max, +duty_max].
Parameters:
motorDC motor instance (must outlive the returned output).
Returns:
Motor output interface.
function syn_dc_motor_ramp_to¶
Ramp to a target speed over a duration.
Parameters:
motorMotor.speedTarget speed [-duty_max, +duty_max].durationRamp duration in milliseconds.
function syn_dc_motor_set_duty_callback¶
Set the PWM duty callback.
void syn_dc_motor_set_duty_callback (
SYN_DCMotor * motor,
void(*)( SYN_GPIO_Pin , uint16_t, void *) cb,
void * ctx
)
The callback is called with the pin and a duty value in [0, duty_max] whenever the motor speed changes.
Parameters:
motorMotor instance.cbDuty callback.ctxUser context.
function syn_dc_motor_set_duty_max¶
Set the maximum duty cycle value.
Call after init to change from the default (1000). Resets speed to 0.
Parameters:
motorMotor instance.duty_maxMaximum duty value (e.g., 255, 1000, 4095, 65535).
function syn_dc_motor_set_speed¶
Set motor speed immediately.
Parameters:
motorDC motor handle.speedSpeed in range [-duty_max, +duty_max]. Positive = forward, negative = reverse, 0 = stop. Clamped to ±duty_max.
function syn_dc_motor_update¶
Update motor ramp. Call periodically.
Parameters:
motorMotor instance.
Public Static Functions Documentation¶
function apply_speed¶
Apply the current speed to the motor outputs.
Parameters:
mDC motor instance.
function clamp_speed¶
Clamp speed to the valid range [-duty_max, +duty_max].
Parameters:
motorMotor instance (for duty_max).speedRaw speed value.
Returns:
Clamped speed.
function dc_output_brake¶
Brake adapter for SYN_MotorOutput .
Parameters:
ctxDC motor instance (SYN_DCMotor*).
function dc_output_coast¶
Coast adapter for SYN_MotorOutput .
Parameters:
ctxDC motor instance (SYN_DCMotor*).
function dc_output_set¶
Set output adapter for SYN_MotorOutput .
Parameters:
ctxDC motor instance (SYN_DCMotor*).outputSigned output level.
The documentation for this class was generated from the following file src/syntropic/motor/syn_dc_motor.c