Ver Fonte

hall实现autohold使用的xxxx_get_vel_count接口

Signed-off-by: kevin <huhui@sharkgulf.com>
kevin há 2 anos atrás
pai
commit
db37ae1296

+ 7 - 6
Applications/foc/motor/hall.c

@@ -30,7 +30,6 @@ static hall_t g_hall;
 #define us_2_s(tick) ((float)tick / 1000000.0f) //s32q14
 #define HALL_MAX_TIME 1000000UL
 
-static u32 stop_cnt = 0;
 static u32 g_delta_cnt = 0;
 static u32 g_trns_cnt = 0;
 static u32 g_min_delta;
@@ -112,7 +111,7 @@ static float __INLINE hall_elec_angle_vel(void){
 
 void hall_debug_log(void) {
 	sys_debug("angle dir %d, stat %d, lowres %f, err %d,%d\n", g_hall.dir, g_hall.state, g_hall.low_res_pos, g_hall.sig_errors, g_hall.noise_errors);
-	sys_debug("D: %d,%d,%d,%d\n", stop_cnt, g_delta_cnt, g_trns_cnt, g_min_delta);
+	sys_debug("D: %d,%d,%d\n", g_delta_cnt, g_trns_cnt, g_min_delta);
 	sys_debug("RPM: %f\n", hall_get_velocity());
 }
 
@@ -139,7 +138,6 @@ void hall_init(void) {
 		gpio_hall_init();
 	}
 	hall_init_low_pos();
-	stop_cnt = 0;
 }
 
 void  hall_set_direction(s8 dir) {
@@ -243,7 +241,6 @@ float hall_update_elec_angle(void) {
 	g_hall.elec_angle = elec_smooth_angle;
 	g_hall.position += g_hall.elec_angle_vel * FOC_CTRL_US / g_hall.mot_poles;
 	if ((g_hall.samples.filled > 1) && (delta_ticks / g_hall.last_delta_ticks >= 1.4f)) {
-		stop_cnt ++;
 		g_hall.elec_angle_vel = g_hall.elec_angle_vel * 0.95f;
 		if (g_hall.elec_angle_vel < 30) {
 			g_hall.elec_angle_vel = 0;
@@ -254,6 +251,10 @@ float hall_update_elec_angle(void) {
 	return hall_get_elec_angle();
 }
 
+float hall_get_vel_counts(void) {
+	return g_hall.elec_angle_vel/PHASE_60_DEGREE * g_hall.dir;
+}
+
 float hall_get_velocity(void) {
 	return g_hall.velocity_filted;
 }
@@ -280,12 +281,12 @@ static __INLINE void hall_calc_mot_velocity(u32 delta_cnt) {
 float hall_offset_detect(float *off) {
 	return 0.0f;
 }
-extern float foc_observer_sensorless_angle(void);
+
 void HALL_IRQHandler(void) {
 	g_delta_cnt++;
 	u32 mask = cpu_enter_critical();
 	u32 delta_cnt = hall_delta_us(g_hall.edge_ticks);
-	if (delta_cnt < 300) {
+	if (delta_cnt < 200) {
 		g_hall.noise_errors++;
 		goto hall_end;
 	}

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

@@ -53,6 +53,7 @@ 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);

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

@@ -189,7 +189,7 @@ static __INLINE float motor_encoder_get_speed(void) {
 
 static __INLINE float motor_encoder_get_vel_count(void) {
 #ifdef CONFIG_USE_ENCODER_HALL
-	return hall_get_velocity();
+	return hall_get_vel_counts();
 #elif defined (CONFIG_USE_ENCODER_ABI)
 	return encoder_get_vel_count();
 #else