![]() |
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.
|
this file contains the code implementation of angle acquisition and initialization functions of sc60228 and sc60224. More...
#include "encoder.h"
#include "spi.h"
#include "gd32f1x0.h"
#include "foc.h"
#include "timer.h"
#include "system.h"
#include "config.h"
#include "filter.h"
Go to the source code of this file.
Functions | |
void | encoder_delay (void) |
delay function for magnetic encoder More... | |
unsigned short | encoder_read_data (unsigned short TxData) |
read data from the register of the magnetic encoder More... | |
unsigned short | encoder_get_mechanical_angle (void) |
read mechanical angle directly from encoder More... | |
float | encoder_get_electronic_angle (void) |
according to the electrical angle calculated from the mechanical angle, this function will call encoder_get_mechanical_angle() function. More... | |
void | encoder_update_speed (void) |
called every 2 milliseconds to calculate the speed. More... | |
void | encoder_zeroing (void) |
correct the mechanical angle zero deviation between the magnetic encoder and FOC. More... | |
Variables | |
volatile unsigned short | machine_angle_offset = 0 |
mechanical angle offset, which is used to align the mechanical angle with the zero point of the electrical angle. More... | |
static volatile unsigned short | last_mechanical_angle = 0 |
the mechanical angle at the last moment is used to calculate the angle differential value and realize the angle measurement function. More... | |
static volatile long long | total_machine_angle = 0 |
the total mechanical angle since power on is used to calculate the angle integral value and realize the angle measurement function. More... | |
static volatile long long | systick_mechanical_angle_last = 0 |
the mechanical angle at the last moment is used to calculate the rotation speed of the motor rotor. More... | |
this file contains the code implementation of angle acquisition and initialization functions of sc60228 and sc60224.
Definition in file encoder.c.
void encoder_delay | ( | void | ) |
delay function for magnetic encoder
Definition at line 44 of file encoder.c.
Referenced by encoder_read_data().
float encoder_get_electronic_angle | ( | void | ) |
according to the electrical angle calculated from the mechanical angle, this function will call encoder_get_mechanical_angle() function.
register | raw data reading back |
Definition at line 93 of file encoder.c.
References ELECANGLE_COEFFICIENT, encoder_get_mechanical_angle(), ENCODER_RESO, FOC_Struct, MECHANGLE_COEFFICIENT, FOC_Structure_t::mechanical_angle, and POLAR_PAIRS.
Referenced by TIMER2_IRQHandler().
unsigned short encoder_get_mechanical_angle | ( | void | ) |
read mechanical angle directly from encoder
register | raw data reading back |
Definition at line 76 of file encoder.c.
References encoder_read_data(), ENCODER_RESO, last_mechanical_angle, machine_angle_offset, and total_machine_angle.
Referenced by encoder_get_electronic_angle(), and foc_calibrate_phase().
unsigned short encoder_read_data | ( | unsigned short | TxData | ) |
read data from the register of the magnetic encoder
[in] | TxData | data to be sent to magnetic encoder |
data | read from magnetic encoder |
Definition at line 56 of file encoder.c.
References encoder_delay(), and spi_readwrite_halfworld().
Referenced by encoder_get_mechanical_angle(), and encoder_zeroing().
void encoder_update_speed | ( | void | ) |
called every 2 milliseconds to calculate the speed.
Definition at line 106 of file encoder.c.
References filter_update_value(), FOC_Struct, FOC_Structure_t::rotate_speed, systick_mechanical_angle_last, total_machine_angle, and velocity_filter.
Referenced by SysTick_Handler().
void encoder_zeroing | ( | void | ) |
correct the mechanical angle zero deviation between the magnetic encoder and FOC.
Definition at line 119 of file encoder.c.
References CALI_TORQUE, delayms(), encoder_read_data(), foc_calculate_dutycycle(), machine_angle_offset, total_machine_angle, and update_pwm_dutycycle().
Referenced by main().
|
static |
the mechanical angle at the last moment is used to calculate the angle differential value and realize the angle measurement function.
Definition at line 29 of file encoder.c.
Referenced by encoder_get_mechanical_angle().
volatile unsigned short machine_angle_offset = 0 |
mechanical angle offset, which is used to align the mechanical angle with the zero point of the electrical angle.
Definition at line 23 of file encoder.c.
Referenced by encoder_get_mechanical_angle(), encoder_zeroing(), flash_read_parameters(), flash_write_parameters(), and report_local_variable().
|
static |
the mechanical angle at the last moment is used to calculate the rotation speed of the motor rotor.
Definition at line 39 of file encoder.c.
Referenced by encoder_update_speed().
|
static |
the total mechanical angle since power on is used to calculate the angle integral value and realize the angle measurement function.
Definition at line 34 of file encoder.c.
Referenced by encoder_get_mechanical_angle(), encoder_update_speed(), and encoder_zeroing().