Pārlūkot izejas kodu

加入挡位和96/48模式

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 3 gadi atpakaļ
vecāks
revīzija
ae784e7440

+ 3 - 2
Applications/app/app.c

@@ -21,7 +21,7 @@ extern void err_code_log(void);
 extern void encoder_log(void);
 extern measure_time_t g_meas_hall;
 extern measure_time_t g_meas_foc;
-
+extern measure_time_t g_meas_MCTask;
 #ifdef JTAG_DEBUG
 int jtag_cmd = 0;
 int jtag_data = 0;
@@ -96,7 +96,7 @@ static u32 _app_report_task(void *p) {
 	can_report_ext_status(0x43);
 	
 	if (++loop % 10 == 0) {
-		sys_debug("modulation %f, %f\n", PMSM_FOC_Get()->out.f_vdqRation, PMSM_FOC_Get()->in.s_targetTorque);
+		sys_debug("modulation %f, %f\n", PMSM_FOC_Get()->out.f_vdqRation, PMSM_FOC_Get()->rtLim.rpmLimRamp.interpolation);
 		encoder_log();
 		err_code_log();
 	}
@@ -107,6 +107,7 @@ static u32 _app_report_task(void *p) {
 static u32 _app_plot_task(void * args) {
 	//can_report_plot_values(0x45);
 	//can_plot3(PMSM_FOC_Get()->out.n_Duty[0], PMSM_FOC_Get()->out.n_Duty[1], PMSM_FOC_Get()->out.n_Duty[2]);
+	can_plot2(PMSM_FOC_Get()->in.s_targetTorque * 10, PMSM_FOC_GetSpeed());
 #if 0
 	if (!_mc_start) {
 		_mc_start = true;

+ 92 - 0
Applications/app/nv_storage.c

@@ -7,6 +7,7 @@
 
 static motor_params_t m_params;
 static foc_params_t   foc_params;
+static mc_gear_config_t gear_config;
 
 motor_params_t *nv_get_motor_params(void) {
 	return &m_params;
@@ -15,6 +16,9 @@ foc_params_t *nv_get_foc_params(void) {
 	return &foc_params;
 }
 
+mc_gear_config_t *nv_get_gear_configs(void) {
+	return &gear_config;
+}
 
 void nv_save_hall_table(s32 *hall_table) {
 	memcpy((char *)m_params.hall_table, (char *)hall_table, sizeof(m_params.hall_table));
@@ -86,9 +90,64 @@ static void nv_default_foc_params(void) {
 	foc_params.pid_conf[PID_FW_id].kp = 0;
 	foc_params.pid_conf[PID_FW_id].ki = 0.01f;
 	foc_params.pid_conf[PID_FW_id].kb = 0;
+}
+
+static void nv_default_gear_config(void) {
+	/* 48v 模式 */
+	gear_config.gears_48[0].u_maxRPM = 1430;
+	gear_config.gears_48[0].u_maxTorque = CONFIG_DEFAULT_PHASE_CURR_LIM * 0.5f;
+	gear_config.gears_48[0].u_maxIdc = 25;
+	gear_config.gears_48[0].u_accTime = 50;
+
+	gear_config.gears_48[1].u_maxRPM = 2100;
+	gear_config.gears_48[1].u_maxTorque = CONFIG_DEFAULT_PHASE_CURR_LIM * 0.8f;
+	gear_config.gears_48[1].u_maxIdc = 30;
+	gear_config.gears_48[1].u_accTime = 80;
+
+	gear_config.gears_48[2].u_maxRPM = 2850;
+	gear_config.gears_48[2].u_maxTorque = CONFIG_DEFAULT_PHASE_CURR_LIM;
+	gear_config.gears_48[2].u_maxIdc = 40;
+	gear_config.gears_48[2].u_accTime = 80;
+
+	gear_config.gears_48[3].u_maxRPM = 2850;
+	gear_config.gears_48[3].u_maxTorque = CONFIG_DEFAULT_PHASE_CURR_LIM;
+	gear_config.gears_48[3].u_maxIdc = 40;
+	gear_config.gears_48[3].u_accTime = 80;
 
+	gear_config.gears_48[4].u_maxRPM = 2850;
+	gear_config.gears_48[4].u_maxTorque = CONFIG_DEFAULT_PHASE_CURR_LIM;
+	gear_config.gears_48[4].u_maxIdc = 40;
+	gear_config.gears_48[4].u_accTime = 80;
+
+	/* 96v 模式 */
+	gear_config.gears_96[0].u_maxRPM = 2850;
+	gear_config.gears_96[0].u_maxTorque = CONFIG_DEFAULT_PHASE_CURR_LIM * 0.5f;
+	gear_config.gears_96[0].u_maxIdc = 25;
+	gear_config.gears_96[0].u_accTime = 50;
+
+	gear_config.gears_96[1].u_maxRPM = 4300;
+	gear_config.gears_96[1].u_maxTorque = CONFIG_DEFAULT_PHASE_CURR_LIM * 0.8f;
+	gear_config.gears_96[1].u_maxIdc = 30;
+	gear_config.gears_96[1].u_accTime = 80;
+
+	gear_config.gears_96[2].u_maxRPM = 5500;
+	gear_config.gears_96[2].u_maxTorque = CONFIG_DEFAULT_PHASE_CURR_LIM;
+	gear_config.gears_96[2].u_maxIdc = 35;
+	gear_config.gears_96[2].u_accTime = 100;
+
+	gear_config.gears_96[3].u_maxRPM = 5500;
+	gear_config.gears_96[3].u_maxTorque = CONFIG_DEFAULT_PHASE_CURR_LIM;
+	gear_config.gears_96[3].u_maxIdc = 45;
+	gear_config.gears_96[3].u_accTime = 100;
+
+	gear_config.gears_96[4].u_maxRPM = 5500;
+	gear_config.gears_96[4].u_maxTorque = CONFIG_DEFAULT_PHASE_CURR_LIM;
+	gear_config.gears_96[4].u_maxIdc = 45;
+	gear_config.gears_96[4].u_accTime = 100;
 }
 
+
+
 void nv_save_motor_params(void) {
 	u16 crc = crc16_get((u8 *)&m_params, sizeof(m_params) - 2);
 	m_params.crc16 = crc;
@@ -150,6 +209,38 @@ void nv_read_foc_params(void) {
 	foc_params.s_maxTorque = foc_params.s_PhaseCurrLim;//overwrite
 }
 
+void nv_save_gear_configs(void) {
+	u16 crc = crc16_get((u8 *)&gear_config, sizeof(gear_config) - 2);
+	gear_config.crc16 = crc;
+	fmc_write_data(gear_config_idx_0, (u8 *)&gear_config, sizeof(gear_config));
+	fmc_write_data(gear_config_idx_1, (u8 *)&gear_config, sizeof(gear_config));
+}
+
+void nv_read_gear_configs(void) {
+	fmc_read_data(gear_config_idx_0, (u8 *)&gear_config, sizeof(gear_config));
+	u16 crc0 = crc16_get((u8 *)&gear_config, sizeof(gear_config) - 2);
+	if (crc0 != gear_config.crc16) {
+		sys_debug("gear 0 error\n");
+		fmc_read_data(gear_config_idx_1, (u8 *)&gear_config, sizeof(gear_config));
+		crc0 = crc16_get((u8 *)&gear_config, sizeof(gear_config) - 2);
+		if (crc0 != gear_config.crc16) {
+			nv_default_gear_config();
+			nv_save_gear_configs();
+			return;
+		}
+		fmc_write_data(gear_config_idx_0, (u8 *)&gear_config, sizeof(gear_config));
+	}else {
+		fmc_read_data(gear_config_idx_1, (u8 *)&gear_config, sizeof(gear_config));
+		crc0 = crc16_get((u8 *)&gear_config, sizeof(gear_config) - 2);
+		if (crc0 != gear_config.crc16) {
+			sys_debug("gear 1 error\n");
+			fmc_read_data(gear_config_idx_0, (u8 *)&gear_config, sizeof(gear_config));
+			fmc_write_data(gear_config_idx_1, (u8 *)&gear_config, sizeof(gear_config));
+		}
+	}
+}
+
+
 void nv_set_pid(u8 id, pid_conf_t *pid) {
 	foc_params.pid_conf[id] = *pid;
 	nv_save_foc_params();
@@ -192,6 +283,7 @@ torque_lut_t *nv_get_trq_tlb(void) {
 void nv_storage_init(void) {
 	nv_read_motor_params();
 	nv_read_foc_params();
+	nv_read_gear_configs();
 	sys_debug("encoder_off = %f\n", m_params.offset);
 	if (m_params.mot_nr != MOTOR_NR) {
 		nv_default_motor_params();

+ 18 - 0
Applications/app/nv_storage.h

@@ -44,6 +44,20 @@ typedef struct {
 	u16   crc16;
 }motor_params_t;
 
+typedef struct {
+	u16 u_maxRPM;
+	u16 u_maxTorque;
+	u16 u_maxIdc;
+	u16 u_accTime;//加速曲线
+}mc_gear_t;
+
+#define CONFIG_MAX_GEAR_NUM 5
+typedef struct {
+	mc_gear_t gears_48[CONFIG_MAX_GEAR_NUM];
+	mc_gear_t gears_96[CONFIG_MAX_GEAR_NUM];
+	u16   crc16;
+}mc_gear_config_t;
+
 #define MAX_TRQ_POINTS 60
 #define MAX_SPD_POINTS 100
 #define TBL_TRQ_INTVAL 10
@@ -68,9 +82,13 @@ typedef struct {
 #define trq_Tbl_idx (focParam_idx_1 + 1)
 #define trq_Tbl_size (30)
 
+#define gear_config_idx_0 (trq_Tbl_idx + trq_Tbl_size)
+#define gear_config_idx_1 (gear_config_idx_0 + 1)
+
 void nv_storage_init(void);
 motor_params_t *nv_get_motor_params(void);
 foc_params_t *nv_get_foc_params(void);
+mc_gear_config_t *nv_get_gear_configs(void);
 void nv_save_angle_offset(float offset);
 void nv_save_motor_params(void);
 void nv_read_motor_params(void);

+ 2 - 0
Applications/bsp/board_mc_v1.h

@@ -30,6 +30,8 @@
 
 #define CONFIG_CURR_LP_PARAM (CONFIG_CURR_LP_CUT_FREQ*2*3.14F/(float)FOC_PWM_FS)
 
+#define CONFIG_96V_MODE_VOL (55.0F)
+
 #define SCHED_TIMER TIMER5
 #define SCHED_TIMER_RCU RCU_TIMER5
 #define SCHED_TIMER_IRQ TIMER5_IRQn

+ 11 - 4
Applications/foc/commands.c

@@ -48,7 +48,7 @@ static u32 foc_command_task(void *args) {
 	}
 	return 0;
 }
-u8 ext_gear = 0;
+
 static void process_ext_command(foc_cmd_body_t *command) {
 	if (command->ext_key == 0x1A01) {
 		return;
@@ -60,8 +60,15 @@ static void process_ext_command(foc_cmd_body_t *command) {
 		}else if (p_mode == 2) {
 			mc_stop();
 		}
-		ext_gear = decode_8bits(b0, 5, 7);
-
+		s8 ext_gear = decode_8bits(b0, 5, 7);
+		if (ext_gear >= 0 && ext_gear <= 5) {
+			if (ext_gear == 0) {
+				mc_set_gear(3);
+			}else {
+				mc_set_gear(ext_gear - 1);
+			}
+		}
+		sys_debug("gear %d\n", ext_gear);
 		u8 b1 = decode_u8((u8 *)command->data + 1);
 		u8 cruise = decode_8bits(b1, 0, 1);
 		if (cruise == 2) {
@@ -95,7 +102,7 @@ static void process_ext_command(foc_cmd_body_t *command) {
 		u8 response[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
 		response[0] &= 0xFC;
 		response[0] |= (mc_is_start()?1:2);
-		response[0] |= (ext_gear << 5);
+		response[0] |= (mc_get_gear() << 5);
 		
 		response[1] &= 0xC0;
 		response[1] |= (PMSM_FOC_Is_CruiseEnabled()?2:1);

+ 34 - 8
Applications/foc/core/PMSM_FOC_Core.c

@@ -506,10 +506,10 @@ void PMSM_FOC_idqCalc(void) {
 		float refTorque = min(eCtrl_get_RefTorque(), eRamp_get_intepolation(&gFoc_Ctrl.rtLim.phaseCurrLimRamp));
 		if (refTorque >= 0) {
 			gFoc_Ctrl.pi_torque->max = refTorque;
-			gFoc_Ctrl.pi_torque->min = 0;//-gFoc_Ctrl.userLim.s_PhaseCurreBrkLim;
+			gFoc_Ctrl.pi_torque->min = 0;
 		}else {
 			gFoc_Ctrl.pi_torque->min = refTorque;
-			gFoc_Ctrl.pi_torque->max = 0;//gFoc_Ctrl.userLim.s_PhaseCurreBrkLim;
+			gFoc_Ctrl.pi_torque->max = 0;
 		}
 		float errRef = eRamp_get_intepolation(&gFoc_Ctrl.rtLim.rpmLimRamp) - gFoc_Ctrl.in.s_motRPM;
 		float maxTrq = PI_Controller_RunSat(gFoc_Ctrl.pi_torque, errRef);
@@ -610,8 +610,11 @@ void PMSM_FOC_DCCurrLimit(float ibusLimit) {
 		ibusLimit = minCurr;
 	}
 	gFoc_Ctrl.userLim.s_iDCLim = (ibusLimit);
-
-	eRamp_set_step_target(&gFoc_Ctrl.rtLim.DCCurrLimRamp, ibusLimit, CONFIG_eCTRL_STEP_TS);
+	if (ABS(gFoc_Ctrl.in.s_motRPM) < 10){
+		eRamp_reset_target(&gFoc_Ctrl.rtLim.DCCurrLimRamp, ibusLimit);
+	}else {
+		eRamp_set_step_target(&gFoc_Ctrl.rtLim.DCCurrLimRamp, ibusLimit, CONFIG_eCTRL_STEP_TS);
+	}
 }
 
 float PMSM_FOC_GetDCCurrLimit(void) {
@@ -619,14 +622,34 @@ float PMSM_FOC_GetDCCurrLimit(void) {
 }
 
 void PMSM_FOC_SpeedLimit(float speedLimit) {
+	PMSM_FOC_SpeedRampLimit(speedLimit, CONFIG_LIMIT_RAMP_TIME);
+}
+
+void PMSM_FOC_SpeedRampLimit(float speedLimit, u32 rampTime) {
 	if (speedLimit > gFoc_Ctrl.hwLim.s_motRPMMax) {
 		speedLimit = gFoc_Ctrl.hwLim.s_motRPMMax;
 	}
+	bool need_reset = false;
+	if (speedLimit < gFoc_Ctrl.userLim.s_motRPMLim){
+		need_reset = true;
+	}
 	gFoc_Ctrl.userLim.s_motRPMLim = (speedLimit);
-	eRamp_set_time(&gFoc_Ctrl.rtLim.rpmLimRamp, CONFIG_LIMIT_RAMP_TIME, CONFIG_LIMIT_RAMP_TIME);
-	eRamp_set_step_target(&gFoc_Ctrl.rtLim.rpmLimRamp, speedLimit, CONFIG_eCTRL_STEP_TS);
+	eRamp_set_time(&gFoc_Ctrl.rtLim.rpmLimRamp, rampTime, rampTime);
+	if (need_reset) {
+		if ((gFoc_Ctrl.out.n_RunMode == CTRL_MODE_TRQ) && gFoc_Ctrl.out.f_vdqRation >= 1.0f) {
+			PI_Controller_Reset(gFoc_Ctrl.pi_torque, gFoc_Ctrl.out.s_RealCurrent);
+		}else if ((gFoc_Ctrl.out.n_RunMode == CTRL_MODE_SPD) && gFoc_Ctrl.pi_speed->is_sat) {
+			PI_Controller_Reset(gFoc_Ctrl.pi_speed, gFoc_Ctrl.out.s_RealCurrent);
+		}
+	}
+	if (ABS(gFoc_Ctrl.in.s_motRPM) < 10) {
+		eRamp_reset_target(&gFoc_Ctrl.rtLim.rpmLimRamp, speedLimit);
+	}else {
+		eRamp_set_step_target(&gFoc_Ctrl.rtLim.rpmLimRamp, speedLimit, CONFIG_eCTRL_STEP_TS);
+	}
 }
 
+
 /* 扭矩模式下的限速,主要是处理转把对应的最高速 */
 void PMSM_FOC_Torque_SpeedLimit(float speedLimit) {
 	if (speedLimit > gFoc_Ctrl.hwLim.s_motRPMMax) {
@@ -698,8 +721,11 @@ void PMSM_FOC_PhaseCurrLim(float lim) {
 		lim = minCurr;
 	}
 	gFoc_Ctrl.userLim.s_PhaseCurrLim = lim;
-	
-	eRamp_set_step_target(&gFoc_Ctrl.rtLim.phaseCurrLimRamp, lim, CONFIG_eCTRL_STEP_TS);
+	if (ABS(gFoc_Ctrl.in.s_motRPM) < 10){
+		eRamp_reset_target(&gFoc_Ctrl.rtLim.phaseCurrLimRamp, lim);
+	}else {
+		eRamp_set_step_target(&gFoc_Ctrl.rtLim.phaseCurrLimRamp, lim, CONFIG_eCTRL_STEP_TS);
+	}
 }
 
 void PMSM_FOC_RT_PhaseCurrLim(float lim) {

+ 1 - 0
Applications/foc/core/PMSM_FOC_Core.h

@@ -287,6 +287,7 @@ void PMSM_FOC_RT_LimInit(void);
 float PMSM_FOC_Get_Real_Torque(void);
 void PMSM_FOC_Reset_Torque(void);
 void PMSM_FOC_Torque_SpeedLimit(float speedLimit);
+void PMSM_FOC_SpeedRampLimit(float speedLimit, u32 rampTime);
 
 #endif /* _PMSM_FOC_Core_H__ */
 

+ 57 - 1
Applications/foc/motor/motor.c

@@ -30,6 +30,8 @@ static shark_timer_t _autohold_beep_timer = TIMER_INIT(_autohold_beep_timer, _au
 
 static motor_t motor = {
 	.s_direction = POSITIVE,
+	.n_gear = 0,
+	.b_is96Mode = false,
 };
 
 static void MC_Check_MosVbusThrottle(void) {
@@ -63,6 +65,10 @@ static u32 _self_check_task(void *p) {
 	return 0;
 }
 
+static void mc_detect_vbus_mode(void) {
+	motor.b_is96Mode = get_vbus_int() >= CONFIG_96V_MODE_VOL;
+}
+
 static void _mc_internal_init(u8 mode, bool start) {
 	motor.mode = mode;
 	motor.throttle = 0;
@@ -77,6 +83,20 @@ static void _mc_internal_init(u8 mode, bool start) {
 	motor.b_break = false;
 	motor.b_wait_brk_release = false;
 }
+
+static void mc_gear_vmode_changed(void) {
+	mc_gear_t *gears;
+	
+	if (motor.b_is96Mode) {
+		gears = &nv_get_gear_configs()->gears_96[0];
+	}else {
+		gears = &nv_get_gear_configs()->gears_48[0];
+	}
+	PMSM_FOC_SpeedRampLimit(gears[motor.n_gear].u_maxRPM, 1000);
+	PMSM_FOC_DCCurrLimit(gears[motor.n_gear].u_maxIdc);
+	PMSM_FOC_PhaseCurrLim(gears[motor.n_gear].u_maxTorque);
+}
+
 void mc_init(void) {
 	adc_init();
 	pwm_3phase_init();
@@ -84,6 +104,7 @@ void mc_init(void) {
 	motor_encoder_init();
 	foc_command_init();
 	torque_init();
+	mc_detect_vbus_mode();
 	PMSM_FOC_CoreInit();
 	eCtrl_init(nv_get_foc_params()->n_acc_time, nv_get_foc_params()->n_dec_time);
 	mc_brk_gpio_init();
@@ -109,6 +130,8 @@ bool mc_start(u8 mode) {
 #ifdef CONFIG_DQ_STEP_RESPONSE
 	mode = CTRL_MODE_CURRENT;
 #endif
+	mc_detect_vbus_mode();
+
 	if (motor.b_lock_motor) {
 		PMSM_FOC_SetErrCode(FOC_NotAllowed);
 		return false;
@@ -189,6 +212,27 @@ bool mc_stop(void) {
 	return true;
 }
 
+bool mc_set_gear(u8 gear) {
+	if (gear >= CONFIG_MAX_GEAR_NUM) {
+		PMSM_FOC_SetErrCode(FOC_Param_Err);
+		return false;
+	}
+	if (motor.n_gear != gear) {
+		motor.n_gear = gear;
+		u32 mask = cpu_enter_critical();
+		mc_gear_vmode_changed();
+		cpu_exit_critical(mask);
+	}
+	return true;
+}
+
+u8 mc_get_gear(void) {
+	if (motor.n_gear == 3){
+		return 0;
+	}
+	return motor.n_gear + 1;
+}
+
 bool mc_set_foc_mode(u8 mode) {
 	if (mode == motor.mode) {
 		return true;
@@ -647,8 +691,13 @@ static void mc_process_throttle_epm(void) {
 
 /*FOC 的部分处理,比如速度环,状态机,转把采集等*/
 measure_time_t g_meas_MCTask;
+#define mc_TaskStart time_measure_start(&g_meas_MCTask)
+#define mc_TaskEnd time_measure_end(&g_meas_MCTask)
 void Sched_MC_mTask(void) {
-	time_measure_start(&g_meas_MCTask);
+	mc_TaskStart;
+	bool is96v_prev = motor.b_is96Mode;
+	mc_detect_vbus_mode();
+
 	u8 runMode = PMSM_FOC_CtrlMode();
 
 	/*保护功能*/
@@ -656,13 +705,18 @@ void Sched_MC_mTask(void) {
 	/* 母线电流,实际采集的相电流矢量大小的计算 */
 	PMSM_FOC_Calc_Current();
 
+	if (is96v_prev != motor.b_is96Mode) {
+		mc_gear_vmode_changed();
+	}
 	if (motor.b_calibrate || (motor.mode == CTRL_MODE_OPEN)) {
+		mc_TaskEnd;
 		return;
 	}
 	/* 堵转处理 */
 	if (mc_run_stall_process(runMode) || (runMode == CTRL_MODE_CURRENT)) {
 		eCtrl_Running();
 		PMSM_FOC_Slow_Task();
+		mc_TaskEnd;
 		return;
 	}
 
@@ -683,6 +737,7 @@ void Sched_MC_mTask(void) {
 			if (!PMSM_FOC_Is_Start() && (!mc_throttle_released())) {
 				mask = cpu_enter_critical();
 				PMSM_FOC_Start(motor.mode);
+				mc_gear_vmode_changed();
 				torque_reset();
 				pwm_enable_channel();
 				cpu_exit_critical(mask);
@@ -699,4 +754,5 @@ void Sched_MC_mTask(void) {
 		}
 #endif
 	}
+	mc_TaskEnd;
 }

+ 6 - 0
Applications/foc/motor/motor.h

@@ -4,6 +4,7 @@
 #include "foc/core/PMSM_FOC_Core.h"
 #include "foc/motor/hall.h"
 #include "foc/motor/encoder.h"
+#include "app/nv_storage.h"
 
 typedef struct {
 	bool   b_start;
@@ -24,6 +25,9 @@ typedef struct {
 	s8     s_direction;
 	u32    n_brake_errors;
 	u8     mode;
+	bool   b_is96Mode;
+	u8     n_gear;
+	mc_gear_t *gear_cfg;
 	u32    n_autohold_time;
 	bool   b_wait_brk_release;
 	bool   b_updated;
@@ -50,6 +54,8 @@ bool mc_command_epm_move(EPM_Dir_t dir);
 bool mc_throttle_epm_move(EPM_Dir_t dir);
 void mc_need_update(void);
 bool mc_is_start(void);
+bool mc_set_gear(u8 gear);
+u8 mc_get_gear(void);
 
 static __INLINE float motor_encoder_get_angle(void) {
 #ifdef USE_ENCODER_HALL

+ 3 - 1
Applications/foc/samples.c

@@ -137,7 +137,7 @@ void sample_uvw_phase(void) {
 }
 
 void sample_motor_temp(void) {
-#ifndef MOTOR_BLUESHARK_OLD
+#ifdef MOTOR_BLUESHARK_OLD
 	u16 adc = adc_get_motor_temp();
 	u16 r = MOTOR_TEMP_R(adc);
 	motor_temp.value = ntc_get_motor_temp(r);
@@ -146,10 +146,12 @@ void sample_motor_temp(void) {
 }
 
 void sample_mos_temp(void) {
+#ifdef MOTOR_BLUESHARK_OLD
 	u16 adc = adc_get_mos_temp();
 	u16 r = MOS_TEMP_R(adc);
 	mos_temp.value = ntc_get_mos_temp(r);
 	LowPass_Filter(mos_temp.filted_value, mos_temp.value, mos_temp.lowpass);
+#endif
 }
 
 

+ 2 - 2
Applications/prot/can_foc_msg.c

@@ -102,7 +102,7 @@ void can_report_mpta_values(u8 can) {
 	encode_s16(data + 6, (s16)(PMSM_FOC_Get()->in.s_targetIdq.q * 10.0f));
 	can_send_message(get_indicator_can_id(can), data, sizeof(data), 0);
 }
-extern u8 ext_gear;
+
 void can_report_ext_status(u8 can) {
 	u8 data[8] = {0x0, 0x0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
 	data[0] = (get_vbus_int()>60?1:0) << 5;
@@ -110,7 +110,7 @@ void can_report_ext_status(u8 can) {
 	data[0] |= (mc_is_epm()?1:0) << 7;
 	data[1] = mc_is_start()?0:1;
 	data[1] |= (PMSM_FOC_Is_CruiseEnabled()?1:0) << 3;
-	data[1] |= ext_gear << 6;
+	data[1] |= mc_get_gear() << 6;
 	encode_s16(data + 2, ABS((s16)(motor_encoder_get_speed()/4.0f)));
 	float vDC = get_vbus_float();
 	encode_s16(data + 4, (s16)(vDC*10));

BIN
Simulink/FOC.slx