hall_sensor.h 867 B

123456789101112131415161718192021222324252627282930313233343536
  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 e_rpm; //每分钟转速,电转速,不是机械转速
  20. u8 state;
  21. u32 ticks;
  22. bool working;
  23. s8 direction;
  24. float degree_per_s; //每秒度, ext: 10度/s
  25. }hall_t;
  26. void hall_sensor_init(void);
  27. float hall_sensor_get_theta(void); //return degree
  28. float hall_sensor_get_speed(void); //return rpm
  29. int hall_sensor_calibrate(float current, u16 *hall_table);
  30. #endif /* _HALL_SENSOR_H__ */