hall_sensor.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef _HALL_SENSOR_H__
  2. #define _HALL_SENSOR_H__
  3. #include "libs/types.h"
  4. #include "hal/hal.h"
  5. #define NEGATIVE (int8_t)-1
  6. #define POSITIVE (int8_t)1
  7. #define PHASE_60_DEGREE (60.0f)
  8. #define PHASE_120_DEGREE (120.0f)
  9. #define PHASE_180_DEGREE (180.0f)
  10. #define PHASE_240_DEGREE (240.0f)
  11. #define PHASE_300_DEGREE (300.0f)
  12. #define PHASE_360_DEGREE (360.0f)
  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. typedef struct {
  23. bool alignmnet;
  24. float theta;
  25. float est_theta;
  26. float e_rpm; //当前的电角度, 单位:RPM
  27. float e_filted_rpm; //滤波后的电角度
  28. u8 state;
  29. u32 ticks;
  30. u32 second;
  31. bool working;
  32. s8 direction;
  33. float degree_per_s; //当前的电角度, 单位:rad/s
  34. float phase_offset;
  35. bool is_override_theta;
  36. float override_theta;
  37. }hall_t;
  38. #define SAMPLE_MAX_COUNT 6
  39. typedef struct {
  40. float angle[SAMPLE_MAX_COUNT];
  41. u32 ticks[SAMPLE_MAX_COUNT];
  42. u32 index;
  43. bool full;
  44. }hall_sample_t;
  45. void hall_sensor_init(void);
  46. float hall_sensor_get_theta(void); //return degree
  47. float hall_sensor_get_speed(void); //return rpm
  48. float hall_sensor_avg_speed(void);
  49. int hall_sensor_calibrate(float voltage, u16 *hall_table);
  50. void hall_sensor_set_theta(bool override, float theta);
  51. #endif /* _HALL_SENSOR_H__ */