소스 검색

解决hall时间计算错误的问题

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 3 년 전
부모
커밋
bfc1bdbc61
4개의 변경된 파일21개의 추가작업 그리고 16개의 파일을 삭제
  1. 10 4
      Applications/bsp/timer_count32.c
  2. 2 2
      Applications/foc/core/PMSM_FOC_Core.c
  3. 8 9
      Applications/foc/motor/hall.c
  4. 1 1
      Applications/foc/motor/hall.h

+ 10 - 4
Applications/bsp/timer_count32.c

@@ -1,6 +1,9 @@
 #include "bsp/bsp.h"
 #include "timer_count32.h"
 #include "os/os_task.h"
+//#define ENABLE_32TIMER 
+
+#ifdef ENABLE_32TIMER
 static void init_master_timer(void);
 static void init_slave_timer(void);
 
@@ -81,14 +84,17 @@ static __inline__ u32 _timer_count32_get(void) {
 #endif
 }
 
-
+#else
+void timer_count32_init(void){
+}
+#endif
 u32 timer_count32_get(void) {
-	return _timer_count32_get();
+	return task_ticks_abs();
 }
 
 u32 timer_count32_delta(u32 now, u32 prev) {
 	if (now >= prev) {
-		return (now - prev);
+		return (now - prev)/120;
 	}
-	return (0xFFFFFFFF + prev - now + 1);
+	return ((u32)0xFFFFFFFF - prev + now + 1)/120;
 }

+ 2 - 2
Applications/foc/core/PMSM_FOC_Core.c

@@ -181,10 +181,10 @@ void PMSM_FOC_Schedule(void) {
 
 	SVM_Duty_Fix(&vAB, _gFOC_Ctrl.in.s_vDC, FOC_PWM_Half_Period, &_gFOC_Ctrl.out);
 
-	if (_g_ctl_count++ % 10 == 0) {
+	if (_g_ctl_count++ % 5 == 0) {
 		//plot_3data16(_gFOC_Ctrl.out.n_Duty[0], _gFOC_Ctrl.out.n_Duty[1], _gFOC_Ctrl.out.n_Duty[2]);
 		//plot_3data16(test_motangle>>5, _gFOC_Ctrl.in.s_motAngle>>5, get_hall_stat(9)*60);
-		plot_3data16(_gFOC_Ctrl.in.s_iABC[0], _gFOC_Ctrl.in.s_iABC[1], _gFOC_Ctrl.in.s_motAngle>>5);
+		plot_3data16(_gFOC_Ctrl.in.s_iABC[0], get_hall_stat(9)*60, _gFOC_Ctrl.in.s_motAngle>>5);
 	}
 	phase_current_point(&_gFOC_Ctrl.out);
 

+ 8 - 9
Applications/foc/motor/hall.c

@@ -19,7 +19,7 @@ static u32 _hall_detect_task(void *args);
 static void _hall_init_el_angle(void);
 
 
-#define HALL_PLACE_OFFSET (220 << 19) //(345) //315
+#define HALL_PLACE_OFFSET (230 << 19) //(345) //315
 /* 
 4,5,1,3,2,6,4
 */
@@ -92,13 +92,11 @@ static void hall_sensor_default(void) {
 	}
 	_sensor_hander.manual_angle = 0x3FF;
 	_hall_init_el_angle();
-	hall_debug_log();
 }
 
 void hall_sensor_init(void) {
-	mc_hall_init();
 	hall_sensor_default();
-	
+	mc_hall_init();
 	shark_task_create(_hall_detect_task, NULL);
 }
 
@@ -106,13 +104,13 @@ void hall_sensor_clear(void) {
 	hall_sensor_default();
 }
 
-
 static u32 _hall_detect_task(void *args) {
 	if (_sensor_hander.el_speed != 0) {
 		u32 ticks_now = timer_count32_get();
-		u32 delta_us = timer_count32_delta(ticks_now, _sensor_hander.hall_ticks);
-		if (delta_us >= (1200*1000)) {
-			hall_sensor_clear();
+		if (ticks_now > _sensor_hander.hall_ticks) {
+			if (timer_count32_delta(ticks_now, _sensor_hander.hall_ticks) > 2000*1000) {
+				hall_sensor_clear();
+			}
 		}
 	}
 	return 0;
@@ -429,13 +427,14 @@ void HALL_IRQHandler(void) {
 		_sensor_hander.comp_count = 0;//(s32)(delta_us/FOC_CTRL_US)/2;
 		_sensor_hander.angle_comp_ts = 0;//estimate_delta_angle/_sensor_hander.comp_count;
 		_sensor_hander.estimate_el_angle = theta_now;
+		delta_us = _hall_get_angle_ticks();
 	}else {
 		_sensor_hander.comp_count = 0;
 		_sensor_hander.angle_comp_ts = 0;
 		_sensor_hander.estimate_el_angle = theta_now;
 	}
 	_sensor_hander.estimate_delta_angle = 0;
-	_sensor_hander.delta_angle_ts = next_delta_angle/(delta_us/FOC_CTRL_US);
+	_sensor_hander.delta_angle_ts = (next_delta_angle/((delta_us<<6)/FOC_CTRL_US))<<6;
 	_sensor_hander.next_delta_angle = next_delta_angle;
 	_sensor_hander.measured_el_angle = theta_now;
 

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

@@ -26,7 +26,7 @@
 #define STATE_7 (uint8_t)7
 
 #define THETA_NONE        (float)0xFFFF
-#define SAMPLE_MAX_COUNT 16
+#define SAMPLE_MAX_COUNT 4
 
 typedef struct {
 	u32        	ticks[SAMPLE_MAX_COUNT];