miniFOC 1.0.3
This open-source project aims to accomplish a FOC(Field Oriented Control) scheme that is operatable with minimum costs in China.
Data Structures | Macros | Functions | Variables
foc.h File Reference

this is the header file of foc.c, which defines the structure of FOC algorithm and angle conversion factor. More...

Go to the source code of this file.

Data Structures

struct  FOC_Structure_t
 structure of FOC algorithm More...
 

Macros

#define MECHANGLE_COEFFICIENT   (6.2831854f / ENCODER_RESO)
 mechanical angle conversion factor More...
 
#define ELECANGLE_COEFFICIENT   ((6.2831854f * POLAR_PAIRS) / ENCODER_RESO)
 electric angle conversion factor More...
 
#define SPEED_COEFFICIENT   ((6.2831852f * TIM13_FREQUENCY) / ENCODER_RESO)
 mechanical rotate speed conversion factor More...
 

Functions

void foc_calculate_dutycycle (float elect_angle, float d, float q, float *u, float *v, float *w)
 calculate the corresponding three-phase PWM duty cycle under the current electrical angle More...
 
void foc_calibrate_phase (void)
 automatic phase sequence detection and correction More...
 

Variables

unsigned char foc_parameter_available_flag
 flag variable for FOC parameter availability More...
 
volatile unsigned char phase_sequence
 motor phase sequence flag variable More...
 
volatile FOC_Structure_t FOC_Struct
 FOC handler. More...
 

Detailed Description

this is the header file of foc.c, which defines the structure of FOC algorithm and angle conversion factor.

Author
Lao·Zhu
Version
V1.0.1
Date
9. October 2021

Definition in file foc.h.

Macro Definition Documentation

◆ ELECANGLE_COEFFICIENT

#define ELECANGLE_COEFFICIENT   ((6.2831854f * POLAR_PAIRS) / ENCODER_RESO)

electric angle conversion factor

Definition at line 26 of file foc.h.

◆ MECHANGLE_COEFFICIENT

#define MECHANGLE_COEFFICIENT   (6.2831854f / ENCODER_RESO)

mechanical angle conversion factor

Definition at line 24 of file foc.h.

◆ SPEED_COEFFICIENT

#define SPEED_COEFFICIENT   ((6.2831852f * TIM13_FREQUENCY) / ENCODER_RESO)

mechanical rotate speed conversion factor

Definition at line 28 of file foc.h.

Function Documentation

◆ foc_calculate_dutycycle()

void foc_calculate_dutycycle ( float  elect_angle,
float  d,
float  q,
float *  u,
float *  v,
float *  w 
)

calculate the corresponding three-phase PWM duty cycle under the current electrical angle

Parameters
[in]elect_angleelectrical angle of motor rotor, in radian system
[in]dexpected field strength in the direct axis direction of the motor
[in]qexpected field strength in the quadrature axis direction of the motor
[out]ucalculation results of U-phase duty cycle
[out]vcalculation results of V-phase duty cycle
[out]wcalculation results of W-phase duty cycle

Definition at line 99 of file foc.c.

References fast_cos, fast_sin(), and VBUS.

Referenced by encoder_zeroing(), foc_calibrate_phase(), and TIMER2_IRQHandler().

◆ foc_calibrate_phase()

void foc_calibrate_phase ( void  )

automatic phase sequence detection and correction

Definition at line 33 of file foc.c.

References CALI_TORQUE, delayms(), encoder_get_mechanical_angle(), foc_calculate_dutycycle(), phase_sequence, and update_pwm_dutycycle().

Referenced by main().

Variable Documentation

◆ foc_parameter_available_flag

unsigned char foc_parameter_available_flag
extern

flag variable for FOC parameter availability

Definition at line 28 of file foc.c.

Referenced by flash_read_parameters(), mdtp_callback_handler(), and report_local_variable().

◆ FOC_Struct

volatile FOC_Structure_t FOC_Struct
extern

◆ phase_sequence

volatile unsigned char phase_sequence
extern

motor phase sequence flag variable

Definition at line 24 of file foc.c.

Referenced by flash_read_parameters(), flash_write_parameters(), foc_calibrate_phase(), report_local_variable(), and TIMER2_IRQHandler().