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.
Functions | Variables
foc.c File Reference

this document is mainly the code implementation of motor phase sequence correction and FOC algorithm. More...

#include "foc.h"
#include "config.h"
#include "fast_math.h"
#include "encoder.h"
#include "system.h"
#include "timer.h"

Go to the source code of this file.

Functions

void foc_calibrate_phase (void)
 automatic phase sequence detection and correction More...
 
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...
 

Variables

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

Detailed Description

this document is mainly the code implementation of motor phase sequence correction and FOC algorithm.

Author
Lao·Zhu
Version
V1.0.3
Date
1. August 2023

Definition in file foc.c.

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 = 1

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

◆ phase_sequence

volatile unsigned char phase_sequence = 0

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().