FOC#

foc.h contains the foc interrupt and related functions.

void set_current_setpoints(int D_setpoint_mA, int Q_setpoint_mA)#

Set target current setpoints in rotor space.

Note

In normal operation, D should be set to 0, and Q set to the desired current based on required torque.

Parameters:
  • D_setpoint_mA – D “normal current”

  • Q_setpoint_mA – Q “tangent current”

void foc_interrupt()#

Runs required FOC functions on TIM6 interrupt at 10KHz.

void clarke_transform(int16_t A, int16_t B, int16_t C, int16_t *alpha, int16_t *beta)#

Power invariant Clarke transform, converts from a 3-phase coordinate system to orthogonal coordinates (with Alpha in line with phase A)

Parameters:
  • A – Phase A value

  • B – Phase B value

  • C – Phase C value

  • alpha – Pointer to Alpha value to be set

  • beta – Pointer to Beta value to be set

void park_transform(int16_t alpha, int16_t beta, uint8_t angle, int16_t *d, int16_t *q)#

Park transform, converts from stator-aligned orthogonal coordinates to rotor aligned orthogonal coordinates. D is aligned “normal” and Q is aligned “tangent”.

Parameters:
  • alpha – Alpha value

  • beta – Beta value

  • angle – Electrical angle as a 8-bit integer (255 = 2pi)

  • d – Pointer to D value to be set

  • q – Pointer to Q value to be set

void inverse_clarke_transform(int16_t alpha, int16_t beta, int16_t *a, int16_t *b, int16_t *c)#

Inverse power invariant Clarke transform. See also clarke_transform()

Parameters:
  • alpha – Alpha value

  • beta – Beta value

  • a – Pointer to A-phase value to be set

  • b – Pointer to A-phase value to be set

  • c – Pointer to A-phase value to be set

void inverse_park_transform(int16_t d, int16_t q, uint8_t angle, int16_t *alpha, int16_t *beta)#

Inverse Park transform. See also park_transform()

Parameters:
  • d

  • q

  • angle

  • alpha

  • beta