Skip to content

File syn_bldc_6step.h

FileList > motor > syn_bldc_6step.h

Go to the source code of this file

Zero-Heap 6-Step (Trapezoidal) BLDC Motor Commutation Driver. More...

  • #include "syntropic/common/syn_defs.h"
  • #include "syntropic/control/syn_pid.h"
  • #include "syntropic/util/syn_qmath.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_BLDC_6Step
struct SYN_BLDC_Config
struct SYN_BLDC_PhaseOutputs

Public Types

Type Name
enum SYN_BLDC_Direction
enum SYN_BLDC_GateState
enum SYN_BLDC_State

Public Functions

Type Name
SYN_Status syn_bldc_6step_get_phase_outputs (const SYN_BLDC_6Step * bldc, SYN_BLDC_PhaseOutputs * out)
Retrieve current 3-phase gate output states.
SYN_Status syn_bldc_6step_init (SYN_BLDC_6Step * bldc, const SYN_BLDC_Config * cfg)
Initialize 6-Step BLDC driver instance.
SYN_Status syn_bldc_6step_set_direction (SYN_BLDC_6Step * bldc, SYN_BLDC_Direction dir)
Set motor rotation direction.
SYN_Status syn_bldc_6step_set_duty (SYN_BLDC_6Step * bldc, uint16_t duty_0_to_1000)
Set PWM duty cycle for motor speed control.
SYN_Status syn_bldc_6step_set_hall (SYN_BLDC_6Step * bldc, uint8_t hall_state, SYN_BLDC_PhaseOutputs * out)
Process 3-bit Hall sensor reading and update 6-step phase commutation gates.
SYN_Status syn_bldc_6step_start (SYN_BLDC_6Step * bldc)
Start motor driver (enable gate commutation).
SYN_Status syn_bldc_6step_stop (SYN_BLDC_6Step * bldc, SYN_BLDC_PhaseOutputs * out)
Stop motor driver (turn OFF all 6 gates).
uint32_t syn_bldc_6step_update_speed (SYN_BLDC_6Step * bldc, uint32_t now_ms, uint32_t target_rpm)
Update Hall-based speed calculation (RPM) and speed PID loop.

Detailed Description

Provides 6-step trapezoidal block commutation for 3-phase Brushless DC (BLDC) motors: * 3-channel Hall sensor state decoding (Hall states 1..6) * 6-step phase commutation lookup table for 3-phase half-bridge outputs (U, V, W) * Clockwise (CW) & Counter-Clockwise (CCW) rotation support * Fault detection for invalid Hall states (0b000 & 0b111) * PWM duty cycle scaling (0..1000) * Hall transition edge timestamping for RPM speed calculation

Public Types Documentation

enum SYN_BLDC_Direction

enum SYN_BLDC_Direction {
    SYN_BLDC_DIR_CW = 1,
    SYN_BLDC_DIR_CCW = 2
};

Motor Rotation Direction.


enum SYN_BLDC_GateState

enum SYN_BLDC_GateState {
    SYN_BLDC_GATE_OFF = 0,
    SYN_BLDC_GATE_PWM = 1,
    SYN_BLDC_GATE_LOW = 2
};

Phase Output State (High-Side / Low-Side Gate Switches).


enum SYN_BLDC_State

enum SYN_BLDC_State {
    SYN_BLDC_STATE_STOPPED = 0,
    SYN_BLDC_STATE_RUNNING = 1,
    SYN_BLDC_STATE_FAULT = 2
};

Driver State.


Public Functions Documentation

function syn_bldc_6step_get_phase_outputs

Retrieve current 3-phase gate output states.

SYN_Status syn_bldc_6step_get_phase_outputs (
    const SYN_BLDC_6Step * bldc,
    SYN_BLDC_PhaseOutputs * out
) 

Parameters:

  • bldc Pointer to driver struct.
  • out Pointer to destination output struct.

Returns:

SYN_OK on success.


function syn_bldc_6step_init

Initialize 6-Step BLDC driver instance.

SYN_Status syn_bldc_6step_init (
    SYN_BLDC_6Step * bldc,
    const SYN_BLDC_Config * cfg
) 

Parameters:

  • bldc Pointer to driver struct.
  • cfg Configuration parameters (or NULL for defaults: 4 pole pairs).

Returns:

SYN_OK on success, SYN_ERR_INVALID_PARAM if bldc is NULL.


function syn_bldc_6step_set_direction

Set motor rotation direction.

SYN_Status syn_bldc_6step_set_direction (
    SYN_BLDC_6Step * bldc,
    SYN_BLDC_Direction dir
) 

Parameters:

  • bldc Pointer to driver struct.
  • dir SYN_BLDC_DIR_CW or SYN_BLDC_DIR_CCW.

Returns:

SYN_OK on success.


function syn_bldc_6step_set_duty

Set PWM duty cycle for motor speed control.

SYN_Status syn_bldc_6step_set_duty (
    SYN_BLDC_6Step * bldc,
    uint16_t duty_0_to_1000
) 

Parameters:

  • bldc Pointer to driver struct.
  • duty_0_to_1000 PWM duty cycle clamped to range 0..1000.

Returns:

SYN_OK on success.


function syn_bldc_6step_set_hall

Process 3-bit Hall sensor reading and update 6-step phase commutation gates.

SYN_Status syn_bldc_6step_set_hall (
    SYN_BLDC_6Step * bldc,
    uint8_t hall_state,
    SYN_BLDC_PhaseOutputs * out
) 

Call this from Hall sensor EXTI GPIO interrupts or input sampling loops.

Parameters:

  • bldc Pointer to driver struct.
  • hall_state 3-bit Hall sensor state (bits [2:0] = H3, H2, H1). Valid: 1..6.
  • out Pointer to output struct to receive new 3-phase gate states.

Returns:

SYN_OK on valid commutation step, SYN_ERR_FAULT if hall_state is 0b000 or 0b111.


function syn_bldc_6step_start

Start motor driver (enable gate commutation).

SYN_Status syn_bldc_6step_start (
    SYN_BLDC_6Step * bldc
) 

Parameters:

  • bldc Pointer to driver struct.

Returns:

SYN_OK on success.


function syn_bldc_6step_stop

Stop motor driver (turn OFF all 6 gates).

SYN_Status syn_bldc_6step_stop (
    SYN_BLDC_6Step * bldc,
    SYN_BLDC_PhaseOutputs * out
) 

Parameters:

  • bldc Pointer to driver struct.
  • out Optional pointer to receive updated OFF gate states.

Returns:

SYN_OK on success.


function syn_bldc_6step_update_speed

Update Hall-based speed calculation (RPM) and speed PID loop.

uint32_t syn_bldc_6step_update_speed (
    SYN_BLDC_6Step * bldc,
    uint32_t now_ms,
    uint32_t target_rpm
) 

Call periodically (e.g. every 10ms or 100ms).

Parameters:

  • bldc Pointer to driver struct.
  • now_ms Current system tick in milliseconds.
  • target_rpm Target motor speed in RPM (used if speed PID is active).

Returns:

Calculated current RPM.



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