Skip to content

File syn_foc.c

FileList > motor > syn_foc.c

Go to the source code of this file

Fixed-point Field-Oriented Control transforms. More...

  • #include "../common/syn_defs.h"
  • #include "../util/syn_assert.h"
  • #include "syn_foc.h"

Public Functions

Type Name
void syn_foc_clarke (const SYN_FOC_ABC * abc, SYN_FOC_AB * ab)
Clarke transform: 3-phase (a,b,c) → 2-phase (α,β).
bool syn_foc_field_weakening (q16_t v_d, q16_t v_q, q16_t v_max, q16_t * id_cmd)
Automatic Field-Weakening Controller.
void syn_foc_inv_clarke (const SYN_FOC_AB * ab, SYN_FOC_ABC * abc)
Inverse Clarke: 2-phase (α,β) → 3-phase (a,b,c).
void syn_foc_inv_park (const SYN_FOC_DQ * dq, q16_t theta, SYN_FOC_AB * ab)
Inverse Park: rotating (d,q) → stationary (α,β).
void syn_foc_inv_park_fast (const SYN_FOC_DQ * dq, q16_t theta, SYN_FOC_AB * ab)
Inverse Park: rotating (d,q) → stationary (α,β) using ultra-fast sincos.
void syn_foc_park (const SYN_FOC_AB * ab, q16_t theta, SYN_FOC_DQ * dq)
Park transform: stationary (α,β) → rotating (d,q).
void syn_foc_park_fast (const SYN_FOC_AB * ab, q16_t theta, SYN_FOC_DQ * dq)
Park transform: stationary (α,β) → rotating (d,q) using ultra-fast sincos.
void syn_foc_svpwm (const SYN_FOC_AB * ab, q16_t v_bus, q16_t * duty_a, q16_t * duty_b, q16_t * duty_c)
Compute Space Vector PWM duty cycles from (α, β).

Macros

Type Name
define Q16_2_INV_SQRT3 75674
Precomputed 2/√3 in Q16.16 (≈ 1.15470).
define Q16_INV_SQRT3 37837
Precomputed 1/√3 in Q16.16 (≈ 0.57735).
define Q16_SQRT3 113512
Precomputed √3 in Q16.16 (≈ 1.73205).
define Q16_SQRT3_OVER_2 56756
Precomputed √3/2 in Q16.16 (≈ 0.86603).

Detailed Description

All transforms use Q16.16 arithmetic with int64_t intermediates. No floating point, no heap allocation.

Public Functions Documentation

function syn_foc_clarke

Clarke transform: 3-phase (a,b,c) → 2-phase (α,β).

void syn_foc_clarke (
    const SYN_FOC_ABC * abc,
    SYN_FOC_AB * ab
) 

Power-invariant form: α = a β = (a + 2b) / √3

Assumes balanced 3-phase: a + b + c = 0.

Parameters:

  • abc Input 3-phase values.
  • ab Output (α, β).

function syn_foc_field_weakening

Automatic Field-Weakening Controller.

bool syn_foc_field_weakening (
    q16_t v_d,
    q16_t v_q,
    q16_t v_max,
    q16_t * id_cmd
) 

Injects negative d-axis current (Id < 0) when commanded voltage magnitude exceeds maximum available bus voltage limit (V_max = V_bus / sqrt(3)), allowing high-speed motor operation above rated base speed.

Parameters:

  • v_d Current D-axis voltage command (Q16).
  • v_q Current Q-axis voltage command (Q16).
  • v_max Maximum available phase voltage magnitude (Q16).
  • id_cmd [in/out] Current D-axis command (Q16). Adjusted if over-voltage occurs.

Returns:

true if field weakening active, false if operating normally.


function syn_foc_inv_clarke

Inverse Clarke: 2-phase (α,β) → 3-phase (a,b,c).

void syn_foc_inv_clarke (
    const SYN_FOC_AB * ab,
    SYN_FOC_ABC * abc
) 

Parameters:

  • ab Input (α, β).
  • abc Output 3-phase values.

function syn_foc_inv_park

Inverse Park: rotating (d,q) → stationary (α,β).

void syn_foc_inv_park (
    const SYN_FOC_DQ * dq,
    q16_t theta,
    SYN_FOC_AB * ab
) 

α = d·cos(θ) − q·sin(θ) β = d·sin(θ) + q·cos(θ)

Parameters:

  • dq Input rotating-frame values.
  • theta Electrical rotor angle in Q16 radians.
  • ab Output stationary-frame values.

function syn_foc_inv_park_fast

Inverse Park: rotating (d,q) → stationary (α,β) using ultra-fast sincos.

void syn_foc_inv_park_fast (
    const SYN_FOC_DQ * dq,
    q16_t theta,
    SYN_FOC_AB * ab
) 


function syn_foc_park

Park transform: stationary (α,β) → rotating (d,q).

void syn_foc_park (
    const SYN_FOC_AB * ab,
    q16_t theta,
    SYN_FOC_DQ * dq
) 

d = α·cos(θ) + β·sin(θ) q = −α·sin(θ) + β·cos(θ)

Parameters:

  • ab Input stationary-frame values.
  • theta Electrical rotor angle in Q16 radians.
  • dq Output rotating-frame values.

function syn_foc_park_fast

Park transform: stationary (α,β) → rotating (d,q) using ultra-fast sincos.

void syn_foc_park_fast (
    const SYN_FOC_AB * ab,
    q16_t theta,
    SYN_FOC_DQ * dq
) 


function syn_foc_svpwm

Compute Space Vector PWM duty cycles from (α, β).

void syn_foc_svpwm (
    const SYN_FOC_AB * ab,
    q16_t v_bus,
    q16_t * duty_a,
    q16_t * duty_b,
    q16_t * duty_c
) 

Maps (α, β) voltages to three-phase PWM duty cycles in the range [0, Q16_ONE]. Uses standard 7-segment SVPWM pattern.

Parameters:

  • ab Input (α, β) voltage commands (Q16).
  • v_bus DC bus voltage in Q16 (for normalization).
  • duty_a Output duty cycle for phase A [0, Q16_ONE].
  • duty_b Output duty cycle for phase B [0, Q16_ONE].
  • duty_c Output duty cycle for phase C [0, Q16_ONE].

Macro Definition Documentation

define Q16_2_INV_SQRT3

Precomputed 2/√3 in Q16.16 (≈ 1.15470).

#define Q16_2_INV_SQRT3 `75674`


define Q16_INV_SQRT3

Precomputed 1/√3 in Q16.16 (≈ 0.57735).

#define Q16_INV_SQRT3 `37837`


define Q16_SQRT3

Precomputed √3 in Q16.16 (≈ 1.73205).

#define Q16_SQRT3 `113512`


define Q16_SQRT3_OVER_2

Precomputed √3/2 in Q16.16 (≈ 0.86603).

#define Q16_SQRT3_OVER_2 `56756`



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