Переглянути джерело

update

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 3 роки тому
батько
коміт
f6d3d3a006

+ 7 - 5
Applications/app/app.c

@@ -1,6 +1,7 @@
 #include "bsp/bsp.h"
 #include "app/app.h"
 #include "bsp/adc.h"
+#include "bsp/pwm.h"
 #include "os/os_task.h"
 #include "libs/logger.h"
 #include "libs/utils.h"
@@ -127,23 +128,24 @@ static u32 _app_report_task(void *p) {
 		//sys_debug("modulation %f, %f\n", PMSM_FOC_Get()->out.f_vdqRation, PMSM_FOC_Get()->rtLim.rpmLimRamp.interpolation);
 		//sys_debug("Slow: %d - %d\n", g_meas_MCTask.intval_time, g_meas_MCTask.exec_time);
 		//sys_debug("Fast: %d - %d, err: %d-%d-%d\n", g_meas_foc.intval_time, g_meas_foc.exec_time, g_meas_foc.intval_hi_err, g_meas_foc.intval_low_err, g_meas_foc.exec_max_error_time);
-		//sys_debug("FOC time err %d %d\n", g_meas_foc.intval_time_h_error, g_meas_foc.intval_time_l_error);
-		//sys_debug("acc vol %d\n", get_acc_vol());
-		//sys_debug("throttle %f\n", get_throttle_float());
+		sys_debug("FOC time err %d %d\n", g_meas_foc.intval_time_h_error, g_meas_foc.intval_time_l_error);
+		sys_debug("acc vol %d\n", get_acc_vol());
+		sys_debug("throttle %f\n", get_throttle_float());
+		sys_debug("deadtime 0x%x\n", get_deadtime());
 		//sys_debug("ADC Vref %f, %f\n", get_adc_vref(), adc_5vref_compesion());
 		//sys_debug("Vdq in %f, %f\n", PMSM_FOC_Get()->in.s_targetVdq.d, PMSM_FOC_Get()->in.s_targetVdq.q);
 		//sys_debug("Vdq out %f, %f\n", PMSM_FOC_Get()->out.s_OutVdq.d, PMSM_FOC_Get()->out.s_OutVdq.q);
 		//sys_debug("target current %f\n", PMSM_FOC_Get()->in.s_targetCurrent);
 		//thro_torque_log();
 		//sys_debug("fan rpm %d, %d\n", mc_params()->fan[0].rpm, mc_params()->fan[1].rpm);
-		//encoder_log();
+		encoder_log();
 		///PMSM_FOC_LogDebug();
 		//eCtrl_debug_log();
 		//err_code_log();
 	}
 	return 200;
 }
-int plot_type = 7;
+int plot_type = 2;
 static void plot_smo_angle(void) {
 	float smo_angle = foc_observer_smo_angle();
 	float delta = smo_angle - PMSM_FOC_Get()->in.s_hallAngle;

+ 2 - 2
Applications/app/nv_storage.c

@@ -132,13 +132,13 @@ static void nv_default_foc_params(void) {
 static void nv_default_gear_config(void) {
 	for (int i = 0; i < CONFIG_MAX_GEAR_NUM; i++) {
 		gear_config.gears_48[i].n_max_speed = 4000;
-		gear_config.gears_48[i].n_max_trq = 200;
+		gear_config.gears_48[i].n_max_trq = CONFIG_MAX_MOTOR_TORQUE/2;
 		gear_config.gears_48[i].n_max_idc = 60;
 		gear_config.gears_48[i].n_zero_accl = 1500;
 		gear_config.gears_48[i].n_accl_time = 500;
 
 		gear_config.gears_96[i].n_max_speed = 8000;
-		gear_config.gears_96[i].n_max_trq = 400;
+		gear_config.gears_96[i].n_max_trq = CONFIG_MAX_MOTOR_TORQUE;
 		gear_config.gears_96[i].n_max_idc = 100;
 		gear_config.gears_96[i].n_zero_accl = 1500;
 		gear_config.gears_96[i].n_accl_time = 400;

+ 1 - 1
Applications/bsp/board_mc100_v1.h

@@ -341,7 +341,7 @@
 #endif
 #define DEBUG_PORT_UART2
 
-#define CONFIG_MOT_TYPE MOTOR_BLUESHARK_A1
+#define CONFIG_MOT_TYPE MOTOR_BLUESHARK_ZD_100
 
 //#define CONFIG_DQ_STEP_RESPONSE
 

+ 2 - 0
Applications/bsp/pwm.h

@@ -83,6 +83,8 @@
 		} \
 	}while(0)
 
+#define get_deadtime() TIMER_CCHP(pwm_timer)
+
 void pwm_3phase_init(void);
 void pwm_3phase_sides(bool hon, bool lon);
 void pwm_start(void);

+ 3 - 3
Applications/foc/core/e_ctrl.c

@@ -118,10 +118,10 @@ void eCtrl_Running(void) {
 		_eCtrl_set_TgtSpeed(g_eCtrl.speed_shadow);
 	}
 	if (g_eCtrl.torque_shadow != g_eCtrl.torque.target) {
-		if (PMSM_FOC_Get()->out.n_RunMode == CTRL_MODE_TRQ) {
-			eRamp_set_time(&g_eCtrl.torque, g_eCtrl.accl_time, g_eCtrl.dec_time);
-		}else {
+		if (PMSM_FOC_Get()->out.n_RunMode == CTRL_MODE_EBRAKE) {
 			eRamp_set_time(&g_eCtrl.torque, g_eCtrl.ebrk_time, g_eCtrl.ebrk_time);
+		}else {
+			eRamp_set_time(&g_eCtrl.torque, g_eCtrl.accl_time, g_eCtrl.dec_time);
 		}
 		_eCtrl_set_TgtTorque(g_eCtrl.torque_shadow);
 	}

+ 3 - 5
Applications/foc/motor/motor.c

@@ -176,7 +176,7 @@ static void _led_off_timer_handler(shark_timer_t *t) {
 static void mc_gear_vmode_changed(void) {
 	mc_gear_t *gears = mc_get_gear_config();
 	
-	//sys_debug("limit %d-%d-%d, mode = %s\n", gears[motor.n_gear].u_maxRPM, gears[motor.n_gear].u_maxIdc, gears[motor.n_gear].u_maxTorque, motor.b_is96Mode?"96V":"48V");
+	sys_debug("limit %d-%d-%d, mode = %s\n", gears->n_max_speed, gears->n_max_idc, gears->n_max_trq, motor.b_is96Mode?"96V":"48V");
 	PMSM_FOC_SpeedLimit(gears->n_max_speed);
 	PMSM_FOC_DCCurrLimit(gears->n_max_idc);
 	PMSM_FOC_TorqueLimit(gears->n_max_trq);
@@ -282,11 +282,9 @@ bool mc_start(u8 mode) {
 	pwm_up_enable(false);
 
 	_mc_internal_init(mode, true);
-#if 0
-	torque_reset();
-#else
+
 	thro_torque_reset();
-#endif
+	mc_gear_vmode_changed();
 	eCtrl_init(mc_get_gear_config()->n_accl_time, nv_get_foc_params()->n_dec_time);
 	motor_encoder_start(true);
 	PMSM_FOC_Start(mode);

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

@@ -85,6 +85,7 @@ void mpta_fw_lookup(float rpm, float torque, DQ_t *dq_out);
 
 #define TRQ_PI_KP 0.6F //0.13f
 #define TRQ_PI_KI 0.5F
+#define TRO_PI_KD 0.0F
 
 #define MOTOR_NR 0x13
 

+ 3 - 3
Applications/foc/samples.c

@@ -43,12 +43,12 @@ void samples_init(void){
 	_vref.value = 0;
 	_vref.lowpass = 0.01f;
 	sample_vref();
-	_vbus.filted_value = (CONFIG_RATED_DC_VOL);
-	_vbus.value = (CONFIG_RATED_DC_VOL);
+	_vbus.value = ((float)adc_get_vbus() * VBUS_VOL_CEOF);
+	_vbus.filted_value = _vbus.value;
 	_vbus.lowpass = (0.01f);
 #ifdef ACC_V_CHAN
+	acc_vol.value = ((float)adc_get_acc() * VBUS_VOL_CEOF);
 	acc_vol.filted_value = (CONFIG_RATED_DC_VOL);
-	acc_vol.value = (CONFIG_RATED_DC_VOL);
 	acc_vol.lowpass = (0.01f);
 #endif
 	sample_vbus();

+ 18 - 0
Applications/prot/can_foc_msg.c

@@ -131,6 +131,24 @@ void can_report_ext_status(u8 can) {
 	shark_can0_send_ext_message(0x1A014D43, data, sizeof(data));
 }
 
+
+void can_response_vols(u8 can, u8 key) {
+	u8 data[16];
+	int len;
+	encoder_can_key(data, CMD_2_CAN_KEY(key));
+	len = 2;
+	float thro = get_throttle_float() * 10.0f;
+	encode_s16(data + len, (s16)thro);
+	len += 2;
+	float acc = get_acc_vol() * 10.0f;
+	encode_s16(data + len, (s16)acc);
+	len += 2;
+	float vbus = get_vbus_float() * 10.0f;
+	encode_s16(data + len, (s16)vbus);
+	len += 2;
+	can_send_response(can, data, len);
+}
+
 void can_report_plot_values(u8 can) {
     s16 trq_ref = eCtrl_get_RefTorque() * 10;
 	s16 real_ref = PMSM_FOC_Get_Real_dqVector() * 10;

+ 1 - 0
Applications/prot/can_foc_msg.h

@@ -13,6 +13,7 @@ void can_report_foc_status(u8 can);
 void can_report_mpta_values(u8 can);
 void can_report_ext_status(u8 can);
 void can_report_plot_values(u8 can);
+void can_response_vols(u8 can, u8 key);
 void can_plot1(s16 v1);
 void can_plot2(s16 v1, s16 v2);
 void can_plot3(s16 v1, s16 v2, s16 v3);

BIN
Simulink/FOC_ADRC.slx


BIN
Simulink/FOC_ADRC.slxc


+ 21 - 0
Simulink/foc_adrc.m

@@ -0,0 +1,21 @@
+% Clear workspace
+close all
+clear
+clc
+
+% Load model parameters
+Ts                  = 5e-7;                         % [s] Model sampling time (200 KHz)
+Ts_ctrl             = 6e-5;                     % [s] Controller sampling time (50us)5e-5
+f_speed_ctrl        = 500;                          % [Hz] Speed/torque Controller frequency = (500 Hz)
+Ts_Spd_ctl          = 1/f_speed_ctrl;
+
+%Simulink provider Motor parameters
+n_polePairs  = 4;        % [-] Number of motor pole pairs
+PM           = 0.01688;   % Permanent magnet flux linkage, 
+Ld           = 0.07e-3;% d-axis inductance, 
+Lq           = 0.150e-3; % q-axis inductance,
+Rs           = 0.011;   % Stator resistance,
+J            = 0.03945; % Moment of inertia,
+bandwith     = 5000;
+i_Udc        = 96;      % DCbus max voltage
+

+ 6 - 5
Simulink/init_model.m

@@ -21,12 +21,13 @@ f_lpf_vdq    = 0.01; %DC link current limit LowPass filter
 pll_w = 100;
 %Simulink provider Motor parameters
 n_polePairs  = 4;        % [-] Number of motor pole pairs
-PM           = 0.1688;   % Permanent magnet flux linkage, 
-Ld           = 0.9262e-3;% d-axis inductance, 
-Lq           = 1.024e-3; % q-axis inductance,
-Rs           = 0.0918;   % Stator resistance,
+PM           = 0.01688;   % Permanent magnet flux linkage, 
+Ld           = 0.07e-3;% d-axis inductance, 
+Lq           = 0.150e-3; % q-axis inductance,
+Rs           = 0.011;   % Stator resistance,
 J            = 0.03945; % Moment of inertia,
-i_Udc        = 300;      % DCbus max voltage
+bandwith     = 5000;
+i_Udc        = 96;      % DCbus max voltage
 i_dqMax      = 150;      % [A] Maximum allowed motor current (continuous)
 n_max        = 2500;             % [rpm] Maximum motor speed: [-5000, 5000]
 %BlueShark Motor parameters

+ 6 - 6
Simulink/motor_data_nihe.m

@@ -1,15 +1,15 @@
 clear;
-y=xlsread('E:\works\项目\MC100\电机台架数据\鲨湾96v电机145外特性.xlsx','MAP1','A2:A9'); % torque
-x=xlsread('E:\works\项目\MC100\电机台架数据\鲨湾96v电机145外特性.xlsx','MAP1','W2:W9'); % D
-z=xlsread('E:\works\项目\MC100\电机台架数据\鲨湾96v电机145外特性.xlsx','MAP1','X2:X9'); % Q
+y=xlsread('E:\works\项目\MC100\电机台架数据\鲨湾96v电机145外特性.xlsx','MAP1','A26:A33'); % torque
+x=xlsread('E:\works\项目\MC100\电机台架数据\鲨湾96v电机145外特性.xlsx','MAP1','W26:W33'); % D
+z=xlsread('E:\works\项目\MC100\电机台架数据\鲨湾96v电机145外特性.xlsx','MAP1','X26:X33'); % Q
 y=abs(y);
 % Te = 1.5*4*(a*iq + (ld - lq)*idiq);
 ft=fittype('6*(a*iq-(l)*id*iq)', 'independent',{'id','iq'}, 'coefficients', {'a', 'l'});
 %ld=0.000070;
 %lq=0.000140;
-%ft=fittype('6*(a*iq+(ld-lq)*id*iq)', 'independent',{'id','iq'}, 'coefficients', {'a', 'ld', 'lq'});
-
-Y=fit([x,z],y,ft,'StartPoint',[0.001, 0.00070])
+ft=fittype('6*(0.0232*iq+(ld-lq)*id*iq)', 'independent',{'id','iq'}, 'coefficients', {'ld', 'lq'});
 
+Y=fit([x,z],y,ft,'StartPoint',[0.00070, 0.000150])
 
 
+Y=fit([x,z],y,ft,'StartPoint',[0.023, 0.00007])

BIN
Simulink/untitled.slx.autosave