hall.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include "foc/core/PI_Controller.h"
  7. #define STATE_0 (uint8_t)0
  8. #define STATE_1 (uint8_t)1
  9. #define STATE_2 (uint8_t)2
  10. #define STATE_3 (uint8_t)3
  11. #define STATE_4 (uint8_t)4
  12. #define STATE_5 (uint8_t)5
  13. #define STATE_6 (uint8_t)6
  14. #define STATE_7 (uint8_t)7
  15. #define THETA_NONE (float)0xFFFF
  16. #define SAMPLE_MAX_COUNT 6
  17. typedef struct {
  18. u32 ticks[SAMPLE_MAX_COUNT];
  19. u32 ticks_sum;
  20. u32 index;
  21. u32 filled;
  22. }hsample_t;
  23. typedef struct {
  24. bool inited;
  25. float phase_offset;
  26. float mot_poles;
  27. u8 state; // state = A <<2+ B <<1 + C
  28. float low_res_pos; //每个霍尔中断更新一次,60度
  29. s8 dir;
  30. s8 prev_dir;
  31. s8 dir_set;
  32. u32 edge_ticks;
  33. u32 last_delta_ticks;
  34. float elec_angle; //经过插值的高分辨率角度
  35. float elec_angle_vel;
  36. float elec_angle_edge; //霍尔中断的时候,上面插值高分辨率的角度所存
  37. float delta_angle_edge;
  38. float angle_smooth_step;
  39. float angle_smooth_cnt;
  40. float velocity_filted;
  41. float position;
  42. hsample_t samples;
  43. bool b_trns_det; //速度突变
  44. u32 sig_errors;
  45. u32 noise_errors;
  46. }hall_t;
  47. void hall_init(void);
  48. float hall_update_elec_angle(void);
  49. float hall_get_elec_angle(void);
  50. float hall_get_velocity(void);
  51. float hall_get_vel_counts(void);
  52. float hall_get_position(void);
  53. float hall_offset_detect(float *off);
  54. void hall_set_direction(s8 dir);
  55. hall_t *hall_get(void);
  56. #endif /* _HALL_SENSOR_H__ */