hall_sensor.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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; //每分钟转速,电转速,不是机械转速
  21. u8 state;
  22. u32 ticks;
  23. bool working;
  24. s8 direction;
  25. float degree_per_s; //每秒度, ext: 10度/s
  26. }hall_t;
  27. #define SAMPLE_MAX_COUNT 12
  28. typedef struct {
  29. float angle[SAMPLE_MAX_COUNT];
  30. u32 ticks[SAMPLE_MAX_COUNT];
  31. u32 index;
  32. bool full;
  33. }hall_sample_t;
  34. void hall_sensor_init(void);
  35. float hall_sensor_get_theta(void); //return degree
  36. float hall_sensor_get_speed(void); //return rpm
  37. int hall_sensor_calibrate(float current, u16 *hall_table);
  38. #endif /* _HALL_SENSOR_H__ */