hall_sensor.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. float phase_offset;
  27. }hall_t;
  28. #define SAMPLE_MAX_COUNT 6
  29. typedef struct {
  30. float angle[SAMPLE_MAX_COUNT];
  31. u32 ticks[SAMPLE_MAX_COUNT];
  32. u32 index;
  33. bool full;
  34. }hall_sample_t;
  35. void hall_sensor_init(void);
  36. float hall_sensor_get_theta(void); //return degree
  37. float hall_sensor_get_speed(void); //return rpm
  38. int hall_sensor_calibrate(float current, u16 *hall_table);
  39. #endif /* _HALL_SENSOR_H__ */