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. float angles[SAMPLE_MAX_COUNT];
  20. u32 ticks_sum;
  21. float angles_sum;
  22. u32 index;
  23. bool full;
  24. }hsample_t;
  25. typedef struct {
  26. bool inited;
  27. float phase_offset;
  28. float mot_poles;
  29. u8 state; // state = A <<2+ B <<1 + C
  30. float low_res_pos; //每个霍尔中断更新一次,60度
  31. s8 dir;
  32. s8 prev_dir;
  33. u32 edge_ticks;
  34. u32 last_delta_ticks;
  35. float elec_angle; //经过插值的高分辨率角度
  36. float elec_angle_vel;
  37. float elec_angle_edge; //霍尔中断的时候,上面插值高分辨率的角度所存
  38. float delta_angle_edge;
  39. float angle_smooth_step;
  40. float angle_smooth_cnt;
  41. float velocity_raw;
  42. float velocity_filted;
  43. float position;
  44. hsample_t samples;
  45. bool b_trns_det; //速度突变
  46. u32 sig_errors;
  47. u32 noise_errors;
  48. }hall_t;
  49. void hall_init(void);
  50. float hall_update_elec_angle(void);
  51. float hall_get_elec_angle(void);
  52. float hall_get_velocity(void);
  53. float hall_get_position(void);
  54. float hall_offset_detect(float *off);
  55. hall_t *hall_get(void);
  56. #endif /* _HALL_SENSOR_H__ */