فهرست منبع

停机后不动态检测编码器错误AB,编码器的pwm错误继续检测

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 2 سال پیش
والد
کامیت
ea1ff84e5f

+ 7 - 4
Applications/foc/motor/encoder.c

@@ -261,7 +261,7 @@ static void encoder_detect_error(s16 cnt) {
 #endif
 }
 
-float encoder_get_theta(void) {
+float encoder_get_theta(bool detect_err) {
 	if (!g_encoder.b_index_found) {
 		return g_encoder.pwm_angle;
 	}
@@ -277,9 +277,12 @@ float encoder_get_theta(void) {
 		}
 		ENC_ClearUpFlags();
 	}
-
-	encoder_detect_error(cnt);
-	
+	if (detect_err) {
+		encoder_detect_error(cnt);
+	}else {
+		g_encoder.last_delta_cnt = MAX_S16;
+		g_encoder.start_dianostic_cnt = 0;
+	}
     bool snap_to_zero_vel = encoder_run_pll((float)(cnt));
 
 	if (snap_to_zero_vel) {

+ 1 - 1
Applications/foc/motor/encoder.h

@@ -44,7 +44,7 @@ typedef struct {
 
 void encoder_init(void);
 void encoder_init_clear(void);
-float encoder_get_theta(void);
+float encoder_get_theta(bool detect_err);
 float encoder_get_speed(void);
 void encoder_set_direction(s8 direction);
 float encoder_get_vel_count(void);

+ 1 - 1
Applications/foc/motor/hall.c

@@ -123,7 +123,7 @@ static u32 _hall_detect_task(void *args) {
 
 #if 1
 int hall_e_count = 0;
-float hall_sensor_get_theta(void){
+float hall_sensor_get_theta(bool detect_err){
 	hall_e_count++;
 	float angle_add = _sensor_hander.delta_angle_ts;
 	if (_sensor_hander.comp_count > 0) {

+ 1 - 1
Applications/foc/motor/hall.h

@@ -51,7 +51,7 @@ typedef struct {
 
 void hall_sensor_init(void);
 void hall_sensor_clear(void);
-float hall_sensor_get_theta(void); //return degree
+float hall_sensor_get_theta(bool detect_err); //return degree
 float hall_sensor_get_speed(void); //return rpm;
 int hall_offset_increase(int inc);
 s32 *hall_get_table(void);

+ 1 - 1
Applications/foc/motor/motor.c

@@ -1077,7 +1077,7 @@ static void motor_vbus_crit_low(s16 curr_vbus) {
 
 void TIMER_UP_IRQHandler(void){
 	if (!motor.b_start && !PMSM_FOC_Is_Start()) {
-		motor_encoder_update();
+		motor_encoder_update(false);
 		motor_vbus_crit_low((s16)get_vbus_int());
 	}
 }

+ 5 - 5
Applications/foc/motor/motor.h

@@ -114,9 +114,9 @@ void mc_enable_tcs(bool enable);
 
 static __INLINE float motor_encoder_get_angle(void) {
 #ifdef USE_ENCODER_HALL
-	return hall_sensor_get_theta();
+	return hall_sensor_get_theta(true);
 #elif defined (USE_ENCODER_ABI)
-	return encoder_get_theta();
+	return encoder_get_theta(true);
 #else
 	#error "Postion sensor ERROR"
 #endif
@@ -132,11 +132,11 @@ static __INLINE u8 motor_encoder_may_error(void) {
 #endif
 }
 
-static __INLINE void motor_encoder_update(void) {
+static __INLINE void motor_encoder_update(bool detect_err) {
 #ifdef USE_ENCODER_HALL
-	hall_sensor_get_theta();
+	hall_sensor_get_theta(detect_err);
 #elif defined (USE_ENCODER_ABI)
-	encoder_get_theta();
+	encoder_get_theta(detect_err);
 #else
 	#error "Postion sensor ERROR"
 #endif