hall_sensor.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef _HALL_SENSOR_H__
  2. #define _HALL_SENSOR_H__
  3. #include "os/os_type.h"
  4. #include "bsp/bsp.h"
  5. #define NEGATIVE (int8_t)-1
  6. #define POSITIVE (int8_t)1
  7. #define PHASE_60_DEGREE (60)
  8. #define PHASE_120_DEGREE (120)
  9. #define PHASE_180_DEGREE (180)
  10. #define PHASE_240_DEGREE (240)
  11. #define PHASE_300_DEGREE (300)
  12. #define PHASE_360_DEGREE (360)
  13. #define STATE_0 (uint8_t)0
  14. #define STATE_1 (uint8_t)1
  15. #define STATE_2 (uint8_t)2
  16. #define STATE_3 (uint8_t)3
  17. #define STATE_4 (uint8_t)4
  18. #define STATE_5 (uint8_t)5
  19. #define STATE_6 (uint8_t)6
  20. #define STATE_7 (uint8_t)7
  21. #define THETA_NONE (float)0xFFFF
  22. #define SAMPLE_MAX_COUNT 6
  23. typedef struct {
  24. u32 ticks[SAMPLE_MAX_COUNT];
  25. u32 ticks_sum;
  26. u32 index;
  27. bool full;
  28. }hall_sample_t;
  29. typedef struct {
  30. bool estimate_angle_aliment;
  31. s32 measured_el_angle; //hall测量到的电角度
  32. float estimate_el_angle; //60度区间内的估计电角度
  33. float estimate_delta_angle;
  34. float el_speed; //当前的电角速度, 单位:rad/s
  35. float el_speed_avg; //滤波后的电角速度
  36. float el_speed_compensate; //电角速度补偿
  37. //float el_angle_mod;
  38. float rpm; //当前的电速度, 单位:RPM
  39. u8 state;
  40. u32 ticks;
  41. bool working;
  42. s8 direction;
  43. u32 phase_offset;
  44. bool is_override_angle;
  45. float override_el_angle;
  46. hall_sample_t samples;
  47. }hall_t;
  48. void hall_sensor_init(void);
  49. void hall_sensor_clear(void);
  50. float hall_sensor_get_theta(void); //return degree
  51. float hall_sensor_get_speed(void); //return rpm
  52. float hall_sensor_avg_speed(void);
  53. int hall_sensor_calibrate(float voltage, u16 *hall_table);
  54. void hall_sensor_set_theta(bool override, float theta);
  55. u16 *hall_phase_angle(void);
  56. int hall_offset_increase(int inc);
  57. #endif /* _HALL_SENSOR_H__ */