| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #ifndef _HALL_SENSOR_H__
- #define _HALL_SENSOR_H__
- #include "os/os_types.h"
- #include "bsp/bsp.h"
- #include "math/fix_math.h"
- #include "foc/core/PI_Controller.h"
- #define STATE_0 (uint8_t)0
- #define STATE_1 (uint8_t)1
- #define STATE_2 (uint8_t)2
- #define STATE_3 (uint8_t)3
- #define STATE_4 (uint8_t)4
- #define STATE_5 (uint8_t)5
- #define STATE_6 (uint8_t)6
- #define STATE_7 (uint8_t)7
- #define THETA_NONE (float)0xFFFF
- #define SAMPLE_MAX_COUNT 6
- typedef struct {
- u32 ticks[SAMPLE_MAX_COUNT];
- u32 ticks_sum;
- u32 index;
- u32 filled;
- }hsample_t;
- typedef struct {
- bool inited;
- float phase_offset;
- float mot_poles;
- u8 state; // state = A <<2+ B <<1 + C
- float low_res_pos; //每个霍尔中断更新一次,60度
- s8 dir;
- s8 prev_dir;
- s8 dir_set;
- u32 edge_ticks;
- u32 last_delta_ticks;
- float elec_angle; //经过插值的高分辨率角度
- float elec_angle_vel;
- float elec_angle_edge; //霍尔中断的时候,上面插值高分辨率的角度所存
- float delta_angle_edge;
- float angle_smooth_step;
- float angle_smooth_cnt;
- float velocity_filted;
- float position;
- hsample_t samples;
- bool b_trns_det; //速度突变
- u32 sig_errors;
- u32 noise_errors;
- }hall_t;
- void hall_init(void);
- float hall_update_elec_angle(void);
- float hall_get_elec_angle(void);
- float hall_get_velocity(void);
- float hall_get_vel_counts(void);
- float hall_get_position(void);
- float hall_offset_detect(float *off);
- void hall_set_direction(s8 dir);
- hall_t *hall_get(void);
- #endif /* _HALL_SENSOR_H__ */
|