hall.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef _HALL_SENSOR_H__
  2. #define _HALL_SENSOR_H__
  3. #include "os/os_types.h"
  4. #include "bsp/bsp.h"
  5. #include "math/fix_math.h"
  6. #define STATE_0 (uint8_t)0
  7. #define STATE_1 (uint8_t)1
  8. #define STATE_2 (uint8_t)2
  9. #define STATE_3 (uint8_t)3
  10. #define STATE_4 (uint8_t)4
  11. #define STATE_5 (uint8_t)5
  12. #define STATE_6 (uint8_t)6
  13. #define STATE_7 (uint8_t)7
  14. #define THETA_NONE (float)0xFFFF
  15. #define SAMPLE_MAX_COUNT 16
  16. typedef struct {
  17. u32 ticks[SAMPLE_MAX_COUNT];
  18. float angles[SAMPLE_MAX_COUNT];
  19. u32 ticks_sum;
  20. float angles_sum;
  21. u32 index;
  22. bool full;
  23. }hall_sample_t;
  24. typedef struct {
  25. float estimate_el_angle; //60度区间内的估计电角度
  26. float estimate_delta_angle;
  27. float measured_el_angle; //hall测量到的电角度
  28. float next_delta_angle;
  29. float delta_angle_ts; //每个控制周期角度的增加量,通过上次的速度计算得到
  30. float angle_comp_ts; //每个控制周期角度增加的补偿量,主要用在加减速,hall角度和60度有偏差的情况
  31. int comp_count;
  32. float immediately_el_speed; //当前的即时速度,主要用来判断电机转动是否达到稳定
  33. float el_speed; //当前的平均效果的电角速度, 单位:rad/s
  34. float rpm; //当前的电速度, 单位:RPM
  35. bool trns_detect; //速度变化超过阈值
  36. u8 hall_stat;
  37. u32 hall_ticks;
  38. s8 direction;
  39. s8 running_dir;
  40. float phase_offset;
  41. hall_sample_t samples;
  42. u32 sensor_error;
  43. float manual_angle;
  44. s32 angle_table[8];
  45. }hall_t;
  46. void hall_sensor_init(void);
  47. void hall_sensor_clear(void);
  48. float hall_sensor_get_theta(void); //return degree
  49. float hall_sensor_get_speed(void); //return rpm;
  50. int hall_offset_increase(int inc);
  51. s32 *hall_get_table(void);
  52. bool hall_detect_angle_finish(void);
  53. void hall_detect_angle(s16 angle);
  54. bool hall_detect_offset_finish(void);
  55. void hall_detect_offset(s16 angle);
  56. void hall_set_direction(s8 direction);
  57. #endif /* _HALL_SENSOR_H__ */