hall_sensor.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 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. typedef struct {
  17. bool alignmnet;
  18. float theta;
  19. float est_theta;
  20. float e_rpm; //当前的电角度, 单位:RPM
  21. float e_filted_rpm; //滤波后的电角度
  22. u8 state;
  23. u32 ticks;
  24. u32 second;
  25. bool working;
  26. s8 direction;
  27. float degree_per_s; //当前的电角度, 单位:rad/s
  28. float phase_offset;
  29. }hall_t;
  30. #define SAMPLE_MAX_COUNT 6
  31. typedef struct {
  32. float angle[SAMPLE_MAX_COUNT];
  33. u32 ticks[SAMPLE_MAX_COUNT];
  34. u32 index;
  35. bool full;
  36. }hall_sample_t;
  37. void hall_sensor_init(void);
  38. float hall_sensor_get_theta(void); //return degree
  39. float hall_sensor_get_speed(void); //return rpm
  40. float hall_sensor_avg_speed(void);
  41. int hall_sensor_calibrate(float current, u16 *hall_table);
  42. #endif /* _HALL_SENSOR_H__ */