46 unsigned char delay_counter = 0xff;
60 gpio_bit_write(GPIOA, GPIO_PIN_4, RESET);
68 gpio_bit_write(GPIOA, GPIO_PIN_4, SET);
100 return electric_angle;
used to place important parameter configurations for users
#define CALI_TORQUE
set calibrate torque to 0.5
#define ENCODER_RESO
SC60228 resolution is 2^8 = 4096.
#define POLAR_PAIRS
set BLDC polar pairs to 7
unsigned short encoder_get_mechanical_angle(void)
read mechanical angle directly from encoder
void encoder_delay(void)
delay function for magnetic encoder
volatile unsigned short machine_angle_offset
mechanical angle offset, which is used to align the mechanical angle with the zero point of the elect...
void encoder_update_speed(void)
called every 2 milliseconds to calculate the speed.
float encoder_get_electronic_angle(void)
according to the electrical angle calculated from the mechanical angle, this function will call encod...
static volatile long long total_machine_angle
the total mechanical angle since power on is used to calculate the angle integral value and realize t...
unsigned short encoder_read_data(unsigned short TxData)
read data from the register of the magnetic encoder
void encoder_zeroing(void)
correct the mechanical angle zero deviation between the magnetic encoder and FOC.
static volatile long long systick_mechanical_angle_last
the mechanical angle at the last moment is used to calculate the rotation speed of the motor rotor.
static volatile unsigned short last_mechanical_angle
the mechanical angle at the last moment is used to calculate the angle differential value and realize...
this is the header file of encoder.c.
float filter_update_value(Filter_Structure_t *param, short value)
update the output value of the first-order low-pass filter
volatile Filter_Structure_t velocity_filter
motor rotation speed low pass filter handle
this is the header file of filter.c, which defines the structure of filter algorithm.
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
volatile FOC_Structure_t FOC_Struct
FOC handler.
this is the header file of foc.c, which defines the structure of FOC algorithm and angle conversion f...
#define ELECANGLE_COEFFICIENT
electric angle conversion factor
#define MECHANGLE_COEFFICIENT
mechanical angle conversion factor
unsigned short spi_readwrite_halfworld(unsigned short data)
spi0 transmit data for sc60228
this is the header file of spi.c.
float rotate_speed
motor rotate speed calculate from timer
float mechanical_angle
mechanical angle read form encoder
structure of low-pass filter algorithm
void delayms(unsigned long count)
millisecond delay function, any time time.
system basic function header file
void update_pwm_dutycycle(float ch0, float ch1, float ch2)
update timer1 ch0 1 2 duty-cycle
this is the header file of timer.c.