| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #ifndef _HALL_SENSOR_H__
- #define _HALL_SENSOR_H__
- #include "os/os_types.h"
- #include "bsp/bsp.h"
- #include "math/fix_math.h"
- #define NEGATIVE (int8_t)-1
- #define POSITIVE (int8_t)1
- //S32Q19 格式
- #define PHASE_0_DEGREE (0)
- #define PHASE_60_DEGREE (983040*32)
- #define PHASE_120_DEGREE (1966080*32)
- #define PHASE_180_DEGREE (2949120*32)
- #define PHASE_240_DEGREE (3932160*32)
- #define PHASE_300_DEGREE (4915200*32)
- #define PHASE_360_DEGREE (5898240*32)
- #define STATE_0 (uint8_t)0
- #define STATE_1 (uint8_t)1
- #define STATE_2 (uint8_t)2
- #define STATE_3 (uint8_t)3
- #define STATE_4 (uint8_t)4
- #define STATE_5 (uint8_t)5
- #define STATE_6 (uint8_t)6
- #define STATE_7 (uint8_t)7
- #define THETA_NONE (float)0xFFFF
- #define SAMPLE_MAX_COUNT 3
- typedef struct {
- u32 ticks[SAMPLE_MAX_COUNT];
- s32q19_t angles[SAMPLE_MAX_COUNT];
- u32 ticks_sum;
- s32q19_t angles_sum;
- u32 index;
- bool full;
- }hall_sample_t;
- typedef struct {
- s32q19_t estimate_el_angle; //60度区间内的估计电角度
- s32q19_t estimate_delta_angle;
- u32 estimate_time_ticks;
- s32q19_t measured_el_angle; //hall测量到的电角度
- s32q19_t next_delta_angle;
- s32q5_t estimate_el_speed;
- s32q5_t immediately_el_speed; //当前的即时速度,主要用来判断电机转动是否达到稳定
- s32q5_t el_speed; //当前的平均效果的电角速度, 单位:rad/s
- s32q5_t rpm; //当前的电速度, 单位:RPM
- bool trns_detect; //速度变化超过阈值
- u8 hall_stat;
- u32 hall_ticks;
- s8 direction;
- s32q19_t phase_offset;
- hall_sample_t samples;
- u32 sensor_error;
- s32q19_t angle_table[8];
- }hall_sensor_t;
- void hall_sensor_init(void);
- void hall_sensor_clear(void);
- s16q5_t hall_sensor_get_theta(void); //return degree
- s32q5_t hall_sensor_get_speed(void); //return rpm;
- int hall_offset_increase(int inc);
- s32 *hall_get_table(void);
- #endif /* _HALL_SENSOR_H__ */
|