| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #ifndef _HALL_SENSOR_H__
- #define _HALL_SENSOR_H__
- #include "os/os_type.h"
- #include "bsp/bsp.h"
- #define NEGATIVE (int8_t)-1
- #define POSITIVE (int8_t)1
- #define PHASE_60_DEGREE (60)
- #define PHASE_120_DEGREE (120)
- #define PHASE_180_DEGREE (180)
- #define PHASE_240_DEGREE (240)
- #define PHASE_300_DEGREE (300)
- #define PHASE_360_DEGREE (360)
- #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];
- u32 ticks_sum;
- u32 index;
- bool full;
- }hall_sample_t;
- typedef struct {
- float estimate_el_angle; //60度区间内的估计电角度
- u32 estimate_time_ticks;
- s32 estimate_delta_angle;//for debug
- s32 measured_el_angle; //hall测量到的电角度
- u32 speed_us_for_estimate; //hall经过60°的时间,给角度估计使用
- float el_speed; //当前的电角速度, 单位:rad/s
- float rpm; //当前的电速度, 单位:RPM
- u8 hall_stat;
- u32 hall_ticks;
- bool working;
- s8 direction;
- s32 phase_offset;
- bool is_override_angle;
- float override_el_angle;
- hall_sample_t samples[8];
- u32 sensor_error;
- }hall_sensor_t;
- void hall_sensor_init(void);
- void hall_sensor_clear(void);
- float hall_sensor_get_theta(void); //return degree
- float hall_sensor_get_speed(void); //return rpm
- float hall_sensor_avg_speed(void);
- int hall_sensor_calibrate(float voltage);
- void hall_sensor_set_theta(bool override, float theta);
- int hall_offset_increase(int inc);
- #endif /* _HALL_SENSOR_H__ */
|