瀏覽代碼

update

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 4 年之前
父節點
當前提交
5d97bbd1e1

+ 21 - 6
Application/App/app.c

@@ -1,17 +1,32 @@
 #include "app/app.h"
 #include "foc/foc_stm.h"
+#include "foc/gas_sensor.h"
+#include "foc/foc_api.h"
+#include "libs/task.h"
 
+static u32 app_task(void);
+static void gas_sample_handler(timer_t *t);
+static timer_t _gas_sample_timer = {.handler = gas_sample_handler};
 void app_init(void){
-
+	task_start(app_task, 5);
+	timer_post(&_gas_sample_timer, 50);
 }
 
 void start_stop_handler(void) {
-	FOCState s = foc_stm_state();
-	if (s == IDLE) {
-		foc_set_current_ramp(-20.0f);
-		foc_start_motor();
+	if (!foc_is_ready()) {
+		foc_set_ready(true);
 	}else {
-		foc_stop_motor();
+		foc_set_ready(false);
 	}
 }
 
+static u32 app_task(void) {
+	gas_sample_voltage();
+	return 1;//隔5ms执行一次
+}
+
+static void gas_sample_handler(timer_t *t) {
+	float v = gas_get_value();
+	foc_set_ref_speed(v * MAX_SPEED_RPM);
+	timer_post(&_gas_sample_timer, 200);
+}

+ 1 - 1
Application/Bsp/serial.c

@@ -86,7 +86,7 @@ static void uart_rx_poll(uart_t *uart) {
 }
 
 static u32 uart_poll_task(void){
-	uart_rx_poll(&uart2);
+	//uart_rx_poll(&uart2);
 	return 0;
 }
 

+ 1 - 1
Application/FOC/PI_Controller.c

@@ -2,7 +2,7 @@
 
 float pi_control(PI_ctrl_t *pi, float error){
 	float output = 0.0f;
-	/* »ý·Ö¿¹±¥ºÍ */
+	/* 积分抗饱和处� */
 	if (pi->output > pi->max_output) {
 		if (error < 0) {
 			pi->i_errors += error;

+ 41 - 29
Application/FOC/foc_api.c

@@ -33,14 +33,24 @@ void foc_init(void) {
 }
 
 static void foc_defulat_value(void){
-	memset(&mFOC, 0, sizeof(mFOC));
 	mFOC.state = IDLE;
 	mFOC.mosGate = false;
 	mFOC.vbus = MAX_VBUS_VOLTAGE;
 	mFOC.state = IDLE;
 	mFOC.mode = FOC_MODE_OPEN_LOOP;
+	mFOC.alpha_beta.alpha = 0;
+	mFOC.alpha_beta.beta = 0;
+	mFOC.dq_ref.Id = 0;
+	mFOC.dq_ref.Iq = 0;
+	mFOC.foc_fault = foc_success;
+	mFOC.is_ready = false;
+	mFOC.rpm_ref = -1;
+	memset(&mFOC.phase_time, 0, sizeof(mFOC.phase_time));
+	mFOC.sector = 0;
+	mFOC.dq_v.Id = 0;
+	mFOC.dq_v.Iq = 0;
 	phase_current_init(&mFOC.current_samp);
-	ramp_ctrl_init(&mFOC.start_ramp);
+	ramp_ctrl_init(&mFOC.voltage_ramp);
 	ramp_ctrl_init(&mFOC.current_ramp);
 	ramp_ctrl_init(&mFOC.speed_ramp);
 	pi_clear(&mFOC.PI_id);
@@ -64,57 +74,59 @@ void foc_clear(void) {
 }
 
 u32 foc_get_speed(void) {
-	return abs(hall_sensor_get_speed()/mFOC.motor_p.poles);
+	float speed = hall_sensor_avg_speed()/(mFOC.motor_p.poles);
+	//printf("avg speed %f, %d\n", speed, mFOC.motor_p.poles);
+	return abs(speed);
 }
 
 bool foc_is_ready(void){
 	return mFOC.is_ready;
 }
 
-void foc_set_ready(bool ready) {
-	mFOC.is_ready = ready;
+foc_fault_t foc_set_ready(bool ready) {
+	if (ready == foc_is_ready()) {
+		return foc_success;
+	}
+	normal_task_enable(false);
+	if (foc_stm_nextstate(ready?START:ANY_STOP) == NoError) {
+		mFOC.is_ready = ready;
+		normal_task_enable(true);
+		return foc_success;
+	}	
+	normal_task_enable(true);
+	return foc_not_allowed;
 }
 
 
-void foc_set_current_ramp(float final){
-	ramp_set_target(&mFOC.current_ramp, mFOC.dq_v.Vq, final, START_RAMP_DURATION);
+void foc_set_voltage_ramp(float final){
+	printf("voltage %f\n", final);
+	ramp_set_target(&mFOC.voltage_ramp, mFOC.dq_v.Vq, final, START_RAMP_DURATION);
 }
 
 void foc_set_speed_ramp(u16 rpm){
 	ramp_set_target(&mFOC.speed_ramp, foc_get_speed(), rpm, SPEED_RAMP_DURATION);
 }
 
+/*
 void foc_set_start_ramp(float v) {
-	ramp_set_target(&mFOC.start_ramp, mFOC.dq_v.Vq, v, START_RAMP_DURATION);
-}
+	ramp_set_target(&mFOC.voltage_ramp, mFOC.dq_v.Vq, v, START_RAMP_DURATION);
+}*/
 
 void foc_set_ref_speed(u16 rpm) {
 	normal_task_enable(false);
+	if (mFOC.state == IDLE || mFOC.state == ANY_STOP) {
+		normal_task_enable(true);
+		return;
+	}
 	mFOC.rpm_ref = rpm;
 	if (mFOC.mode == FOC_MODE_OPEN_LOOP) {
-		foc_set_start_ramp(speed_to_voltage(rpm));
-		ramp_exc(&mFOC.start_ramp);
-	}else if (mFOC.mode == FOC_MODE_PI_CURRENT) {
-		foc_set_current_ramp(speed_to_current(rpm));
-		ramp_exc(&mFOC.current_ramp);
+		foc_set_voltage_ramp(speed_to_voltage(rpm));
+		ramp_set_target(&mFOC.speed_ramp, rpm, rpm, SPEED_RAMP_DURATION);
+		ramp_exc(&mFOC.voltage_ramp);
 	}
 	normal_task_enable(true);
 }
 
-foc_fault_t api_set_ready(bool ready) {
-	if (ready == foc_is_ready()) {
-		return foc_success;
-	}
-	normal_task_enable(false);
-	if (foc_stm_nextstate(ready?START:ANY_STOP) == NoError) {
-		foc_set_ready(ready);
-		normal_task_enable(true);
-		return foc_success;
-	}	
-	normal_task_enable(true);
-	return foc_not_allowed;
-}
-
 foc_fault_t foc_start_motor(void){
 	return foc_stm_nextstate(START);
 }
@@ -167,13 +179,13 @@ void foc_overide_set_theta(float theta){
 void foc_overide_set_vdq(float d, float q){
 	mFOC.override.vdq.Vd = d;
 	mFOC.override.vdq.Vq = q;
+	//printf("%f, %f\n", d, q);
 }
 
 float foc_get_vbus_voltage(void){
 	return mFOC.vbus;
 }
 static u32 foc_measure_task(void){
-	gas_sample_voltage();
 	vbus_sample_voltage();
 	ntc_sensor_sample();
 	LowPass_Filter(mFOC.vbus, vbus_get_voltage(), 0.1f);

+ 3 - 3
Application/FOC/foc_api.h

@@ -14,14 +14,14 @@ void foc_overide_theta(bool enable);
 void foc_overide_vdq(bool enable);
 void foc_overide_set_theta(float theta);
 void foc_overide_set_vdq(float d, float q);
-void foc_set_current_ramp(float final);
+void foc_set_voltage_ramp(float final);
 void foc_set_speed_ramp(u16 rpm);
-void foc_set_start_ramp(float v);
+//void foc_set_start_ramp(float v);
 void foc_current_calibrate(void);
 u32 foc_get_speed(void);
 float foc_get_vbus_voltage(void);
 bool foc_is_ready(void);
-void foc_set_ready(bool ready);
+foc_fault_t foc_set_ready(bool ready);
 void foc_set_ref_speed(u16 rpm);
 float speed_to_voltage(u16 rpm);
 float speed_to_current(u16 rpm);

+ 24 - 16
Application/FOC/foc_core.c

@@ -10,7 +10,6 @@
 #include "circle_limitation.h"
 #include "svpwm.h"
 
-
 motor_foc_t mFOC = {
 	.motor_p = {
 		.poles = 2,
@@ -21,20 +20,20 @@ motor_foc_t mFOC = {
 		.b_emf = 4.332566f,
 	},
 	.PI_id = {
-		.Kp_gain = 5,
-		.Ki_gain = 100,
+		.Kp_gain = 9,
+		.Ki_gain = 1071,
 		.max_output = MAX_VBUS_VOLTAGE,
 		.min_output = -MAX_VBUS_VOLTAGE,		
 	},
 	.PI_iq = {
-		.Kp_gain = 5,
-		.Ki_gain = 100,
+		.Kp_gain = 10,
+		.Ki_gain = 1080,
 		.max_output = MAX_VBUS_VOLTAGE,
 		.min_output = -MAX_VBUS_VOLTAGE,
 	},
 	.PI_speed = {
-		.Kp_gain = 5,
-		.Ki_gain = 100,
+		.Kp_gain = 1,
+		.Ki_gain = 200,
 		.max_output = MAX_CURRENT,
 		.min_output = -MAX_CURRENT,
 	},	
@@ -68,10 +67,13 @@ static void __inline foc_update_theta(motor_foc_t *foc) {
 #endif
 
 
-static void __inline Foc_Current_PI_Contrl(motor_foc_t *foc, dq_t *sampled, dq_t *ref_out) {
+static void __inline Foc_Calc_Voltage(motor_foc_t *foc, dq_t *sampled, dq_t *ref_out) {
+	//float vd = pi_control(&foc->PI_id, foc->dq_ref.Id - sampled->Id);
+	//float vq = pi_control(&foc->PI_iq, foc->dq_ref.Iq - sampled->Iq);
 	if (foc->mode == FOC_MODE_PI_CURRENT || foc->mode == FOC_MODE_PI_FULL) {
 		ref_out->Vd = pi_control(&foc->PI_id, foc->dq_ref.Id - sampled->Id);
 		ref_out->Vq = pi_control(&foc->PI_iq, foc->dq_ref.Iq - sampled->Iq);
+		//printf("vd = %f, vq = %f\n", vd, vq);
 	}else {
 		ref_out->Vd = foc->dq_ref.Vd;
 		ref_out->Vq = foc->dq_ref.Vq;
@@ -160,7 +162,7 @@ void FOC_Fast_Task(motor_foc_t *foc){
 	/* alpha-beta坐标系到D-Q旋转坐标系 */
 	Park(&sample_ab, foc->motor_s.theta, &sample_dq);
 	/* 电流环,输出电压给SVPWM */
-	Foc_Current_PI_Contrl(foc, &sample_dq, &v_dq);
+	Foc_Calc_Voltage(foc, &sample_dq, &v_dq);
 	/* 确保电压在6个扇区的内切圆中 */
 	CirCle_Limitation_Process(&v_dq, foc->vbus, 0.95f);
 	/* d-q坐标系到alpha-beta坐标系,输出给svpwm */
@@ -181,12 +183,18 @@ void FOC_Fast_Task(motor_foc_t *foc){
 
 /* 计算电流环的参考输入 */
 void Foc_Calc_Current_Ref(motor_foc_t *foc) {
+	static int count = 0;
+	float speed_ref = ramp_get_target(&foc->speed_ramp);
+	float speed_feedback = foc_get_speed();
+	float vq_out = pi_control(&foc->PI_speed, speed_ref - speed_feedback);	
 	if (foc->mode == FOC_MODE_PI_SPEED || foc->mode == FOC_MODE_PI_FULL){
-		float speed_ref = ramp_get_target(&foc->speed_ramp);
-		float speed_feedback = foc_get_speed();
-		float vq_out = pi_control(&foc->PI_speed, speed_ref - speed_feedback);
 		foc->dq_ref.Iq = vq_out;
 		foc->dq_ref.Id = 0.0f; //if MTPA used, d is not 0
+		if (((count) % 10) == 0) {
+			printf("vq_out = %f, %f, %f\n", vq_out, speed_ref, speed_feedback);
+		}
+		count++;
+		
 	}else {
 		foc->dq_ref.Iq = ramp_get_target(&foc->current_ramp);
 		foc->dq_ref.Id = 0.0f; //if MTPA used, d is not 0
@@ -194,15 +202,15 @@ void Foc_Calc_Current_Ref(motor_foc_t *foc) {
 }
 
 void Foc_Speed_Ramp(motor_foc_t *foc){
-	if (foc->rpm_ref >= 0 && foc->mode != FOC_MODE_PI_CURRENT){
+	if (foc->rpm_ref >= 0 && foc->mode != FOC_MODE_OPEN_LOOP){
 		u16 current_rpm = foc_get_speed();
 		u16 ref_rpm = foc->rpm_ref;
 		foc->rpm_ref = -1;
 		
-		if (ref_rpm + 60 < current_rpm){
-			ramp_set_target(&foc->current_ramp, foc->dq_ref.Iq, speed_to_current(ref_rpm), SPEED_RAMP_DURATION);
+		if (ref_rpm + RPM_FOR_CLOSE_LOOP < current_rpm){
+			ramp_set_target(&foc->voltage_ramp, foc->dq_ref.Vq, speed_to_voltage(ref_rpm), SPEED_RAMP_DURATION);
 			ramp_exc(&foc->current_ramp);
-			foc->mode = FOC_MODE_PI_CURRENT;
+			foc->mode = FOC_MODE_OPEN_LOOP;
 		}
 	}
 }

+ 13 - 8
Application/FOC/foc_stm.c

@@ -56,6 +56,9 @@ foc_fault_t foc_stm_nextstate(FOCState state) {
 
 void FOC_Normal_Task(motor_foc_t *foc) {
 	switch (foc->state) {
+		case IDLE:
+			foc->mode = FOC_MODE_OPEN_LOOP;
+			break;
 		case START:
 			PWM_TurnOnLowSides();
 			foc_stm_nextstate(CURRENT_CALIBRATE);
@@ -67,21 +70,22 @@ void FOC_Normal_Task(motor_foc_t *foc) {
 		case READY_TO_RUN:
 			foc_pwm_start(true);
 			foc_stm_nextstate(RAMPING_START);
-			ramp_exc(&foc->current_ramp);
+			ramp_exc(&foc->voltage_ramp);
 			foc_overide_vdq(true);
 			break;
 		case RAMPING_START:
-			foc_overide_set_vdq(0.0f, ramp_get_target(&foc->current_ramp));
+			foc_overide_set_vdq(0.0f, ramp_get_target(&foc->voltage_ramp));
+			printf("target %f\n", ramp_get_target(&foc->voltage_ramp));
 			if (foc_get_speed() >= RPM_FOR_CLOSE_LOOP){
-				foc_stm_nextstate(CLOSED_LOOP);
-				ramp_clear(&foc->current_ramp);
-				foc_overide_vdq(false);
+				//foc_stm_nextstate(CLOSED_LOOP);
+				//foc_overide_vdq(false);
 			}
 			break;
 		case CLOSED_LOOP:
 			Foc_Speed_Ramp(foc);
 			foc->mode = FOC_MODE_PI_FULL;
 			foc_stm_nextstate(RUNNING);
+			ramp_clear(&foc->voltage_ramp);
 			break;
 		case RUNNING:
 			Foc_Speed_Ramp(foc);
@@ -90,13 +94,14 @@ void FOC_Normal_Task(motor_foc_t *foc) {
 				foc_stm_nextstate(ANY_STOP);
 				break;
 			}
+			/*
 			if (foc_get_speed() <= RPM_FOR_CLOSE_LOOP){
-				foc_set_current_ramp(speed_to_current(foc_get_speed()));
-				ramp_exc(&foc->current_ramp);
+				foc_set_voltage_ramp(speed_to_voltage(foc_get_speed()));
+				ramp_exc(&foc->voltage_ramp);
 				foc_stm_nextstate(RAMPING_START);
 				foc->mode = FOC_MODE_OPEN_LOOP;
 				foc_overide_vdq(true);
-			}
+			}*/
 			break;
 		case ANY_STOP:
 			ramp_clear(&foc->current_ramp);

+ 8 - 8
Application/FOC/foc_type.h

@@ -21,12 +21,12 @@ typedef struct _dqaix {
 }dq_t;
 
 typedef struct _motor_p {
-	u8   poles; //������
-	float  ld;    //q ����
-	float  lq;    //d ����
-	float  rs;     //����
-	float  flux_linkage; //����
-	float  inertia; //ת������
+	int   poles; //电机极对数
+	float  ld;    //q轴电感
+	float  lq;    //d轴电感
+	float  rs;     //定子内阻
+	float  flux_linkage; //永磁磁链
+	float  inertia; 
 	float  b_emf;
 }motor_param_t;
 
@@ -111,7 +111,7 @@ typedef struct foc_s {
 	volatile foc_mode_t mode;
 	override_param_t override;
 	bool mosGate;
-	ramp_t start_ramp; //��������ĵ�ѹramp,����������ͨ�����õ�ѹ�����Ƶ���
+	ramp_t voltage_ramp; //开环情况下直接设置svm的voltage
 	ramp_t current_ramp; //���ٵ���б��
 	ramp_t speed_ramp; //�ı��ٶȵ�ramp���������ű仯��Ҫ����speed_ramp
 	foc_fault_t foc_fault;
@@ -128,7 +128,7 @@ typedef enum {
 #define A_mA(a) ((a*1000))
 #define mA_A(ma) (((float)(ma))/1000.0f)
 
-#define RPM_FOR_CLOSE_LOOP 60.0F
+#define RPM_FOR_CLOSE_LOOP 30.0F
 #define MAX_SPEED_RPM 3000
 
 #if 1

+ 22 - 1
Application/FOC/hall_sensor.c

@@ -73,6 +73,17 @@ void hall_sensor_init(void) {
 #endif
 }
 
+
+static void _detect_timeout(void){
+	u32 now = get_seconds();
+	if (now > _hall.second + 4) {//4s内没有霍尔中断,速度清零
+		if (_hall.degree_per_s > 0) {
+			_hall.degree_per_s = 0;
+			_hall.e_rpm = _hall.e_filted_rpm = 0;
+		}
+	}
+}
+
 float hall_sensor_get_theta(void){
 	if (!_hall.working) {
 		read_hall(_hall.state, _hall.theta);
@@ -91,10 +102,17 @@ float hall_sensor_get_theta(void){
 	return angle;
 }
 
+
 float hall_sensor_get_speed(void) {
+	_detect_timeout();
 	return _hall.e_rpm;
 }
 
+float hall_sensor_avg_speed(void) {
+	_detect_timeout();
+	return _hall.e_filted_rpm;
+}
+
 
 int hall_sensor_calibrate(float current, u16 *hall_table){
 	foc_overide_set_theta(0.0f);
@@ -248,8 +266,10 @@ void hall_sensor_handler(void) {
 		_hall.degree_per_s = delta_theta / delta_time;
 	}else {
 		_hall.degree_per_s = _hall_avg_speed();
+		_hall.e_filted_rpm = _hall.degree_per_s / 360.0f * 60.0f; //电角速度
 	}
 	_hall.ticks = task_ticks_abs();
+	_hall.second = get_seconds();
 	_hall.theta = theta_now;
 	_hall.state = state_now;
 	_hall.e_rpm = _hall.degree_per_s / 360.0f * 60.0f;
@@ -347,11 +367,12 @@ void hall_sensor_handler1(void) {
 		_hall.degree_per_s = delta_theta / delta_time;
 	}else {
 		_hall.degree_per_s = _hall_avg_speed();
+		_hall.e_filted_rpm = _hall.degree_per_s / 360.0f * 60.0f; //电角速度
 	}
 	_hall.ticks = task_ticks_abs();
 	_hall.theta += delta_theta;
 	_hall.state = state_now;
-	_hall.e_rpm = _hall.degree_per_s / 360.0f * 60.0f;
+	_hall.e_rpm = _hall.degree_per_s / 360.0f * 60.0f; //电角速度
 	//printf("speed :%.4f - %.4f - %.4f - %d\n", _hall.degree_per_s, delta_theta, delta_time, (int)_hall.e_rpm);
 }
 #endif

+ 5 - 2
Application/FOC/hall_sensor.h

@@ -20,12 +20,14 @@ typedef struct {
 	bool  alignmnet;
 	float theta;
 	float est_theta;
-	float e_rpm;        //每分钟转速,电转速,不是机械转速
+	float e_rpm;        //褰撳墠鐨勭數瑙掑害, 鍗曚綅锛歊PM
+	float e_filted_rpm;    //婊ゆ尝鍚庣殑鐢佃�搴�
 	u8    state;
 	u32   ticks;
+	u32   second;
 	bool  working;
 	s8    direction;
-	float degree_per_s; //每秒度, ext: 10度/s
+	float degree_per_s; //褰撳墠鐨勭數瑙掑害, 鍗曚綅锛歳ad/s
 	float phase_offset;
 }hall_t;
 
@@ -41,6 +43,7 @@ typedef struct {
 void hall_sensor_init(void);
 float hall_sensor_get_theta(void); //return degree
 float hall_sensor_get_speed(void); //return rpm
+float hall_sensor_avg_speed(void);
 int hall_sensor_calibrate(float current, u16 *hall_table);
 
 #endif /* _HALL_SENSOR_H__ */

+ 9 - 9
Application/Hal/hal.h

@@ -64,12 +64,12 @@
 #define READ_HALL3() (HAL_GPIO_ReadPin(HALL_3_GROUP, HALL_3_PIN) == GPIO_PIN_SET ?1:0)
 
 #define SYSTEM_CLOCK (72000000L)
-#define TIM_CLOCK (SYSTEM_CLOCK * 2) /*SystemClock_Config中TIM1的clk从sys PLL 过来,固定2倍的PLL频率*/
+#define TIM_CLOCK (SYSTEM_CLOCK * 2) /*SystemClock_Config锟斤拷TIM1锟斤拷clk锟斤拷sys PLL 锟斤拷锟斤拷锟斤拷锟教讹拷2锟斤拷锟斤拷PLL频锟斤拷*/
 #define TIM_CLOCK_MHz (144)
 #define ADC_CLOCK (SYSTEM_CLOCK)
 #define ADC_CLOCK_MHz (72)
 #define NS_PER_TCLK (7) /* (1/144000000 * 1000000000) */
-#define NS_2_TCLK(ns) ((ns/NS_PER_TCLK) + 1) //ns 转为pwm使用的那个TIM的clk count
+#define NS_2_TCLK(ns) ((ns/NS_PER_TCLK) + 1) //ns 转为pwm使锟矫碉拷锟角革拷TIM锟斤拷clk count
 #define FOC_PWM_FS (30 * 1000)
 #define FOC_PWM_period (TIM_CLOCK/FOC_PWM_FS)
 #define FOC_PWM_Half_Period (FOC_PWM_period/2)
@@ -82,16 +82,16 @@
 #define HW_DEAD_TIME_NS  800
 #define HW_RISE_TIME_NS  50
 #define HW_NOISE_TIME_NS 50
-#define TDead NS_2_TCLK(HW_DEAD_TIME_NS/2)/* 死区时间 */ 
-#define TRise NS_2_TCLK(HW_RISE_TIME_NS)/* MOS 开关时间*/
-#define TNoise NS_2_TCLK(HW_NOISE_TIME_NS)/* MOS开关引入的开关噪声时间 */
-#define TADC   ((uint16_t)((ADC_TRIG_CONV_LATENCY_CYCLES + ADC_SAMPLING_CYCLES) * 2 * TIM_CLOCK_MHz) / ADC_CLOCK_MHz + 1u)/* ADC 采样时间 */
+#define TDead NS_2_TCLK(HW_DEAD_TIME_NS/2)/* 锟斤拷锟斤拷时锟斤拷 */ 
+#define TRise NS_2_TCLK(HW_RISE_TIME_NS)/* MOS 锟斤拷锟斤拷时锟斤拷*/
+#define TNoise NS_2_TCLK(HW_NOISE_TIME_NS)/* MOS锟斤拷锟斤拷锟斤拷锟斤拷目锟斤拷锟斤拷锟斤拷锟绞憋拷锟� */
+#define TADC   ((uint16_t)((ADC_TRIG_CONV_LATENCY_CYCLES + ADC_SAMPLING_CYCLES) * 2 * TIM_CLOCK_MHz) / ADC_CLOCK_MHz + 1u)/* ADC 锟斤拷锟斤拷时锟斤拷 */
 
 #define START_RAMP_DURATION (100)//ms
-#define SPEED_SAMPLE_INVAL (100) //转把采集的间隔,ms
-#define SPEED_RAMP_DURATION SPEED_SAMPLE_INVAL //设置速度的斜波时间,速度平滑上升或下降
+#define SPEED_SAMPLE_INVAL (100) //转锟窖采硷拷锟侥硷拷锟�,ms
+#define SPEED_RAMP_DURATION SPEED_SAMPLE_INVAL //锟斤拷锟斤拷锟劫度碉拷斜锟斤拷时锟戒,锟劫讹拷平锟斤拷锟斤拷锟斤拷锟斤拷锟铰斤拷
 
-#define MAX_VBUS_VOLTAGE 24.0f
+#define MAX_VBUS_VOLTAGE 12.0f
 #define MAX_CURRENT      50.0F
 void Error_Handler(void);
 void SystemClock_Config(void);

+ 2 - 2
Application/Hal/uart2.c

@@ -39,9 +39,9 @@ void UART2_Init(void){
 	  Error_Handler();
 	}
 	LL_USART_DisableIT_TXE(huart2.Instance);
-	LL_USART_EnableDirectionRx(huart2.Instance);
+	//LL_USART_EnableDirectionRx(huart2.Instance);
 	LL_USART_EnableDirectionTx(huart2.Instance);
-	LL_USART_EnableIT_RXNE(huart2.Instance);
+	//LL_USART_EnableIT_RXNE(huart2.Instance);
 	HAL_NVIC_EnableIRQ(USART2_IRQn);
 }
 

+ 26 - 4
Project/Motor_PMSM.uvoptx

@@ -145,7 +145,7 @@
         <SetRegEntry>
           <Number>0</Number>
           <Key>ST-LINKIII-KEIL_SWO</Key>
-          <Name>-U0671FF363730554157013636 -O718 -SF1800 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F3xx_256.FLM -FS08000000 -FL010000 -FP0($$Device:STM32F302R8Tx$CMSIS\Flash\STM32F3xx_256.FLM)</Name>
+          <Name>-U0671FF363730554157013636 -O718 -SF1800 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8004 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F3xx_256.FLM -FS08000000 -FL010000 -FP0($$Device:STM32F302R8Tx$CMSIS\Flash\STM32F3xx_256.FLM)</Name>
         </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
@@ -153,7 +153,24 @@
           <Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F3xx_256 -FS08000000 -FL010000 -FP0($$Device:STM32F302R8Tx$CMSIS\Flash\STM32F3xx_256.FLM))</Name>
         </SetRegEntry>
       </TargetDriverDllRegistry>
-      <Breakpoint/>
+      <Breakpoint>
+        <Bp>
+          <Number>0</Number>
+          <Type>0</Type>
+          <LineNumber>64</LineNumber>
+          <EnabledFlag>1</EnabledFlag>
+          <Address>134242474</Address>
+          <ByteObject>0</ByteObject>
+          <HtxType>0</HtxType>
+          <ManyObjects>0</ManyObjects>
+          <SizeOfObject>0</SizeOfObject>
+          <BreakByAccess>0</BreakByAccess>
+          <BreakIfRCount>1</BreakIfRCount>
+          <Filename>..\Application\Hal\uart2.c</Filename>
+          <ExecCommand></ExecCommand>
+          <Expression>\\Motor_PMSM\../Application/Hal/uart2.c\64</Expression>
+        </Bp>
+      </Breakpoint>
       <WatchWindow1>
         <Ww>
           <count>0</count>
@@ -188,7 +205,12 @@
         <Ww>
           <count>6</count>
           <WinNumber>1</WinNumber>
-          <ItemText>mFOC.hall_table,0x0A</ItemText>
+          <ItemText>_gas</ItemText>
+        </Ww>
+        <Ww>
+          <count>7</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>mFOC</ItemText>
         </Ww>
       </WatchWindow1>
       <Tracepoint>
@@ -197,7 +219,7 @@
       <DebugFlag>
         <trace>0</trace>
         <periodic>1</periodic>
-        <aLwin>1</aLwin>
+        <aLwin>0</aLwin>
         <aCover>0</aCover>
         <aSer1>0</aSer1>
         <aSer2>0</aSer2>

二進制
Simulink/SVPWM_MOS.slx