Преглед на файлове

add hall functions

Signed-off-by: kevin <huhui@sharkgulf.com>
kevin преди 2 години
родител
ревизия
ba956a8e25
променени са 2 файла, в които са добавени 33 реда и са изтрити 8 реда
  1. 14 0
      Applications/foc/motor/motor.c
  2. 19 8
      Applications/foc/motor/motor.h

+ 14 - 0
Applications/foc/motor/motor.c

@@ -746,6 +746,12 @@ bool mc_start_epm_move(epm_dir_t dir, bool is_command) {
 		if (!mot_contrl_is_start(&motor.controller)) {
 			mot_contrl_start(&motor.controller, motor.mode);
 			mc_gear_mode_set(false);
+			motor_encoder_reinit();
+			if (dir == EPM_Dir_Back) {
+				motor_encoder_set_direction(NEGATIVE);
+			}else {
+				motor_encoder_set_direction(POSITIVE);
+			}
 			pwm_enable_channel();
 		}else if (mot_contrl_is_auto_holdding(&motor.controller)) {
 			mc_auto_hold(false);
@@ -1643,6 +1649,14 @@ static void mc_motor_runstop(void) {
 		mot_contrl_start(&motor.controller, motor.mode);
 		mc_gear_mode_set(true);
 		throttle_torque_reset();
+		motor_encoder_reinit();
+		if (motor.b_epm) {
+			if (motor.epm_dir == EPM_Dir_Back) {
+				motor_encoder_set_direction(NEGATIVE);
+			}else {
+				motor_encoder_set_direction(POSITIVE);
+			}
+		}
 		pwm_enable_channel();
 		g_meas_foc.first = true;
 		motor.foc_start_cnt ++;

+ 19 - 8
Applications/foc/motor/motor.h

@@ -153,7 +153,7 @@ static __INLINE foc_t *foc(void) {
 
 static __INLINE float motor_encoder_get_angle(void) {
 #ifdef USE_ENCODER_HALL
-	return hall_sensor_get_theta(true);
+	return hall_update_elec_angle();
 #elif defined (USE_ENCODER_ABI)
 	return encoder_get_theta(true);
 #else
@@ -173,7 +173,7 @@ static __INLINE u8 motor_encoder_may_error(void) {
 
 static __INLINE void motor_encoder_update(bool detect_err) {
 #ifdef USE_ENCODER_HALL
-	hall_sensor_get_theta(detect_err);
+	hall_update_elec_angle();
 #elif defined (USE_ENCODER_ABI)
 	encoder_get_theta(detect_err);
 #else
@@ -183,7 +183,7 @@ static __INLINE void motor_encoder_update(bool detect_err) {
 
 static __INLINE float motor_encoder_get_speed(void) {
 #ifdef USE_ENCODER_HALL
-	return hall_sensor_get_speed();
+	return hall_get_velocity();
 #elif defined (USE_ENCODER_ABI)
 	return encoder_get_speed();
 #else
@@ -193,7 +193,7 @@ static __INLINE float motor_encoder_get_speed(void) {
 
 static __INLINE float motor_encoder_get_vel_count(void) {
 #ifdef USE_ENCODER_HALL
-	return 0;
+	return hall_get_vel_counts();
 #elif defined (USE_ENCODER_ABI)
 	return encoder_get_vel_count();
 #else
@@ -203,7 +203,7 @@ static __INLINE float motor_encoder_get_vel_count(void) {
 
 static __INLINE float motor_encoder_get_position(void) {
 #ifdef USE_ENCODER_HALL
-	return 0;
+	return hall_get_position();
 #elif defined (USE_ENCODER_ABI)
 	return encoder_get_position();
 #else
@@ -214,7 +214,7 @@ static __INLINE float motor_encoder_get_position(void) {
 
 static __INLINE void motor_encoder_init(void) {
 #ifdef USE_ENCODER_HALL
-	hall_sensor_init();
+	hall_init();
 #elif defined (USE_ENCODER_ABI)
 	encoder_init();
 #else
@@ -224,7 +224,7 @@ static __INLINE void motor_encoder_init(void) {
 
 static __INLINE void motor_encoder_start(bool start) {
 #ifdef USE_ENCODER_HALL
-	hall_sensor_clear(direction);
+	hall_init();
 #elif defined (USE_ENCODER_ABI)
 	encoder_init_clear();
 #else
@@ -232,6 +232,17 @@ static __INLINE void motor_encoder_start(bool start) {
 #endif
 }
 
+static __INLINE void motor_encoder_reinit(void) {
+#ifdef USE_ENCODER_HALL
+	hall_init();
+#elif defined (USE_ENCODER_ABI)
+	//do nothing
+#else
+	#error "Postion sensor ERROR"
+#endif
+}
+
+
 static __INLINE float motor_encoder_zero_phase_detect(float *enc_off){
 #ifdef USE_ENCODER_HALL
 	return 0.0f;
@@ -246,7 +257,7 @@ static __INLINE void motor_encoder_set_direction(s8 dir) {
 #ifdef USE_ENCODER_HALL
 	hall_set_direction(dir);
 #elif defined (USE_ENCODER_ABI)
-	encoder_set_direction(dir);
+	//encoder_set_direction(dir);
 #else
 	#error "Postion sensor ERROR"
 #endif