Browse Source

hall速度降到0的处理

Signed-off-by: kevin <huhui@sharkgulf.com>
kevin 2 years ago
parent
commit
b0e3269c9b
1 changed files with 10 additions and 12 deletions
  1. 10 12
      Applications/foc/motor/hall.c

+ 10 - 12
Applications/foc/motor/hall.c

@@ -166,6 +166,7 @@ void hall_init(void) {
 	g_hall.samples.index = 0;
 	g_hall.samples.filled = 0;
 	g_hall.elec_angle_vel = 0;
+	g_hall.edge_ticks = 0;
 	g_hall.dir_set = g_hall.prev_dir = g_hall.dir = POSITIVE;
 	g_min_delta = 1000000 * 100;
 	for (int i = 0; i < SAMPLE_MAX_COUNT; i++) {
@@ -285,17 +286,13 @@ float hall_update_elec_angle(void) {
 	norm_angle_deg(elec_smooth_angle);
 	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)) {
-		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;
-			g_hall.samples.filled = 0;
-			g_hall.samples.index = 0;
-			g_hall.dir = g_hall.prev_dir = g_hall.dir_set;
-			hall_init_low_pos();
-		}
-		float velocity_raw = g_hall.elec_angle_vel/PHASE_360_DEGREE/g_hall.mot_poles * 60.0f * g_hall.dir;
-		g_hall.velocity_filted = velocity_raw;
+	if ((g_hall.elec_angle_vel > 0.000001f) && (delta_ticks >= HALL_MAX_TIME)) {
+		g_hall.elec_angle_vel = 0;
+		g_hall.samples.filled = 0;
+		g_hall.samples.index = 0;
+		g_hall.velocity_filted = 0;
+		g_hall.dir = g_hall.prev_dir = g_hall.dir_set;
+		hall_init_low_pos();
 	}
 	return hall_get_elec_angle();
 }
@@ -335,10 +332,11 @@ 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 < 200) {
+	if (delta_cnt < 200) { //1200rpm, 30 poles
 		g_hall.noise_errors++;
 		goto hall_end;
 	}
+
 	if (!hall_update_low_pos()) {
 		goto hall_end;
 	}