| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #ifndef _Encoder_H__
- #define _Encoder_H__
- #include "bsp/enc_intf.h"
- #include "foc/core/PI_Controller.h"
- typedef struct {
- bool b_index_found; //I 对齐
- float enc_offset;
- float pwm_angle;
- u32 pwm_count;
- float abi_angle;
- float interpolation;
- float pll_bandwidth_shadow;
- float pll_bandwidth;
- PLL_t est_pll;
- bool b_timer_ov;
- u32 cpr;
- u32 last_cnt;
- u32 b_index_cnt;
- u32 last_us;
- s8 enc_dir; //encoder count dir UP or DOWN
- s8 direction; //motor running dir, 逆时针 正,顺时针负
- u16 p_dir_cnt;
- u16 n_dir_cnt;
- float est_vel_counts; //每秒多少个计数
- float est_angle_counts;
- float rpm;
- }encoder_t;
- #define ENC_MAX_RES 4096
- /*min. 490 Hz, max 603 Hz*/
- #define ENC_PWM_Max_P (1.0f/490.0f)
- #define ENC_PWM_Min_P (1.0f/603.0f)
- #define ENC_PWM_MAX_RES 4119.0F
- #define ENC_PWM_INIT_WIDTH 12.0F //PWM 起始宽度
- #define ENC_PWM_ERROR_WIDTH 4.0f //PWM 指示错误的宽度
- #define ENC_PWM_END_WIDTH 0.0F
- #define ENC_PWM_Error_P (ENC_PWM_INIT_WIDTH/ENC_PWM_MAX_RES)
- #define ENC_PWM_MIN_duty ((ENC_PWM_INIT_WIDTH + ENC_PWM_ERROR_WIDTH + ENC_PWM_END_WIDTH)/ENC_PWM_MAX_RES)
- #define ENC_Duty_2_Pluse_Nr(duty) (duty * ENC_PWM_MAX_RES - (ENC_PWM_INIT_WIDTH + ENC_PWM_ERROR_WIDTH + ENC_PWM_END_WIDTH)) //通过占空比计算有几个脉冲
- #define ENC_Pluse_Nr_2_angle(Nr) (360.0f/(float)ENC_MAX_RES * (Nr))
- void encoder_init(void);
- void encoder_init_clear(s8 direction);
- float encoder_get_theta(void);
- float encoder_get_speed(void);
- void encoder_detect_offset(float angle);
- void encoder_set_direction(s8 direction);
- #endif /* _Encoder_H__ */
|