Explorar o código

改装电机2,使用encoder_off2.h

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui %!s(int64=3) %!d(string=hai) anos
pai
achega
dd388bc93f
Modificáronse 48 ficheiros con 4232 adicións e 48 borrados
  1. 3 0
      Applications/app/app.c
  2. 3 2
      Applications/app/nv_storage.c
  3. 3 2
      Applications/bsp/board_mc_v1.h
  4. 1 1
      Applications/bsp/bsp.h
  5. 3 1
      Applications/bsp/delay.c
  6. 9 1
      Applications/bsp/pwm.h
  7. 1 1
      Applications/bsp/uart.c
  8. 1 1
      Applications/bsp/uart.h
  9. 2 1
      Applications/foc/commands.c
  10. 34 13
      Applications/foc/core/PMSM_FOC_Core.c
  11. 2 1
      Applications/foc/core/PMSM_FOC_Core.h
  12. 1 1
      Applications/foc/core/e_ctrl.c
  13. 6 6
      Applications/foc/core/torque.c
  14. 7 7
      Applications/foc/foc_config.h
  15. 6 0
      Applications/foc/motor/current.c
  16. 15 7
      Applications/foc/motor/encoder.c
  17. 113 0
      Applications/foc/motor/encoder_off2.h
  18. 12 2
      Applications/foc/motor/motor.c
  19. 44 0
      Applications/math/fast_math.c
  20. 11 0
      Applications/math/fast_math.h
  21. 14 0
      Project/MC100.uvoptx
  22. 1 1
      Project/MC100.uvprojx
  23. BIN=BIN
      Simulink/ADRC.slx
  24. BIN=BIN
      Simulink/FOC.slx.autosave
  25. 26 0
      Simulink/Fir_angle2.m
  26. BIN=BIN
      Simulink/MotorController_FOC.slxc
  27. 16 0
      Simulink/Subsystem_ert_rtw/Subsystem.bat
  28. 78 0
      Simulink/Subsystem_ert_rtw/Subsystem.c
  29. 86 0
      Simulink/Subsystem_ert_rtw/Subsystem.h
  30. 406 0
      Simulink/Subsystem_ert_rtw/Subsystem.mk
  31. 2 0
      Simulink/Subsystem_ert_rtw/Subsystem.rsp
  32. 7 0
      Simulink/Subsystem_ert_rtw/Subsystem_comp.rsp
  33. 0 0
      Simulink/Subsystem_ert_rtw/Subsystem_ref.rsp
  34. BIN=BIN
      Simulink/Subsystem_ert_rtw/buildInfo.mat
  35. BIN=BIN
      Simulink/Subsystem_ert_rtw/codeInfo.mat
  36. BIN=BIN
      Simulink/Subsystem_ert_rtw/codedescriptor.dmr
  37. BIN=BIN
      Simulink/Subsystem_ert_rtw/compileInfo.mat
  38. 14 0
      Simulink/Subsystem_ert_rtw/defines.txt
  39. 109 0
      Simulink/Subsystem_ert_rtw/ert_main.c
  40. 2 0
      Simulink/Subsystem_ert_rtw/modelsources.txt
  41. 4 0
      Simulink/Subsystem_ert_rtw/rtw_proj.tmw
  42. 102 0
      Simulink/Subsystem_ert_rtw/rtwtypes.h
  43. BIN=BIN
      Simulink/Subsystem_ert_rtw/rtwtypeschksum.mat
  44. 2 0
      Simulink/Subsystem_ert_rtw/setup_msvc.bat
  45. 3072 0
      Simulink/angle2.csv
  46. 1 0
      Simulink/init_model.m
  47. 2 0
      Simulink/myfilter.m
  48. 11 0
      Simulink/myfilter2.m

+ 3 - 0
Applications/app/app.c

@@ -56,6 +56,9 @@ void fetch_jtag_cmd(void) {
 	}else if (jtag_cmd == 8) {
 		//mc_current_sensor_calibrate((float)jtag_data/10.0f);
 		jtag_cmd = 0;
+	}else if (jtag_cmd == 9) {
+		mc_encoder_zero_calibrate(jtag_data);
+		jtag_cmd = 0;
 	}
 	jtag_cmd = 0;
 }

+ 3 - 2
Applications/app/nv_storage.c

@@ -31,7 +31,8 @@ static void nv_default_motor_params(void) {
 	m_params.r = MOTOR_R;
 	m_params.ld = MOTOR_Ld;
 	m_params.lq = MOTOR_Lq;
-	m_params.offset = (360-128);
+	m_params.offset = (69.0f);
+	//m_params.offset = (360-128);
 	m_params.est_pll_band = 100;
 	m_params.pos_lock_pll_band = 100;
 	m_params.flux_linkage = 0.0f;
@@ -42,7 +43,7 @@ static void nv_default_foc_params(void) {
 	foc_params.s_maxiDC = 30;
 	//foc_params.s_maxIdq = 200;
 	//foc_params.s_minIdq = -200;
-	foc_params.s_PhaseCurrLim = 30;
+	foc_params.s_PhaseCurrLim = 180;
 	foc_params.s_maxRPM = 8000;
 	foc_params.s_maxEpmRPM = 133;
 	foc_params.s_maxTorque = 50;

+ 3 - 2
Applications/bsp/board_mc_v1.h

@@ -32,7 +32,7 @@
 #define CONFIG_MAX_PHASE_VOL    140.0F
 #define CONFIG_MAX_VBUS_VOLTAGE 100.0F
 #define CONFIG_MAX_TORQUE       50.0F
-#define CONFIG_CURRENT_BANDWITH 500 /* 电流环带宽 */
+#define CONFIG_CURRENT_BANDWITH 500.0f /* 电流环带宽 */
 
 /* MOS驱动 */
 #define pwm_timer TIMER0
@@ -79,7 +79,7 @@
 #define V_PHASE_I_CHAN  ADC_CHANNEL_5
 #define W_PHASE_I_CHAN  ADC_CHANNEL_6
 
-#define PWM_UV_SWAP
+//#define CONFIG_PWM_UV_SWAP
 
 #define V_PHASE_ADC_GROUP 	GPIOA
 #define V_PHASE_ADC_PIN 	GPIO_PIN_5
@@ -151,6 +151,7 @@
 
 /* 是否用编码器 */
 #define USE_ENCODER_ABI
+//#define ENCODER_CC_INVERT //编码器方向和电机反向
 
 /* 编码器 */
 #define ENC_A_GROUP GPIOB

+ 1 - 1
Applications/bsp/bsp.h

@@ -21,7 +21,7 @@
 #define ADC_CLOCK_MHz (30u)
 #define NS_PER_TCLK (8u) /* (1/120000000 * 1000000000) */
 #define NS_2_TCLK(ns) (((ns)/NS_PER_TCLK) + 1u) //ns תΪpwmʹ�õ��Ǹ�TIM��clk count
-#define FOC_PWM_FS (15000u)
+#define FOC_PWM_FS (16000u)
 #define FOC_PWM_period (TIM_CLOCK/FOC_PWM_FS)
 #define FOC_PWM_Half_Period (FOC_PWM_period/2)
 

+ 3 - 1
Applications/bsp/delay.c

@@ -29,7 +29,9 @@ void task_ticks_delay(uint32_t ticks)
 	uint32_t start;
 
 	start = task_ticks_abs();
-	while (task_ticks_rel(start) < ticks);
+	while (task_ticks_rel(start) < ticks){
+		
+	};
 }
 
 void task_udelay(uint32_t delay)

+ 9 - 1
Applications/bsp/pwm.h

@@ -17,7 +17,7 @@
 #define ch2_update_duty(duty) 	TIMER_CH2CV(pwm_timer) = (uint32_t)duty
 #define update_adc_trigger(time) TIMER_CH3CV(pwm_timer) = (uint32_t)time
 
-#ifdef PWM_UV_SWAP
+#ifdef CONFIG_PWM_UV_SWAP
 #define pwm_update_duty(dutyA, dutyB, dutyC) \
 	do {\
 		ch0_update_duty(dutyC);\
@@ -63,6 +63,14 @@
 		} \
 	}while(0)
 
+#define pwm_brake_enable(n) \
+	do { \
+		if (n) { \
+			nvic_irq_enable(TIMER0_BRK_IRQn, EBREAK_IRQ_PRIORITY, 0); \
+		}else { \
+			nvic_irq_disable(TIMER0_BRK_IRQn); \
+		} \
+	}while(0)
 
 void pwm_3phase_init(void);
 void pwm_start(void);

+ 1 - 1
Applications/bsp/uart.c

@@ -4,7 +4,7 @@
 #include "libs/logger.h"
 #include "libs/utils.h"
 
-#define SHARK_UART_BAUDRATE				76800
+#define SHARK_UART_BAUDRATE				500000
 
 #ifdef DEBUG_PORT_UART1
 #define SHARK_UART0_com					USART1

+ 1 - 1
Applications/bsp/uart.h

@@ -11,7 +11,7 @@
 #define CH_ESC_END						0x06
 #define CH_ESC_ESC						0x07
 
-#define SHARK_UART_TX_MEM_SIZE			(1 * 1024)
+#define SHARK_UART_TX_MEM_SIZE			(22 * 1024)
 #define SHARK_UART_RX_MEM_SIZE			512
 #define RX_FRAME_MAX_LEN 260
 #define RX_OLD_FRAME_MAX_LEN 256

+ 2 - 1
Applications/foc/commands.c

@@ -95,6 +95,7 @@ static void process_foc_command(foc_cmd_body_t *command) {
 		case Foc_Set_Ctrl_Mode:
 		{
 			u8 mode = decode_u8(command->data);
+			sys_debug("mode = %d\n", mode);
 			if (!PMSM_FOC_SetCtrlMode(mode)) {
 				erroCode = PMSM_FOC_GetErrCode();
 			}
@@ -153,7 +154,7 @@ static void process_foc_command(foc_cmd_body_t *command) {
 		{
 			s16 vd = decode_s16(((u8 *)command->data));
 			s16 vq = decode_s16(((u8 *)command->data) + 2);
-			sys_debug("set v_q %d\n", vq);
+			sys_debug("set v_q %d, %d\n", vd, vq);
 			PMSM_FOC_SetOpenVdq(vd, (vq));
 			break;
 		}

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

@@ -15,6 +15,8 @@
 #include "math/fir.h"
 PMSM_FOC_Ctrl _gFOC_Ctrl;
 static Fir_t phase1, phase2;
+TD_t speed_td;
+
 static bool g_focinit = false;
 
 static u32 PMSM_FOC_Debug_Task(void *p);
@@ -185,6 +187,7 @@ void PMSM_FOC_CoreInit(void) {
 	_gFOC_Ctrl.pi_ctl_lock = &PI_Ctrl_lock;
 	_gFOC_Ctrl.pi_ctl_power = &PI_Ctrl_Power;
 
+	TD_Init(&speed_td, 2.0f, (1.0f/(float)SPD_CTRL_TS));
 	PMSM_FOC_Conf_PID();
 	
 	memset(&_gFOC_Ctrl.in, 0, sizeof(_gFOC_Ctrl.in));
@@ -294,9 +297,11 @@ static __INLINE void PMSM_FOC_Update_PI_Idq(void) {
 
 static u32 PMSM_FOC_Debug_Task(void *p) {
 	if (_gFOC_Ctrl.in.b_motEnable) {
-		plot_3data16(FtoS16x10(_gFOC_Ctrl.in.s_vABC[1]), FtoS16x10(_gFOC_Ctrl.out.s_RealVdq.q), _gFOC_Ctrl.in.s_motRPM);
+		//plot_3data16(FtoS16x10(_gFOC_Ctrl.in.s_iABCFilter[0]), FtoS16x10(_gFOC_Ctrl.in.s_iABCFilter[1]), _gFOC_Ctrl.in.s_motRPM);
+		//plot_3data16(FtoS16x10(_gFOC_Ctrl.out.s_RealIdq.d), FtoS16x10(_gFOC_Ctrl.out.s_RealIdq.q), FtoS16x10(_gFOC_Ctrl.idq_ctl[1].s_FinalTgt));
+		//plot_3data16( _gFOC_Ctrl.in.s_motRPM, speed_td.target, speed_td.diff);
 	}
-	return 0;
+	return 1;
 }
 
 void PMSM_FOC_Schedule(void) {
@@ -335,10 +340,9 @@ void PMSM_FOC_Schedule(void) {
 	pwm_update_duty(_gFOC_Ctrl.out.n_Duty[0], _gFOC_Ctrl.out.n_Duty[1], _gFOC_Ctrl.out.n_Duty[2]);
 	pwm_update_sample(_gFOC_Ctrl.out.n_Sample1, _gFOC_Ctrl.out.n_Sample2, _gFOC_Ctrl.out.n_CPhases);
 
-#ifdef NO_SAMPLE_IDC
-	LowPass_Filter(_gFOC_Ctrl.out.s_FilterIdq.d, _gFOC_Ctrl.out.s_RealIdq.d, 0.01f);
-	LowPass_Filter(_gFOC_Ctrl.out.s_FilterIdq.q, _gFOC_Ctrl.out.s_RealIdq.q, 0.01f);
-#endif
+	if (_gFOC_Ctrl.ctrl_count % 5 == 0) {
+		plot_3data16(FtoS16x10(_gFOC_Ctrl.in.s_iABCFilter[0]), FtoS16x10(_gFOC_Ctrl.in.s_iABCFilter[1]), FtoS16x10(_gFOC_Ctrl.in.s_iABCFilter[2]));
+	}
 }
 
 void PMSM_FOC_LogDebug(void) {
@@ -418,7 +422,7 @@ void PMSM_FOC_idqCalc(void) {
 	if ((_gFOC_Ctrl.out.n_RunMode == CTRL_MODE_CURRENT) || (_gFOC_Ctrl.out.n_RunMode == CTRL_MODE_CURRENT_BRK)) {
 		_gFOC_Ctrl.in.s_targetCurrent = eCtrl_get_RefCurrent();
 		if (_gFOC_Ctrl.out.n_RunMode == CTRL_MODE_CURRENT_BRK) {
-			if (eCtrl_get_FinalCurrent() < 0.0001f && _gFOC_Ctrl.in.s_motRPM < MIN_RPM_EXIT_EBRAKE) {
+			if (eCtrl_get_FinalCurrent() < 0.0001f && _gFOC_Ctrl.in.s_motRPM < CONFIG_MIN_RPM_EXIT_EBRAKE) {
 				_gFOC_Ctrl.in.s_targetCurrent = 0;
 			}
 		}
@@ -426,7 +430,7 @@ void PMSM_FOC_idqCalc(void) {
 		float refTorque = eCtrl_get_FinalTorque();
 		_gFOC_Ctrl.pi_ctl_trq->max = refTorque;
 		_gFOC_Ctrl.pi_ctl_trq->min = -refTorque;
-		if ((eCtrl_get_FinalTorque() <= 0.0001f) && (_gFOC_Ctrl.in.s_motRPM < MIN_RPM_EXIT_EBRAKE)) {
+		if ((eCtrl_get_FinalTorque() <= 0.0001f) && (_gFOC_Ctrl.in.s_motRPM < CONFIG_MIN_RPM_EXIT_EBRAKE)) {
 			_gFOC_Ctrl.pi_ctl_trq->max = 0;
 			_gFOC_Ctrl.pi_ctl_trq->min = 0; //防止倒转
 		}
@@ -440,7 +444,7 @@ void PMSM_FOC_idqCalc(void) {
 		if (_gFOC_Ctrl.in.b_cruiseEna) {
 			refSpeed = _gFOC_Ctrl.in.s_cruiseRPM;
 		}else {
-			if ((eCtrl_get_FinalSpeed() == 0) && (_gFOC_Ctrl.in.s_motRPM < MIN_RPM_EXIT_EBRAKE)) {
+			if ((eCtrl_get_FinalSpeed() == 0) && (_gFOC_Ctrl.in.s_motRPM < CONFIG_MIN_RPM_EXIT_EBRAKE)) {
 				_gFOC_Ctrl.pi_ctl_spd->max = 0;
 				_gFOC_Ctrl.pi_ctl_spd->min = 0; //防止倒转
 			}
@@ -449,6 +453,7 @@ void PMSM_FOC_idqCalc(void) {
 		float maxTrq = PI_Controller_RunSat(_gFOC_Ctrl.pi_ctl_spd, errRef);
 		_gFOC_Ctrl.in.s_targetTorque = PMSM_FOC_Limit_Power(maxTrq);
 	}
+	TD_run(&speed_td, _gFOC_Ctrl.in.s_motRPM);
 	PMSM_FOC_idq_Assign();
 }
 
@@ -532,6 +537,15 @@ bool PMSM_FOC_SetCtrlMode(u8 mode) {
 	return true;
 }
 
+void PMSM_FOC_GetCurrentMode(u8 *data) {
+	data[0] = _gFOC_Ctrl.in.n_ctlMode;
+	data[0] |= _gFOC_Ctrl.out.n_RunMode << 2;
+	data[0] |= (_gFOC_Ctrl.in.b_cruiseEna?1:0) << 4;
+	data[0] |= (PMSM_FOC_Is_CruiseEnabled()?1:0) << 5;
+	data[0] |= (PMSM_FOC_is_epmMode()?1:0) << 6;
+	data[0] |= (0) << 7; //motor locked
+}
+
 u8 PMSM_FOC_GetCtrlMode(void) {
 	return _gFOC_Ctrl.in.n_ctlMode;
 }
@@ -556,7 +570,7 @@ void PMSM_FOC_SetOpenVdq(float vd, float vq) {
 bool PMSM_FOC_EnableCruise(bool enable) {
 	if (enable != _gFOC_Ctrl.in.b_cruiseEna) {
 		float motSpd = PMSM_FOC_GetSpeed();
-		if (motSpd < MIN_CRUISE_RPM) { //
+		if (enable && (motSpd < CONFIG_MIN_CRUISE_RPM)) { //
 			PMSM_FOC_SetErrCode(FOC_NowAllowed_With_Speed);
 			return false;
 		}
@@ -634,6 +648,10 @@ bool PMSM_FOC_Set_Torque(float trq) {
 
 bool PMSM_FOC_Set_CruiseSpeed(float rpm) {
 	if (PMSM_FOC_Is_CruiseEnabled()) {
+		if (rpm < CONFIG_MIN_CRUISE_RPM) {
+			PMSM_FOC_SetErrCode(FOC_NowAllowed_With_Speed);
+			return false;
+		}
 		_gFOC_Ctrl.in.s_cruiseRPM = rpm;
 		return true;
 	}
@@ -700,19 +718,22 @@ u32 PMSM_FOC_GetCriticalError(void) {
 	return _gFOC_Ctrl.out.n_CritiCalErrMask;
 }
 //获取母线电流
-float PMSM_FOC_Get_iDC(void) {
+float PMSM_FOC_Calc_iDC(void) {
 	float vd = _gFOC_Ctrl.out.s_OutVdq.d;
 	float vq = _gFOC_Ctrl.out.s_OutVdq.q;
+#ifdef NO_SAMPLE_IDC
+	LowPass_Filter(_gFOC_Ctrl.out.s_FilterIdq.d, _gFOC_Ctrl.out.s_RealIdq.d, 0.01f);
+	LowPass_Filter(_gFOC_Ctrl.out.s_FilterIdq.q, _gFOC_Ctrl.out.s_RealIdq.q, 0.01f);
+#endif
 	float id = _gFOC_Ctrl.out.s_FilterIdq.d;
 	float iq = _gFOC_Ctrl.out.s_FilterIdq.q;
-	
     /*
 		根据公式(等幅值变换,功率不等):
 		iDC x vDC = 2/3(iq x vq + id x vd);
 	*/
 	float m_pow = (vd * id + vq * iq); //s32q10
 	float raw_idc = m_pow / _gFOC_Ctrl.in.s_vDC * 1.5f; //s16q5
-	LowPass_Filter(_gFOC_Ctrl.out.s_FilteriDC, raw_idc, 0.1f);
+	LowPass_Filter(_gFOC_Ctrl.out.s_FilteriDC, raw_idc, 0.01f);
 	return _gFOC_Ctrl.out.s_FilteriDC;
 }
 

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

@@ -209,7 +209,7 @@ bool PMSM_FOC_Set_CruiseSpeed(float rpm);
 float PMSM_FOC_GetSpeed(void);
 bool PMSM_FOC_Lock_Motor(bool lock);
 void PMSM_FOC_Brake(bool brake);
-float PMSM_FOC_Get_iDC(void);
+float PMSM_FOC_Calc_iDC(void);
 void PMSM_FOC_LockMotor(bool lock);
 void PMSM_FOC_SetPid(u8 id, float kp, float ki, float kb);
 void PMSM_FOC_Set_Angle(float angle);
@@ -232,6 +232,7 @@ u32 PMSM_FOC_GetCriticalError(void);
 void PMSM_FOC_PhaseCurrLim(float lim);
 float PMSM_FOC_GetPhaseCurrLim(void);
 float PMSM_FOC_GetiBusLimit(void);
+void PMSM_FOC_GetCurrentMode(u8 *data);
 
 #endif /* _PMSM_FOC_Core_H__ */
 

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

@@ -52,7 +52,7 @@ bool eCtrl_enable_eBrake(bool enable) {
 		g_eCtrl.is_ebrake_shadow = false;
 		return g_eCtrl.is_ebrake_shadow;
 	}
-	if (enable && PMSM_FOC_GetSpeed() > MIN_RPM_FOR_EBRAKE) {
+	if (enable && PMSM_FOC_GetSpeed() > CONFIG_MIN_RPM_FOR_EBRAKE) {
 		g_eCtrl.is_ebrake_shadow = true;
 	}else if (!enable && !_eCtrl_isHwBrk_shutPower()){
 		g_eCtrl.is_ebrake_shadow = false;

+ 6 - 6
Applications/foc/core/torque.c

@@ -18,23 +18,23 @@ void torque_get_idq(float torque, float rpm, DQ_t *dq_out) {
 
 float speed_target_from_throttle(float f_throttle) {
 
-	if (f_throttle <= (THROTTLE_LOW_VALUE)) {
+	if (f_throttle <= (CONFIG_THROTTLE_LOW_VALUE)) {
 		return 0;
 	}
-	float delta = f_throttle - (THROTTLE_LOW_VALUE);
+	float delta = f_throttle - (CONFIG_THROTTLE_LOW_VALUE);
 
-	float ration = delta / (THROTTLE_MAX_VALUE - THROTTLE_LOW_VALUE);
+	float ration = delta / (CONFIG_THROTTLE_MAX_VALUE - CONFIG_THROTTLE_LOW_VALUE);
 
 	return (PMSM_FOC_GetSpeedLimit() * ration);
 }
 
 float torque_target_from_throttle(float f_throttle) {
-	if (f_throttle <= (THROTTLE_LOW_VALUE)) {
+	if (f_throttle <= (CONFIG_THROTTLE_LOW_VALUE)) {
 		return 0;
 	}
-	float delta = f_throttle - (THROTTLE_LOW_VALUE);
+	float delta = f_throttle - (CONFIG_THROTTLE_LOW_VALUE);
 
-	float ration = delta / (THROTTLE_MAX_VALUE - THROTTLE_LOW_VALUE);
+	float ration = delta / (CONFIG_THROTTLE_MAX_VALUE - CONFIG_THROTTLE_LOW_VALUE);
 
 	return (PMSM_FOC_GetTorqueLimit() * ration);
 }

+ 7 - 7
Applications/foc/foc_config.h

@@ -3,19 +3,19 @@
 
 
 /* 转把 */
-#define THROTTLE_LOW_VALUE 1.2f /* 转把最小值 */
-#define THROTTLE_MAX_VALUE 3.8f /* 转把最大值 */
-#define THROTTLE_MIN_RPM   10   /* 转把对应最小的速度 */
-#define THROTTLE_MIN_IDQ   20   /* 转把对应最小的扭矩电流 Q轴 */
-#define MIN_CRUISE_RPM 	   1000     /* 能启动定速巡航的最小速度 */
+#define CONFIG_THROTTLE_LOW_VALUE 1.2f /* 转把最小值 */
+#define CONFIG_THROTTLE_MAX_VALUE 3.8f /* 转把最大值 */
+#define CONFIG_THROTTLE_MIN_RPM   10   /* 转把对应最小的速度 */
+#define CONFIG_THROTTLE_MIN_IDQ   20   /* 转把对应最小的扭矩电流 Q轴 */
+#define CONFIG_MIN_CRUISE_RPM 	   1000     /* 能启动定速巡航的最小速度 */
 #ifdef GD32_FOC_DEMO
 #define MAX_vDC (16)   /* 母线最大电压 V*/
 #else
 #define MAX_vDC (50)   /* 母线最大电压 V*/
 #endif
 
-#define MIN_RPM_FOR_EBRAKE 1000 //进入电流回收的最小转速
-#define MIN_RPM_EXIT_EBRAKE 100 //推出电流回收的最小转速
+#define CONFIG_MIN_RPM_FOR_EBRAKE 1000 //进入电流回收的最小转速
+#define CONFIG_MIN_RPM_EXIT_EBRAKE 100 //推出电流回收的最小转速
 
 #define IDQ_CTRL_TS FOC_PWM_FS
 #define SPD_CTRL_TS 1000

+ 6 - 0
Applications/foc/motor/current.c

@@ -326,9 +326,15 @@ void phase_current_get(float *iABC){
 		cs->adc_ib = -(cs->adc_ia + cs->adc_ic);
 	}
 #ifdef HIGH_SIDE_CURRENT_SENSOR
+#ifdef CONFIG_PWM_UV_SWAP
 	iABC[1] = -cs->adc_ib * ADC_TO_CURR_ceof1;
 	iABC[2] = -cs->adc_ic * ADC_TO_CURR_ceof2;
 	iABC[0] = -(iABC[1] + iABC[2]);
+#else
+	iABC[1] = -cs->adc_ib * ADC_TO_CURR_ceof1;
+	iABC[0] = -cs->adc_ic * ADC_TO_CURR_ceof2;
+	iABC[2] = -(iABC[1] + iABC[0]);
+#endif
 #else
 	iABC[0] = -cs->adc_ia * ADC_TO_CURR_ceof;
 	iABC[1] = -cs->adc_ib * ADC_TO_CURR_ceof;

+ 15 - 7
Applications/foc/motor/encoder.c

@@ -6,7 +6,7 @@
 #include "libs/logger.h"
 #include "app/nv_storage.h"
 #include "math/fast_math.h"
-#include "encoder_off.h"
+#include "encoder_off2.h"
 
 /* 磁编码器使用一对极的磁铁,所以编码器获取的角度和机械角度相同需要转为电角度*/
 
@@ -183,6 +183,7 @@ void _encoder_caliberate_deinit(void) {
 
 #define MIN_OFF_COUNT 2
 void encoder_detect_offset(float angle){
+#if 1
 	_encoder_caliberate_init();
 	float delta = (g_encoder.abi_angle - angle);
 	if (delta > 200) {
@@ -202,6 +203,9 @@ void encoder_detect_offset(float angle){
 			g_encoder.encoder_off_count[g_encoder.last_cnt] += 0x10;
 		}
 	}
+#else
+	plot_2data16((s16)angle, (s16)g_encoder.abi_angle);
+#endif
 }
 static void _detect_off_finished(void);
 bool encoder_detect_finish(void) {
@@ -227,18 +231,21 @@ bool encoder_detect_finish(void) {
 static void _detect_off_finished(void) {
 	for (int i = 0; i < 1024; i++) {
 		float angle_off = g_encoder.encoder_off_map[i] / (((g_encoder.encoder_off_count[i] >> 4)&0xF) + (g_encoder.encoder_off_count[i]&0xF));
-		plot_3data16(0, 0, (s16)angle_off);
-		delay_ms(2);
+		plot_1data16((s16)angle_off);
+		delay_ms(10);
+		wdog_reload();
 	}
 	for (int i = 0; i < 1024; i++) {
 		float angle_off =  g_encoder.encoder_off_map[i] / (((g_encoder.encoder_off_count[i] >> 4)&0xF) + (g_encoder.encoder_off_count[i]&0xF));
-		plot_3data16(0, 0, (s16)angle_off);
-		delay_ms(2);
+		plot_1data16((s16)angle_off);
+		delay_ms(10);
+		wdog_reload();
 	}
 	for (int i = 0; i < 1024; i++) {
 		float angle_off =  g_encoder.encoder_off_map[i] / (((g_encoder.encoder_off_count[i] >> 4)&0xF) + (g_encoder.encoder_off_count[i]&0xF));
-		plot_3data16(0, 0, (s16)angle_off);
-		delay_ms(2);
+		plot_1data16((s16)angle_off);
+		delay_ms(10);
+		wdog_reload();
 	}	
 }
 
@@ -258,6 +265,7 @@ float encoder_zero_phase_detect(void) {
 		phase = g_encoder.pwm_angle;
 		total_ph += phase;
 	}
+	sys_debug("offset = %f\n", (total_ph/(float)count));
 	return (total_ph/(float)count);
 }
 

+ 113 - 0
Applications/foc/motor/encoder_off2.h

@@ -0,0 +1,113 @@
+#include "math/fix_math.h" 
+
+/* Auto gen by my tools, and use matlab to desing a FIR filter-(MC100/Simulink/Fir_angle.m) */
+/* Matlib Command: Fir=Fir_angle; angle_off=filter(Fir.Numerator, 1, angle_in); */
+/* angle_in is the data, by plot MC_tools */
+/* Use angle_out=single(angle_off) convert double to float */
+
+#define FIR_PHASE_SHIFT 477
+const static s16q10_t _encoder_off_map[] = {
+22285,22288,22291,22294,22297,22300,22303,22305,22307,22309,22311,22313,22314,22315,22316,22317,
+22318,22319,22319,22319,22319,22319,22319,22318,22317,22316,22315,22314,22312,22310,22308,22306,22303,22301,22298,22294,
+22291,22288,22284,22280,22275,22271,22266,22261,22256,22251,22245,22239,22233,22227,22221,22214,22207,22200,22193,22185,
+22177,22169,22161,22152,22144,22135,22126,22116,22107,22097,22087,22076,22066,22055,22044,22033,22022,22010,21998,21986,
+21974,21961,21948,21935,21922,21909,21895,21882,21868,21853,21839,21824,21810,21795,21779,21764,21748,21733,21717,21701,
+21684,21668,21651,21634,21617,21600,21582,21565,21547,21529,21511,21493,21474,21456,21437,21418,21399,21380,21361,21341,
+21322,21302,21282,21262,21242,21222,21202,21181,21161,21140,21119,21098,21077,21056,21035,21014,20993,20971,20950,20928,
+20907,20885,20864,20842,20820,20798,20776,20754,20732,20710,20688,20666,20644,20622,20600,20577,20555,20533,20511,20489,
+20467,20445,20423,20400,20378,20356,20334,20312,20291,20269,20247,20225,20203,20182,20160,20138,20117,20096,20074,20053,
+20032,20011,19990,19969,19948,19927,19907,19886,19866,19846,19826,19806,19786,19766,19747,19727,19708,19689,19670,19651,
+19633,19614,19596,19578,19560,19542,19525,19507,19490,19473,19456,19439,19423,19407,19391,19375,19359,19344,19328,19313,
+19299,19284,19270,19256,19242,19228,19215,19202,19189,19176,19164,19152,19140,19128,19117,19106,19095,19084,19074,19064,
+19054,19045,19035,19026,19018,19009,19001,18993,18986,18978,18971,18965,18958,18952,18946,18941,18936,18931,18926,18922,
+18918,18914,18911,18908,18905,18902,18900,18898,18897,18896,18895,18894,18894,18894,18894,18895,18896,18897,18899,18901,
+18903,18906,18909,18912,18915,18919,18923,18928,18933,18938,18943,18949,18955,18962,18968,18975,18983,18991,18999,19007,
+19016,19025,19034,19044,19054,19064,19075,19086,19097,19109,19120,19133,19145,19158,19171,19184,19198,19212,19227,19241,
+19256,19272,19287,19303,19319,19336,19353,19370,19387,19405,19423,19441,19460,19479,19498,19518,19537,19557,19578,19598,
+19619,19641,19662,19684,19706,19728,19751,19774,19797,19820,19844,19868,19892,19916,19941,19966,19991,20017,20042,20068,
+20095,20121,20148,20175,20202,20229,20257,20285,20313,20341,20370,20398,20427,20457,20486,20516,20545,20575,20606,20636,
+20667,20697,20729,20760,20791,20822,20854,20886,20918,20950,20983,21015,21048,21081,21114,21147,21180,21214,21247,21281,
+21315,21349,21383,21418,21452,21487,21521,21556,21591,21626,21661,21696,21732,21767,21802,21838,21874,21909,21945,21981,
+22017,22053,22089,22125,22161,22198,22234,22270,22307,22343,22380,22416,22453,22489,22526,22562,22599,22636,22672,22709,
+22745,22782,22819,22855,22892,22928,22965,23002,23038,23075,23111,23147,23184,23220,23256,23292,23328,23364,23400,23436,
+23472,23508,23544,23579,23615,23650,23686,23721,23756,23791,23826,23861,23896,23931,23965,23999,24034,24068,24102,24136,
+24169,24203,24236,24270,24303,24336,24369,24401,24434,24466,24498,24530,24562,24593,24625,24656,24687,24718,24748,24779,
+24809,24839,24869,24898,24927,24957,24986,25014,25043,25071,25099,25126,25154,25181,25208,25235,25261,25288,25314,25339,
+25365,25390,25415,25439,25464,25488,25511,25535,25558,25581,25604,25626,25648,25670,25692,25713,25734,25754,25775,25795,
+25814,25834,25853,25871,25890,25908,25926,25943,25960,25977,25994,26010,26026,26041,26056,26071,26085,26100,26113,26127,
+26140,26153,26165,26177,26189,26200,26211,26222,26232,26242,26252,26261,26270,26279,26287,26295,26302,26309,26316,26322,
+26328,26334,26339,26344,26349,26353,26357,26360,26363,26366,26368,26370,26372,26373,26374,26375,26375,26375,26374,26373,
+26372,26370,26368,26366,26363,26360,26357,26353,26349,26344,26339,26334,26329,26323,26316,26310,26303,26296,26288,26280,
+26271,26263,26254,26244,26234,26224,26214,26203,26192,26180,26169,26156,26144,26131,26118,26105,26091,26077,26063,26048,
+26033,26018,26002,25986,25970,25954,25937,25920,25903,25885,25867,25849,25830,25812,25793,25773,25754,25734,25714,25693,
+25673,25652,25631,25609,25588,25566,25544,25521,25499,25476,25453,25430,25406,25383,25359,25335,25311,25286,25262,25237,
+25212,25187,25161,25136,25110,25084,25058,25032,25006,24979,24953,24926,24899,24872,24845,24817,24790,24762,24735,24707,
+24679,24651,24623,24595,24567,24538,24510,24481,24453,24424,24396,24367,24338,24309,24280,24251,24222,24193,24164,24135,
+24106,24077,24048,24019,23990,23961,23931,23902,23873,23844,23815,23786,23757,23728,23699,23670,23641,23613,23584,23555,
+23527,23498,23470,23441,23413,23385,23357,23329,23301,23273,23245,23218,23190,23163,23135,23108,23081,23054,23027,23001,
+22974,22948,22921,22895,22869,22843,22818,22792,22767,22742,22717,22692,22667,22643,22618,22594,22570,22546,22523,22500,
+22476,22453,22431,22408,22386,22363,22341,22320,22298,22277,22256,22235,22214,22194,22173,22153,22133,22114,22094,22075,
+22056,22038,22019,22001,21983,21966,21948,21931,21914,21897,21881,21864,21848,21833,21817,21802,21787,21772,21758,21743,
+21729,21716,21702,21689,21676,21663,21651,21638,21626,21615,21603,21592,21581,21570,21560,21549,21539,21530,21520,21511,
+21502,21493,21485,21476,21468,21461,21453,21446,21439,21432,21426,21419,21413,21408,21402,21397,21391,21387,21382,21378,
+21373,21369,21366,21362,21359,21356,21353,21350,21348,21346,21344,21342,21341,21339,21338,21337,21337,21336,21336,21336,
+21336,21336,21337,21338,21339,21340,21341,21343,21344,21346,21348,21350,21353,21355,21358,21361,21364,21367,21370,21374,
+21378,21382,21386,21390,21394,21399,21403,21408,21413,21418,21423,21428,21434,21439,21445,21451,21457,21463,21469,21475,
+21482,21488,21495,21502,21508,21515,21522,21529,21537,21544,21551,21559,21566,21574,21581,21589,21597,21605,21613,21621,
+21629,21637,21646,21654,21662,21671,21679,21687,21696,21705,21713,21722,21730,21739,21748,21757,21765,21774,21783,21792,
+21801,21810,21818,21827,21836,21845,21854,21862,21871,21880,21889,21898,21906,21915,21924,21932,21941,21950,21958,21967,
+21975,21984,21992,22001,22009,22017,22025,22033,22042,22050,22057,22065,22073,22081,22089,22096,22104,22111,22118,22126,
+22133,22140,22147,22153,22160,22167,22173,22180,22186,22192,22198,22204,22210,22216,22221,22227,22232,22237,22242,22247,
+22252,22256,22261,22265,22269,22273,22277,22281,22285,22288,22291,22294,22297,22300,22303,22305,22307,22309,22311,22313,
+22314,22315,22316,22317,22318,22319,22319,22319,22319,22319,22319,22318,22317,22316,22315,22314,22312,22310,22308,22306,
+22303,22301,22298,22294,22291,22288,22284,22280,22275,22271,22266,22261,22256,22251,22245,22239,22233,22227,22221,22214,
+22207,22200,22193,22185,22177,22169,22161,22152,22144,22135,22126,22116,22107,22097,22087,22076,22066,22055,22044,22033,
+22022,22010,21998,21986,21974,21961,21948,21935,21922,21909,21895,21882,21868,21853,21839,21824,21810,21795,21779,21764,
+21748,21733,21717,21701,21684,21668,21651,21634,21617,21600,21582,21565,21547,21529,21511,21493,21474,21456,21437,21418,
+21399,21380,21361,21341,21322,21302,21282,21262,21242,21222,21202,21181,21161,21140,21119,21098,21077,21056,21035,21014,
+20993,20971,20950,20928,20907,20885,20864,20842,20820,20798,20776,20754,20732,20710,20688,20666,20644,20622,20600,20577,
+20555,20533,20511,20489,20467,20445,20423,20400,20378,20356,20334,20312,20291,20269,20247,20225,20203,20182,20160,20138,
+20117,20096,20074,20053,20032,20011,19990,19969,19948,19927,19907,19886,19866,19846,19826,19806,19786,19766,19747,19727,
+19708,19689,19670,19651,19633,19614,19596,19578,19560,19542,19525,19507,19490,19473,19456,19439,19423,19407,19391,19375,
+19359,19344,19328,19313,19299,19284,19270,19256,19242,19228,19215,19202,19189,19176,19164,19152,19140,19128,19117,19106,
+19095,19084,19074,19064,19054,19045,19035,19026,19018,19009,19001,18993,18986,18978,18971,18965,18958,18952,18946,18941,
+18936,18931,18926,18922,18918,18914,18911,18908,18905,18902,18900,18898,18897,18896,18895,18894,18894,18894,18894,18895,
+18896,18897,18899,18901,18903,18906,18909,18912,18915,18919,18923,18928,18933,18938,18943,18949,18955,18962,18968,18975,
+18983,18991,18999,19007,19016,19025,19034,19044,19054,19064,19075,19086,19097,19109,19120,19133,19145,19158,19171,19184,
+19198,19212,19227,19241,19256,19272,19287,19303,19319,19336,19353,19370,19387,19405,19423,19441,19460,19479,19498,19518,
+19537,19557,19578,19598,19619,19641,19662,19684,19706,19728,19751,19774,19797,19820,19844,19868,19892,19916,19941,19966,
+19991,20017,20042,20068,20095,20121,20148,20175,20202,20229,20257,20285,20313,20341,20370,20398,20427,20457,20486,20516,
+20545,20575,20606,20636,20667,20697,20729,20760,20791,20822,20854,20886,20918,20950,20983,21015,21048,21081,21114,21147,
+21180,21214,21247,21281,21315,21349,21383,21418,21452,21487,21521,21556,21591,21626,21661,21696,21732,21767,21802,21838,
+21874,21909,21945,21981,22017,22053,22089,22125,22161,22198,22234,22270,22307,22343,22380,22416,22453,22489,22526,22562,
+22599,22636,22672,22709,22745,22782,22819,22855,22892,22928,22965,23002,23038,23075,23111,23147,23184,23220,23256,23292,
+23328,23364,23400,23436,23472,23508,23544,23579,23615,23650,23686,23721,23756,23791,23826,23861,23896,23931,23965,23999,
+24034,24068,24102,24136,24169,24203,24236,24270,24303,24336,24369,24401,24434,24466,24498,24530,24562,24593,24625,24656,
+24687,24718,24748,24779,24809,24839,24869,24898,24927,24957,24986,25014,25043,25071,25099,25126,25154,25181,25208,25235,
+25261,25288,25314,25339,25365,25390,25415,25439,25464,25488,25511,25535,25558,25581,25604,25626,25648,25670,25692,25713,
+25734,25754,25775,25795,25814,25834,25853,25871,25890,25908,25926,25943,25960,25977,25994,26010,26026,26041,26056,26071,
+26085,26100,26113,26127,26140,26153,26165,26177,26189,26200,26211,26222,26232,26242,26252,26261,26270,26279,26287,26295,
+26302,26309,26316,26322,26328,26334,26339,26344,26349,26353,26357,26360,26363,26366,26368,26370,26372,26373,26374,26375,
+26375,26375,26374,26373,26372,26370,26368,26366,26363,26360,26357,26353,26349,26344,26339,26334,26329,26323,26316,26310,
+26303,26296,26288,26280,26271,26263,26254,26244,26234,26224,26214,26203,26192,26180,26169,26156,26144,26131,26118,26105,
+26091,26077,26063,26048,26033,26018,26002,25986,25970,25954,25937,25920,25903,25885,25867,25849,25830,25812,25793,25773,
+25754,25734,25714,25693,25673,25652,25631,25609,25588,25566,25544,25521,25499,25476,25453,25430,25406,25383,25359,25335,
+25311,25286,25262,25237,25212,25187,25161,25136,25110,25084,25058,25032,25006,24979,24953,24926,24899,24872,24845,24817,
+24790,24762,24735,24707,24679,24651,24623,24595,24567,24538,24510,24481,24453,24424,24396,24367,24338,24309,24280,24251,
+24222,24193,24164,24135,24106,24077,24048,24019,23990,23961,23931,23902,23873,23844,23815,23786,23757,23728,23699,23670,
+23641,23613,23584,23555,23527,23498,23470,23441,23413,23385,23357,23329,23301,23273,23245,23218,23190,23163,23135,23108,
+23081,23054,23027,23001,22974,22948,22921,22895,22869,22843,22818,22792,22767,22742,22717,22692,22667,22643,22618,22594,
+22570,22546,22523,22500,22476,22453,22431,22408,22386,22363,22341,22320,22298,22277,22256,22235,22214,22194,22173,22153,
+22133,22114,22094,22075,22056,22038,22019,22001,21983,21966,21948,21931,21914,21897,21881,21864,21848,21833,21817,21802,
+21787,21772,21758,21743,21729,21716,21702,21689,21676,21663,21651,21638,21626,21615,21603,21592,21581,21570,21560,21549,
+21539,21530,21520,21511,21502,21493,21485,21476,21468,21461,21453,21446,21439,21432,21426,21419,21413,21408,21402,21397,
+21391,21387,21382,21378,21373,21369,21366,21362,21359,21356,21353,21350,21348,21346,21344,21342,21341,21339,21338,21337,
+21337,21336,21336,21336,21336,21336,21337,21338,21339,21340,21341,21343,21344,21346,21348,21350,21353,21355,21358,21361,
+21364,21367,21370,21374,21378,21382,21386,21390,21394,21399,21403,21408,21413,21418,21423,21428,21434,21439,21445,21451,
+21457,21463,21469,21475,21482,21488,21495,21502,21508,21515,21522,21529,21537,21544,21551,21559,21566,21574,21581,21589,
+21597,21605,21613,21621,21629,21637,21646,21654,21662,21671,21679,21687,21696,21705,21713,21722,21730,21739,21748,21757,
+21765,21774,21783,21792,21801,21810,21818,21827,21836,21845,21854,21862,21871,21880,21889,21898,21906,21915,21924,21932,
+21941,21950,21958,21967,21975,21984,21992,22001,22009,22017,22025,22033,22042,22050,22057,22065,22073,22081,22089,22096,
+22104,22111,22118,22126,22133,22140,22147,22153,22160,22167,22173,22180,22186,22192,22198,22204,22210,22216,22221,22227,
+22232,22237,22242,22247,22252,22256,22261,22265,22269,22273,22277,22281,
+};

+ 12 - 2
Applications/foc/motor/motor.c

@@ -19,6 +19,8 @@
 #include "app/nv_storage.h"
 
 static bool mc_is_hwbrake(void);
+static void _pwm_brake_timer_handler(shark_timer_t *);
+static shark_timer_t _brake_timer = TIMER_INIT(_brake_timer, _pwm_brake_timer_handler);
 
 
 static motor_t motor = {
@@ -160,6 +162,7 @@ void mc_encoder_off_calibrate(s16 vd) {
 			delay_ms(2);
 			motor_encoder_offset(angle);
 		}
+		wdog_reload();
 		if (motor_encoder_offset_is_finish()) {
 			break;
 		}
@@ -172,6 +175,7 @@ void mc_encoder_off_calibrate(s16 vd) {
 			delay_ms(2);
 			motor_encoder_offset(angle);
 		}
+		wdog_reload();
 		if (motor_encoder_offset_is_finish()) {
 			break;
 		}
@@ -179,6 +183,7 @@ void mc_encoder_off_calibrate(s16 vd) {
 	delay_ms(500);
 	PMSM_FOC_SetOpenVdq(0, 0);
 	delay_ms(500);
+	wdog_reload();
 	adc_stop_convert();
 	pwm_stop();
 	PMSM_FOC_Stop();
@@ -243,7 +248,7 @@ bool mc_lock_motor(bool lock) {
 
 
 bool mc_throttle_released(void) {
-	return get_throttle_float() < THROTTLE_LOW_VALUE;
+	return get_throttle_float() < CONFIG_THROTTLE_LOW_VALUE;
 }
 
 static bool mc_is_hwbrake(void) {
@@ -290,8 +295,13 @@ void MC_Brake_IRQHandler(void) {
 	}
 }
 
+static void _pwm_brake_timer_handler(shark_timer_t *t){
+	pwm_brake_enable(true);
+}
 
 void MC_Protect_IRQHandler(void){
+	pwm_brake_enable(false);
+	shark_timer_post(&_brake_timer, 1000);
 	if (!motor.b_start) {
 		return;
 	}
@@ -345,7 +355,7 @@ void Sched_MC_mTask(void) {
 #if ANGLE_TEST
 	_debug_angle();
 #endif
-	PMSM_FOC_Get_iDC();
+	PMSM_FOC_Calc_iDC();
 	if ((runMode != CTRL_MODE_OPEN) || (motor.mode != CTRL_MODE_OPEN)) {
 		if (motor.mode != CTRL_MODE_OPEN) {
 			u32 mask;

+ 44 - 0
Applications/math/fast_math.c

@@ -231,3 +231,47 @@ void fast_sincosf(float angle, float *sin, float *cos){
 	}
 }
 #endif
+
+void TD_run(TD_t *td, float in)
+{
+  float rtb_DiscreteTimeIntegrator;
+
+  /* Outputs for Atomic SubSystem: '<Root>/Subsystem' */
+  /* DiscreteIntegrator: '<S1>/Discrete-Time Integrator' */
+  rtb_DiscreteTimeIntegrator = td->Integrator;
+
+  /* Outport: '<Root>/target' incorporates:
+   *  DiscreteIntegrator: '<S1>/Discrete-Time Integrator1'
+   */
+  td->target = td->Integrator1;
+
+  /* Update for DiscreteIntegrator: '<S1>/Discrete-Time Integrator' incorporates:
+   *  DiscreteIntegrator: '<S1>/Discrete-Time Integrator1'
+   *  Gain: '<S1>/Gain'
+   *  Gain: '<S1>/Gain1'
+   *  Inport: '<Root>/in'
+   *  Inport: '<Root>/time'
+   *  Math: '<S1>/Math Function'
+   *  Product: '<S1>/Product'
+   *  Product: '<S1>/Product1'
+   *  Sum: '<S1>/Sum'
+   *  Sum: '<S1>/Sum1'
+   */
+  td->Integrator += ((td->Integrator1 - in) * (-(td->time * td->time)) + (-2.0) * td->time * td->Integrator) * td->DT;
+
+  /* Update for DiscreteIntegrator: '<S1>/Discrete-Time Integrator1' */
+  td->Integrator1 += td->DT * rtb_DiscreteTimeIntegrator;
+
+  /* End of Outputs for SubSystem: '<Root>/Subsystem' */
+
+  /* Outport: '<Root>/diff' */
+  td->diff = rtb_DiscreteTimeIntegrator;
+}
+
+void TD_Init(TD_t *td, float wc, float DT) {
+	memset(td, 0, sizeof(TD_t));
+	td->DT = DT;
+	td->time = wc *wc;
+}
+
+

+ 11 - 0
Applications/math/fast_math.h

@@ -66,5 +66,16 @@ static float limitRPM(float vel_limit, float vel_estimate, float vel_gain, float
 	return Tmax;
 }
 
+typedef struct {                         /* '<Root>/in' */
+  float time;                         /* '<Root>/time' */
+  float target;
+  float diff;
+  float Integrator;
+  float Integrator1;
+  float DT;
+}TD_t;
+
+void TD_run(TD_t *td, float in);
+void TD_Init(TD_t *td, float wc, float DT);
 #endif /* _Fast_Math_H__ */
 

+ 14 - 0
Project/MC100.uvoptx

@@ -117,6 +117,10 @@
         <pMon>Segger\JL2CM3.dll</pMon>
       </DebugOpt>
       <TargetDriverDllRegistry>
+        <SetRegEntry>
+          <Number>0</Number>
+          <Key>DLGUARM</Key>
+        </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
           <Key>ARMRTXEVENTFLAGS</Key>
@@ -200,6 +204,16 @@
           <WinNumber>1</WinNumber>
           <ItemText>g_meas_MCTask,0x0A</ItemText>
         </Ww>
+        <Ww>
+          <count>11</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>target_d</ItemText>
+        </Ww>
+        <Ww>
+          <count>12</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>target_q</ItemText>
+        </Ww>
       </WatchWindow1>
       <Tracepoint>
         <THDelay>0</THDelay>

+ 1 - 1
Project/MC100.uvprojx

@@ -337,7 +337,7 @@
             <v6Rtti>0</v6Rtti>
             <VariousControls>
               <MiscControls>--gnu</MiscControls>
-              <Define>USE_STDPERIPH_DRIVER,GD32F30X_HD,BACK_TRACE,MC100_HW_V1,CONFIG_CAN_IAP</Define>
+              <Define>USE_STDPERIPH_DRIVER,GD32F30X_HD,BACK_TRACE,MC100_HW_V1,CONFIG_CAN_IAP,JTAG_DEBUG</Define>
               <Undefine></Undefine>
               <IncludePath>..\Librarys\CMSIS\Include,..\Librarys\CMSIS\GD\GD32F30x\Include,..\Librarys\GD32F30x_Drivers\include,..\Applications;..\Simulink\PMSM_Controller_ert_rtw</IncludePath>
             </VariousControls>

BIN=BIN
Simulink/ADRC.slx


BIN=BIN
Simulink/FOC.slx.autosave


+ 26 - 0
Simulink/Fir_angle2.m

@@ -0,0 +1,26 @@
+function Hd = Fir_angle2
+%FIR_ANGLE2 返回离散时间滤波器对象。
+
+% MATLAB Code
+% Generated by MATLAB(R) 9.9 and DSP System Toolbox 9.11.
+% Generated on: 15-Oct-2022 15:21:25
+
+% Equiripple Lowpass filter designed using the FIRPM function.
+
+% All frequency values are in Hz.
+Fs = 500;  % Sampling Frequency
+
+Fpass = 1;                 % Passband Frequency
+Fstop = 5;                 % Stopband Frequency
+Dpass = 5.7564627261e-05;  % Passband Ripple
+Dstop = 0.0001;            % Stopband Attenuation
+dens  = 20;                % Density Factor
+
+% Calculate the order from the parameters using FIRPMORD.
+[N, Fo, Ao, W] = firpmord([Fpass, Fstop]/(Fs/2), [1 0], [Dpass, Dstop]);
+
+% Calculate the coefficients using the FIRPM function.
+b  = firpm(N, Fo, Ao, W, {dens});
+Hd = dfilt.dffir(b);
+
+% [EOF]

BIN=BIN
Simulink/MotorController_FOC.slxc


+ 16 - 0
Simulink/Subsystem_ert_rtw/Subsystem.bat

@@ -0,0 +1,16 @@
+
+call "setup_msvc.bat"
+
+
+call  "\\DESKTOP-C3O4FD7\D$\Program Files\R2020b\bin\win64\checkMATLABRootForDriveMap.exe" "\\DESKTOP-C3O4FD7\D$\Program Files\R2020b"  > mlEnv.txt
+for /f %%a in (mlEnv.txt) do set "%%a"\n
+cd .
+
+if "%1"=="" (nmake MATLAB_ROOT=%MATLAB_ROOT% ALT_MATLAB_ROOT=%ALT_MATLAB_ROOT% MATLAB_BIN=%MATLAB_BIN% ALT_MATLAB_BIN=%ALT_MATLAB_BIN%  -f Subsystem.mk all) else (nmake MATLAB_ROOT=%MATLAB_ROOT% ALT_MATLAB_ROOT=%ALT_MATLAB_ROOT% MATLAB_BIN=%MATLAB_BIN% ALT_MATLAB_BIN=%ALT_MATLAB_BIN%  -f Subsystem.mk %1)
+@if errorlevel 1 goto error_exit
+
+exit 0
+
+:error_exit
+echo The make command returned an error of %errorlevel%
+exit 1

+ 78 - 0
Simulink/Subsystem_ert_rtw/Subsystem.c

@@ -0,0 +1,78 @@
+/*
+ * File: Subsystem.c
+ *
+ * Code generated for Simulink model 'Subsystem'.
+ *
+ * Model version                  : 1.2
+ * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
+ * C/C++ source code generated on : Fri Oct 14 20:06:32 2022
+ *
+ * Target selection: ert.tlc
+ * Embedded hardware selection: ARM Compatible->ARM Cortex-M
+ * Code generation objectives:
+ *    1. Execution efficiency
+ *    2. RAM efficiency
+ * Validation result: Not run
+ */
+
+#include "Subsystem.h"
+
+/* Block signals and states (default storage) */
+DW rtDW;
+
+/* External inputs (root inport signals with default storage) */
+ExtU rtU;
+
+/* External outputs (root outports fed by signals with default storage) */
+ExtY rtY;
+
+/* Model step function */
+void Subsystem_step(void)
+{
+  real_T rtb_DiscreteTimeIntegrator;
+
+  /* Outputs for Atomic SubSystem: '<Root>/Subsystem' */
+  /* DiscreteIntegrator: '<S1>/Discrete-Time Integrator' */
+  rtb_DiscreteTimeIntegrator = rtDW.DiscreteTimeIntegrator_DSTATE;
+
+  /* Outport: '<Root>/target' incorporates:
+   *  DiscreteIntegrator: '<S1>/Discrete-Time Integrator1'
+   */
+  rtY.target = rtDW.DiscreteTimeIntegrator1_DSTATE;
+
+  /* Update for DiscreteIntegrator: '<S1>/Discrete-Time Integrator' incorporates:
+   *  DiscreteIntegrator: '<S1>/Discrete-Time Integrator1'
+   *  Gain: '<S1>/Gain'
+   *  Gain: '<S1>/Gain1'
+   *  Inport: '<Root>/in'
+   *  Inport: '<Root>/time'
+   *  Math: '<S1>/Math Function'
+   *  Product: '<S1>/Product'
+   *  Product: '<S1>/Product1'
+   *  Sum: '<S1>/Sum'
+   *  Sum: '<S1>/Sum1'
+   */
+  rtDW.DiscreteTimeIntegrator_DSTATE += ((rtDW.DiscreteTimeIntegrator1_DSTATE -
+    rtU.in) * -(rtU.time * rtU.time) + -2.0 * rtU.time *
+    rtDW.DiscreteTimeIntegrator_DSTATE) * 6.25E-5;
+
+  /* Update for DiscreteIntegrator: '<S1>/Discrete-Time Integrator1' */
+  rtDW.DiscreteTimeIntegrator1_DSTATE += 6.25E-5 * rtb_DiscreteTimeIntegrator;
+
+  /* End of Outputs for SubSystem: '<Root>/Subsystem' */
+
+  /* Outport: '<Root>/diff' */
+  rtY.diff = rtb_DiscreteTimeIntegrator;
+}
+
+/* Model initialize function */
+void Subsystem_initialize(void)
+{
+  /* (no initialization code required) */
+}
+
+/*
+ * File trailer for generated code.
+ *
+ * [EOF]
+ */

+ 86 - 0
Simulink/Subsystem_ert_rtw/Subsystem.h

@@ -0,0 +1,86 @@
+/*
+ * File: Subsystem.h
+ *
+ * Code generated for Simulink model 'Subsystem'.
+ *
+ * Model version                  : 1.2
+ * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
+ * C/C++ source code generated on : Fri Oct 14 20:06:32 2022
+ *
+ * Target selection: ert.tlc
+ * Embedded hardware selection: ARM Compatible->ARM Cortex-M
+ * Code generation objectives:
+ *    1. Execution efficiency
+ *    2. RAM efficiency
+ * Validation result: Not run
+ */
+
+#ifndef RTW_HEADER_Subsystem_h_
+#define RTW_HEADER_Subsystem_h_
+#ifndef Subsystem_COMMON_INCLUDES_
+#define Subsystem_COMMON_INCLUDES_
+#include "rtwtypes.h"
+#endif                                 /* Subsystem_COMMON_INCLUDES_ */
+
+/* Model Code Variants */
+
+/* Macros for accessing real-time model data structure */
+
+/* Block signals and states (default storage) for system '<Root>' */
+typedef struct {
+  real_T DiscreteTimeIntegrator_DSTATE;/* '<S1>/Discrete-Time Integrator' */
+  real_T DiscreteTimeIntegrator1_DSTATE;/* '<S1>/Discrete-Time Integrator1' */
+} DW;
+
+/* External inputs (root inport signals with default storage) */
+typedef struct {
+  real_T in;                           /* '<Root>/in' */
+  real_T time;                         /* '<Root>/time' */
+} ExtU;
+
+/* External outputs (root outports fed by signals with default storage) */
+typedef struct {
+  real_T target;                       /* '<Root>/target' */
+  real_T diff;                         /* '<Root>/diff' */
+} ExtY;
+
+/* Block signals and states (default storage) */
+extern DW rtDW;
+
+/* External inputs (root inport signals with default storage) */
+extern ExtU rtU;
+
+/* External outputs (root outports fed by signals with default storage) */
+extern ExtY rtY;
+
+/* Model entry point functions */
+extern void Subsystem_initialize(void);
+extern void Subsystem_step(void);
+
+/*-
+ * The generated code includes comments that allow you to trace directly
+ * back to the appropriate location in the model.  The basic format
+ * is <system>/block_name, where system is the system number (uniquely
+ * assigned by Simulink) and block_name is the name of the block.
+ *
+ * Note that this particular code originates from a subsystem build,
+ * and has its own system numbers different from the parent model.
+ * Refer to the system hierarchy for this subsystem below, and use the
+ * MATLAB hilite_system command to trace the generated code back
+ * to the parent model.  For example,
+ *
+ * hilite_system('ADRC/Subsystem')    - opens subsystem ADRC/Subsystem
+ * hilite_system('ADRC/Subsystem/Kp') - opens and selects block Kp
+ *
+ * Here is the system hierarchy for this model
+ *
+ * '<Root>' : 'ADRC'
+ * '<S1>'   : 'ADRC/Subsystem'
+ */
+#endif                                 /* RTW_HEADER_Subsystem_h_ */
+
+/*
+ * File trailer for generated code.
+ *
+ * [EOF]
+ */

+ 406 - 0
Simulink/Subsystem_ert_rtw/Subsystem.mk

@@ -0,0 +1,406 @@
+###########################################################################
+## Makefile generated for component 'Subsystem'. 
+## 
+## Makefile     : Subsystem.mk
+## Generated on : Fri Oct 14 20:06:41 2022
+## Final product: $(RELATIVE_PATH_TO_ANCHOR)\Subsystem.exe
+## Product type : executable
+## 
+###########################################################################
+
+###########################################################################
+## MACROS
+###########################################################################
+
+# Macro Descriptions:
+# PRODUCT_NAME            Name of the system to build
+# MAKEFILE                Name of this makefile
+# COMPILER_COMMAND_FILE   Compiler command listing model reference header paths
+# CMD_FILE                Command file
+
+PRODUCT_NAME              = Subsystem
+MAKEFILE                  = Subsystem.mk
+MATLAB_ROOT               = D:\Program Files\R2020b
+MATLAB_BIN                = D:\Program Files\R2020b\bin
+MATLAB_ARCH_BIN           = $(MATLAB_BIN)\win64
+START_DIR                 = E:\works\mcu\MC100\Simulink
+SOLVER                    = 
+SOLVER_OBJ                = 
+CLASSIC_INTERFACE         = 0
+TGT_FCN_LIB               = ISO_C
+MODEL_HAS_DYNAMICALLY_LOADED_SFCNS = 0
+RELATIVE_PATH_TO_ANCHOR   = ..
+COMPILER_COMMAND_FILE     = Subsystem_comp.rsp
+CMD_FILE                  = Subsystem.rsp
+C_STANDARD_OPTS           = 
+CPP_STANDARD_OPTS         = 
+NODEBUG                   = 1
+
+###########################################################################
+## TOOLCHAIN SPECIFICATIONS
+###########################################################################
+
+# Toolchain Name:          Microsoft Visual C++ 2019 v16.0 | nmake (64-bit Windows)
+# Supported Version(s):    16.0
+# ToolchainInfo Version:   2020b
+# Specification Revision:  1.0
+# 
+#-------------------------------------------
+# Macros assumed to be defined elsewhere
+#-------------------------------------------
+
+# NODEBUG
+# cvarsdll
+# cvarsmt
+# conlibsmt
+# ldebug
+# conflags
+# cflags
+
+#-----------
+# MACROS
+#-----------
+
+MW_EXTERNLIB_DIR    = $(MATLAB_ROOT)\extern\lib\win64\microsoft
+MW_LIB_DIR          = $(MATLAB_ROOT)\lib\win64
+CPU                 = AMD64
+APPVER              = 5.02
+CVARSFLAG           = $(cvarsmt)
+CFLAGS_ADDITIONAL   = -D_CRT_SECURE_NO_WARNINGS
+CPPFLAGS_ADDITIONAL = -EHs -D_CRT_SECURE_NO_WARNINGS /wd4251
+LIBS_TOOLCHAIN      = $(conlibs)
+
+TOOLCHAIN_SRCS = 
+TOOLCHAIN_INCS = 
+TOOLCHAIN_LIBS = 
+
+#------------------------
+# BUILD TOOL COMMANDS
+#------------------------
+
+# C Compiler: Microsoft Visual C Compiler
+CC = cl
+
+# Linker: Microsoft Visual C Linker
+LD = link
+
+# C++ Compiler: Microsoft Visual C++ Compiler
+CPP = cl
+
+# C++ Linker: Microsoft Visual C++ Linker
+CPP_LD = link
+
+# Archiver: Microsoft Visual C/C++ Archiver
+AR = lib
+
+# MEX Tool: MEX Tool
+MEX_PATH = $(MATLAB_ARCH_BIN)
+MEX = "$(MEX_PATH)\mex"
+
+# Download: Download
+DOWNLOAD =
+
+# Execute: Execute
+EXECUTE = $(PRODUCT)
+
+# Builder: NMAKE Utility
+MAKE = nmake
+
+
+#-------------------------
+# Directives/Utilities
+#-------------------------
+
+CDEBUG              = -Zi
+C_OUTPUT_FLAG       = -Fo
+LDDEBUG             = /DEBUG
+OUTPUT_FLAG         = -out:
+CPPDEBUG            = -Zi
+CPP_OUTPUT_FLAG     = -Fo
+CPPLDDEBUG          = /DEBUG
+OUTPUT_FLAG         = -out:
+ARDEBUG             =
+STATICLIB_OUTPUT_FLAG = -out:
+MEX_DEBUG           = -g
+RM                  = @del
+ECHO                = @echo
+MV                  = @ren
+RUN                 = @cmd /C
+
+#----------------------------------------
+# "Faster Builds" Build Configuration
+#----------------------------------------
+
+ARFLAGS              = /nologo
+CFLAGS               = $(cflags) $(CVARSFLAG) $(CFLAGS_ADDITIONAL) \
+                       /Od /Oy-
+CPPFLAGS             = /TP $(cflags) $(CVARSFLAG) $(CPPFLAGS_ADDITIONAL) \
+                       /Od /Oy-
+CPP_LDFLAGS          = $(ldebug) $(conflags) $(LIBS_TOOLCHAIN)
+CPP_SHAREDLIB_LDFLAGS  = $(ldebug) $(conflags) $(LIBS_TOOLCHAIN) \
+                         -dll -def:$(DEF_FILE)
+DOWNLOAD_FLAGS       =
+EXECUTE_FLAGS        =
+LDFLAGS              = $(ldebug) $(conflags) $(LIBS_TOOLCHAIN)
+MEX_CPPFLAGS         =
+MEX_CPPLDFLAGS       =
+MEX_CFLAGS           =
+MEX_LDFLAGS          =
+MAKE_FLAGS           = -f $(MAKEFILE)
+SHAREDLIB_LDFLAGS    = $(ldebug) $(conflags) $(LIBS_TOOLCHAIN) \
+                       -dll -def:$(DEF_FILE)
+
+
+
+###########################################################################
+## OUTPUT INFO
+###########################################################################
+
+PRODUCT = $(RELATIVE_PATH_TO_ANCHOR)\Subsystem.exe
+PRODUCT_TYPE = "executable"
+BUILD_TYPE = "Top-Level Standalone Executable"
+
+###########################################################################
+## INCLUDE PATHS
+###########################################################################
+
+INCLUDES_BUILDINFO = 
+
+INCLUDES = $(INCLUDES_BUILDINFO)
+
+###########################################################################
+## DEFINES
+###########################################################################
+
+DEFINES_BUILD_ARGS = -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DTERMFCN=0 -DONESTEPFCN=1 -DMAT_FILE=0 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0
+DEFINES_CUSTOM = 
+DEFINES_OPTS = -DTID01EQ=0
+DEFINES_STANDARD = -DMODEL=Subsystem -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0
+
+DEFINES = $(DEFINES_BUILD_ARGS) $(DEFINES_CUSTOM) $(DEFINES_OPTS) $(DEFINES_STANDARD)
+
+###########################################################################
+## SOURCE FILES
+###########################################################################
+
+SRCS = $(START_DIR)\Subsystem_ert_rtw\Subsystem.c
+
+MAIN_SRC = $(START_DIR)\Subsystem_ert_rtw\ert_main.c
+
+ALL_SRCS = $(SRCS) $(MAIN_SRC)
+
+###########################################################################
+## OBJECTS
+###########################################################################
+
+OBJS = Subsystem.obj
+
+MAIN_OBJ = ert_main.obj
+
+ALL_OBJS = $(OBJS) $(MAIN_OBJ)
+
+###########################################################################
+## PREBUILT OBJECT FILES
+###########################################################################
+
+PREBUILT_OBJS = 
+
+###########################################################################
+## LIBRARIES
+###########################################################################
+
+LIBS = 
+
+###########################################################################
+## SYSTEM LIBRARIES
+###########################################################################
+
+SYSTEM_LIBS = 
+
+###########################################################################
+## ADDITIONAL TOOLCHAIN FLAGS
+###########################################################################
+
+#---------------
+# C Compiler
+#---------------
+
+CFLAGS_BASIC = $(DEFINES) @$(COMPILER_COMMAND_FILE)
+
+CFLAGS = $(CFLAGS) $(CFLAGS_BASIC)
+
+#-----------------
+# C++ Compiler
+#-----------------
+
+CPPFLAGS_BASIC = $(DEFINES) @$(COMPILER_COMMAND_FILE)
+
+CPPFLAGS = $(CPPFLAGS) $(CPPFLAGS_BASIC)
+
+###########################################################################
+## INLINED COMMANDS
+###########################################################################
+
+
+!include $(MATLAB_ROOT)\rtw\c\tools\vcdefs.mak
+
+
+###########################################################################
+## PHONY TARGETS
+###########################################################################
+
+.PHONY : all build buildobj clean info prebuild download execute set_environment_variables
+
+
+all : build
+	@cmd /C "@echo ### Successfully generated all binary outputs."
+
+
+build : set_environment_variables prebuild $(PRODUCT)
+
+
+buildobj : set_environment_variables prebuild $(OBJS) $(PREBUILT_OBJS)
+	@cmd /C "@echo ### Successfully generated all binary outputs."
+
+
+prebuild : 
+
+
+download : $(PRODUCT)
+
+
+execute : download
+	@cmd /C "@echo ### Invoking postbuild tool "Execute" ..."
+	$(EXECUTE) $(EXECUTE_FLAGS)
+	@cmd /C "@echo ### Done invoking postbuild tool."
+
+
+set_environment_variables : 
+	@set INCLUDE=$(INCLUDES);$(INCLUDE)
+	@set LIB=$(LIB)
+
+
+###########################################################################
+## FINAL TARGET
+###########################################################################
+
+#-------------------------------------------
+# Create a standalone executable            
+#-------------------------------------------
+
+$(PRODUCT) : $(OBJS) $(PREBUILT_OBJS) $(MAIN_OBJ)
+	@cmd /C "@echo ### Creating standalone executable "$(PRODUCT)" ..."
+	$(LD) $(LDFLAGS) -out:$(PRODUCT) @$(CMD_FILE) $(SYSTEM_LIBS) $(TOOLCHAIN_LIBS)
+	@cmd /C "@echo ### Created: $(PRODUCT)"
+
+
+###########################################################################
+## INTERMEDIATE TARGETS
+###########################################################################
+
+#---------------------
+# SOURCE-TO-OBJECT
+#---------------------
+
+.c.obj :
+	$(CC) $(CFLAGS) -Fo"$@" "$<"
+
+
+.cpp.obj :
+	$(CPP) $(CPPFLAGS) -Fo"$@" "$<"
+
+
+{$(RELATIVE_PATH_TO_ANCHOR)}.c.obj :
+	$(CC) $(CFLAGS) -Fo"$@" "$<"
+
+
+{$(RELATIVE_PATH_TO_ANCHOR)}.cpp.obj :
+	$(CPP) $(CPPFLAGS) -Fo"$@" "$<"
+
+
+{$(START_DIR)}.c.obj :
+	$(CC) $(CFLAGS) -Fo"$@" "$<"
+
+
+{$(START_DIR)}.cpp.obj :
+	$(CPP) $(CPPFLAGS) -Fo"$@" "$<"
+
+
+{$(START_DIR)\Subsystem_ert_rtw}.c.obj :
+	$(CC) $(CFLAGS) -Fo"$@" "$<"
+
+
+{$(START_DIR)\Subsystem_ert_rtw}.cpp.obj :
+	$(CPP) $(CPPFLAGS) -Fo"$@" "$<"
+
+
+{$(MATLAB_ROOT)\rtw\c\src}.c.obj :
+	$(CC) $(CFLAGS) -Fo"$@" "$<"
+
+
+{$(MATLAB_ROOT)\rtw\c\src}.cpp.obj :
+	$(CPP) $(CPPFLAGS) -Fo"$@" "$<"
+
+
+{$(MATLAB_ROOT)\simulink\src}.c.obj :
+	$(CC) $(CFLAGS) -Fo"$@" "$<"
+
+
+{$(MATLAB_ROOT)\simulink\src}.cpp.obj :
+	$(CPP) $(CPPFLAGS) -Fo"$@" "$<"
+
+
+Subsystem.obj : $(START_DIR)\Subsystem_ert_rtw\Subsystem.c
+	$(CC) $(CFLAGS) -Fo"$@" $(START_DIR)\Subsystem_ert_rtw\Subsystem.c
+
+
+ert_main.obj : $(START_DIR)\Subsystem_ert_rtw\ert_main.c
+	$(CC) $(CFLAGS) -Fo"$@" $(START_DIR)\Subsystem_ert_rtw\ert_main.c
+
+
+###########################################################################
+## DEPENDENCIES
+###########################################################################
+
+$(ALL_OBJS) : rtw_proj.tmw $(COMPILER_COMMAND_FILE) $(MAKEFILE)
+
+
+###########################################################################
+## MISCELLANEOUS TARGETS
+###########################################################################
+
+info : 
+	@cmd /C "@echo ### PRODUCT = $(PRODUCT)"
+	@cmd /C "@echo ### PRODUCT_TYPE = $(PRODUCT_TYPE)"
+	@cmd /C "@echo ### BUILD_TYPE = $(BUILD_TYPE)"
+	@cmd /C "@echo ### INCLUDES = $(INCLUDES)"
+	@cmd /C "@echo ### DEFINES = $(DEFINES)"
+	@cmd /C "@echo ### ALL_SRCS = $(ALL_SRCS)"
+	@cmd /C "@echo ### ALL_OBJS = $(ALL_OBJS)"
+	@cmd /C "@echo ### LIBS = $(LIBS)"
+	@cmd /C "@echo ### MODELREF_LIBS = $(MODELREF_LIBS)"
+	@cmd /C "@echo ### SYSTEM_LIBS = $(SYSTEM_LIBS)"
+	@cmd /C "@echo ### TOOLCHAIN_LIBS = $(TOOLCHAIN_LIBS)"
+	@cmd /C "@echo ### CFLAGS = $(CFLAGS)"
+	@cmd /C "@echo ### LDFLAGS = $(LDFLAGS)"
+	@cmd /C "@echo ### SHAREDLIB_LDFLAGS = $(SHAREDLIB_LDFLAGS)"
+	@cmd /C "@echo ### CPPFLAGS = $(CPPFLAGS)"
+	@cmd /C "@echo ### CPP_LDFLAGS = $(CPP_LDFLAGS)"
+	@cmd /C "@echo ### CPP_SHAREDLIB_LDFLAGS = $(CPP_SHAREDLIB_LDFLAGS)"
+	@cmd /C "@echo ### ARFLAGS = $(ARFLAGS)"
+	@cmd /C "@echo ### MEX_CFLAGS = $(MEX_CFLAGS)"
+	@cmd /C "@echo ### MEX_CPPFLAGS = $(MEX_CPPFLAGS)"
+	@cmd /C "@echo ### MEX_LDFLAGS = $(MEX_LDFLAGS)"
+	@cmd /C "@echo ### MEX_CPPLDFLAGS = $(MEX_CPPLDFLAGS)"
+	@cmd /C "@echo ### DOWNLOAD_FLAGS = $(DOWNLOAD_FLAGS)"
+	@cmd /C "@echo ### EXECUTE_FLAGS = $(EXECUTE_FLAGS)"
+	@cmd /C "@echo ### MAKE_FLAGS = $(MAKE_FLAGS)"
+
+
+clean : 
+	$(ECHO) "### Deleting all derived files..."
+	@if exist $(PRODUCT) $(RM) $(PRODUCT)
+	$(RM) $(ALL_OBJS)
+	$(ECHO) "### Deleted all derived files."
+
+

+ 2 - 0
Simulink/Subsystem_ert_rtw/Subsystem.rsp

@@ -0,0 +1,2 @@
+Subsystem.obj
+ert_main.obj

+ 7 - 0
Simulink/Subsystem_ert_rtw/Subsystem_comp.rsp

@@ -0,0 +1,7 @@
+-IE:\works\mcu\MC100\Simulink
+-IE:\works\mcu\MC100\Simulink\Subsystem_ert_rtw
+-I"D:\Program Files\R2020b\extern\include"
+-I"D:\Program Files\R2020b\simulink\include"
+-I"D:\Program Files\R2020b\rtw\c\src"
+-I"D:\Program Files\R2020b\rtw\c\src\ext_mode\common"
+-I"D:\Program Files\R2020b\rtw\c\ert"

+ 0 - 0
Simulink/Subsystem_ert_rtw/Subsystem_ref.rsp


BIN=BIN
Simulink/Subsystem_ert_rtw/buildInfo.mat


BIN=BIN
Simulink/Subsystem_ert_rtw/codeInfo.mat


BIN=BIN
Simulink/Subsystem_ert_rtw/codedescriptor.dmr


BIN=BIN
Simulink/Subsystem_ert_rtw/compileInfo.mat


+ 14 - 0
Simulink/Subsystem_ert_rtw/defines.txt

@@ -0,0 +1,14 @@
+MODEL=Subsystem
+NUMST=1
+NCSTATES=0
+HAVESTDIO
+MODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0
+CLASSIC_INTERFACE=0
+ALLOCATIONFCN=0
+TID01EQ=0
+TERMFCN=0
+ONESTEPFCN=1
+MAT_FILE=0
+MULTI_INSTANCE_CODE=0
+INTEGER_CODE=0
+MT=0

+ 109 - 0
Simulink/Subsystem_ert_rtw/ert_main.c

@@ -0,0 +1,109 @@
+/*
+ * File: ert_main.c
+ *
+ * Code generated for Simulink model 'Subsystem'.
+ *
+ * Model version                  : 1.2
+ * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
+ * C/C++ source code generated on : Fri Oct 14 20:06:32 2022
+ *
+ * Target selection: ert.tlc
+ * Embedded hardware selection: ARM Compatible->ARM Cortex-M
+ * Code generation objectives:
+ *    1. Execution efficiency
+ *    2. RAM efficiency
+ * Validation result: Not run
+ */
+
+#include <stddef.h>
+#include <stdio.h>              /* This ert_main.c example uses printf/fflush */
+#include "Subsystem.h"                 /* Model's header file */
+#include "rtwtypes.h"
+
+/*
+ * Associating rt_OneStep with a real-time clock or interrupt service routine
+ * is what makes the generated code "real-time".  The function rt_OneStep is
+ * always associated with the base rate of the model.  Subrates are managed
+ * by the base rate from inside the generated code.  Enabling/disabling
+ * interrupts and floating point context switches are target specific.  This
+ * example code indicates where these should take place relative to executing
+ * the generated code step function.  Overrun behavior should be tailored to
+ * your application needs.  This example simply sets an error status in the
+ * real-time model and returns from rt_OneStep.
+ */
+void rt_OneStep(void);
+void rt_OneStep(void)
+{
+  static boolean_T OverrunFlag = false;
+
+  /* Disable interrupts here */
+
+  /* Check for overrun */
+  if (OverrunFlag) {
+    return;
+  }
+
+  OverrunFlag = true;
+
+  /* Save FPU context here (if necessary) */
+  /* Re-enable timer or interrupt here */
+  /* Set model inputs here */
+
+  /* Step the model */
+  Subsystem_step();
+
+  /* Get model outputs here */
+
+  /* Indicate task complete */
+  OverrunFlag = false;
+
+  /* Disable interrupts here */
+  /* Restore FPU context here (if necessary) */
+  /* Enable interrupts here */
+}
+
+/*
+ * The example "main" function illustrates what is required by your
+ * application code to initialize, execute, and terminate the generated code.
+ * Attaching rt_OneStep to a real-time clock is target specific.  This example
+ * illustrates how you do this relative to initializing the model.
+ */
+int_T main(int_T argc, const char *argv[])
+{
+  /* Unused arguments */
+  (void)(argc);
+  (void)(argv);
+
+  /* Initialize model */
+  Subsystem_initialize();
+
+  /* Attach rt_OneStep to a timer or interrupt service routine with
+   * period 6.25E-5 seconds (the model's base sample time) here.  The
+   * call syntax for rt_OneStep is
+   *
+   *  rt_OneStep();
+   */
+  printf("Warning: The simulation will run forever. "
+         "Generated ERT main won't simulate model step behavior. "
+         "To change this behavior select the 'MAT-file logging' option.\n");
+  fflush((NULL));
+  while (1) {
+    /*  Perform other application tasks here */
+  }
+
+  /* The option 'Remove error status field in real-time model data structure'
+   * is selected, therefore the following code does not need to execute.
+   */
+#if 0
+
+  /* Disable rt_OneStep() here */
+#endif
+
+  return 0;
+}
+
+/*
+ * File trailer for generated code.
+ *
+ * [EOF]
+ */

+ 2 - 0
Simulink/Subsystem_ert_rtw/modelsources.txt

@@ -0,0 +1,2 @@
+  Subsystem.c
+

+ 4 - 0
Simulink/Subsystem_ert_rtw/rtw_proj.tmw

@@ -0,0 +1,4 @@
+Simulink Coder project for Subsystem using . MATLAB root = D:\Program Files\R2020b. SimStruct date: 29-7月-2020 14:26:22
+This file is generated by Simulink Coder for use by the make utility
+to determine when to rebuild objects when the name of the current Simulink Coder project changes.
+The rtwinfomat located at: ..\slprj\ert\Subsystem\tmwinternal\binfo.mat

+ 102 - 0
Simulink/Subsystem_ert_rtw/rtwtypes.h

@@ -0,0 +1,102 @@
+/*
+ * File: rtwtypes.h
+ *
+ * Code generated for Simulink model 'Subsystem'.
+ *
+ * Model version                  : 1.2
+ * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
+ * C/C++ source code generated on : Fri Oct 14 20:06:32 2022
+ *
+ * Target selection: ert.tlc
+ * Embedded hardware selection: ARM Compatible->ARM Cortex-M
+ * Code generation objectives:
+ *    1. Execution efficiency
+ *    2. RAM efficiency
+ * Validation result: Not run
+ */
+
+#ifndef RTWTYPES_H
+#define RTWTYPES_H
+
+/* Logical type definitions */
+#if (!defined(__cplusplus))
+#ifndef false
+#define false                          (0U)
+#endif
+
+#ifndef true
+#define true                           (1U)
+#endif
+#endif
+
+/*=======================================================================*
+ * Target hardware information
+ *   Device type: ARM Compatible->ARM Cortex-M
+ *   Number of bits:     char:   8    short:   16    int:  32
+ *                       long:  32    long long:  64
+ *                       native word size:  32
+ *   Byte ordering: LittleEndian
+ *   Signed integer division rounds to: Zero
+ *   Shift right on a signed integer as arithmetic shift: on
+ *=======================================================================*/
+
+/*=======================================================================*
+ * Fixed width word size data types:                                     *
+ *   int8_T, int16_T, int32_T     - signed 8, 16, or 32 bit integers     *
+ *   uint8_T, uint16_T, uint32_T  - unsigned 8, 16, or 32 bit integers   *
+ *   real32_T, real64_T           - 32 and 64 bit floating point numbers *
+ *=======================================================================*/
+typedef signed char int8_T;
+typedef unsigned char uint8_T;
+typedef short int16_T;
+typedef unsigned short uint16_T;
+typedef int int32_T;
+typedef unsigned int uint32_T;
+typedef long long int64_T;
+typedef unsigned long long uint64_T;
+typedef float real32_T;
+typedef double real64_T;
+
+/*===========================================================================*
+ * Generic type definitions: boolean_T, char_T, byte_T, int_T, uint_T,       *
+ *                           real_T, time_T, ulong_T, ulonglong_T.           *
+ *===========================================================================*/
+typedef double real_T;
+typedef double time_T;
+typedef unsigned char boolean_T;
+typedef int int_T;
+typedef unsigned int uint_T;
+typedef unsigned long ulong_T;
+typedef unsigned long long ulonglong_T;
+typedef char char_T;
+typedef unsigned char uchar_T;
+typedef char_T byte_T;
+
+/*=======================================================================*
+ * Min and Max:                                                          *
+ *   int8_T, int16_T, int32_T     - signed 8, 16, or 32 bit integers     *
+ *   uint8_T, uint16_T, uint32_T  - unsigned 8, 16, or 32 bit integers   *
+ *=======================================================================*/
+#define MAX_int8_T                     ((int8_T)(127))
+#define MIN_int8_T                     ((int8_T)(-128))
+#define MAX_uint8_T                    ((uint8_T)(255U))
+#define MAX_int16_T                    ((int16_T)(32767))
+#define MIN_int16_T                    ((int16_T)(-32768))
+#define MAX_uint16_T                   ((uint16_T)(65535U))
+#define MAX_int32_T                    ((int32_T)(2147483647))
+#define MIN_int32_T                    ((int32_T)(-2147483647-1))
+#define MAX_uint32_T                   ((uint32_T)(0xFFFFFFFFU))
+#define MAX_int64_T                    ((int64_T)(9223372036854775807LL))
+#define MIN_int64_T                    ((int64_T)(-9223372036854775807LL-1LL))
+#define MAX_uint64_T                   ((uint64_T)(0xFFFFFFFFFFFFFFFFULL))
+
+/* Block D-Work pointer type */
+typedef void * pointer_T;
+
+#endif                                 /* RTWTYPES_H */
+
+/*
+ * File trailer for generated code.
+ *
+ * [EOF]
+ */

BIN=BIN
Simulink/Subsystem_ert_rtw/rtwtypeschksum.mat


+ 2 - 0
Simulink/Subsystem_ert_rtw/setup_msvc.bat

@@ -0,0 +1,2 @@
+set "VSCMD_START_DIR=%CD%"
+"d:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\VCVARSALL.BAT " amd64

+ 3072 - 0
Simulink/angle2.csv

@@ -0,0 +1,3072 @@
+2334 
+2329 
+2290 
+2284 
+2307 
+2332 
+2343 
+2370 
+2418 
+2465 
+2478 
+2491 
+2527 
+2542 
+2549 
+2512 
+2504 
+2504 
+2475 
+2454 
+2428 
+2401 
+2365 
+2343 
+2345 
+2350 
+2326 
+2312 
+2330 
+2327 
+2326 
+2314 
+2306 
+2312 
+2322 
+2322 
+2335 
+2331 
+2338 
+2373 
+2407 
+2460 
+2502 
+2543 
+2592 
+2635 
+2688 
+2721 
+2736 
+2744 
+2726 
+2718 
+2706 
+2709 
+2701 
+2678 
+2658 
+2658 
+2662 
+2664 
+2650 
+2620 
+2596 
+2574 
+2545 
+2515 
+2484 
+2449 
+2408 
+2370 
+2349 
+2329 
+2302 
+2294 
+2317 
+2333 
+2349 
+2368 
+2402 
+2420 
+2442 
+2455 
+2466 
+2464 
+2444 
+2407 
+2403 
+2388 
+2346 
+2305 
+2295 
+2296 
+2284 
+2277 
+2292 
+2300 
+2307 
+2321 
+2356 
+2371 
+2375 
+2380 
+2387 
+2405 
+2398 
+2393 
+2425 
+2420 
+2436 
+2478 
+2533 
+2578 
+2625 
+2668 
+2733 
+2791 
+2810 
+2848 
+2880 
+2895 
+2873 
+2873 
+2901 
+2935 
+2911 
+2920 
+2947 
+2945 
+2955 
+2952 
+2957 
+2924 
+2891 
+2894 
+2885 
+2845 
+2764 
+2735 
+2748 
+2675 
+2626 
+2630 
+2632 
+2639 
+2645 
+2676 
+2718 
+2739 
+2749 
+2773 
+2811 
+2813 
+2768 
+2763 
+2752 
+2715 
+2661 
+2624 
+2623 
+2578 
+2554 
+2542 
+2524 
+2469 
+2406 
+2392 
+2384 
+2365 
+2330 
+2288 
+2290 
+2260 
+2243 
+2219 
+2197 
+2202 
+2200 
+2244 
+2832 
+2536 
+2464 
+2488 
+2524 
+2509 
+2558 
+2541 
+2509 
+2537 
+2477 
+2466 
+2459 
+2430 
+2430 
+2409 
+2431 
+2432 
+2404 
+2407 
+2405 
+2429 
+2394 
+2401 
+2366 
+2348 
+2333 
+2303 
+2304 
+2297 
+2279 
+2294 
+2321 
+2362 
+2374 
+2396 
+2428 
+2473 
+2487 
+2490 
+2491 
+2496 
+2469 
+2425 
+2418 
+2403 
+2376 
+2306 
+2306 
+2323 
+2304 
+2256 
+2257 
+2274 
+2247 
+2223 
+2229 
+2258 
+2227 
+2189 
+2209 
+2246 
+2233 
+2177 
+2213 
+2261 
+2287 
+2294 
+2345 
+2408 
+2450 
+2463 
+2494 
+2558 
+2576 
+2538 
+2537 
+2577 
+2550 
+2512 
+2521 
+2538 
+2521 
+2478 
+2488 
+2501 
+2499 
+2414 
+2386 
+2391 
+2359 
+2288 
+2250 
+2218 
+2186 
+2098 
+2065 
+2072 
+2040 
+2007 
+2033 
+2077 
+2081 
+2069 
+2097 
+2156 
+2177 
+2145 
+2169 
+2188 
+2163 
+2105 
+2104 
+2105 
+2084 
+2011 
+2018 
+2034 
+2039 
+1994 
+2007 
+2032 
+2034 
+2033 
+2054 
+2078 
+2071 
+2028 
+2053 
+2085 
+2053 
+2036 
+2052 
+2107 
+2123 
+2158 
+2205 
+2275 
+2308 
+2339 
+2389 
+2457 
+2479 
+2462 
+2457 
+2477 
+2480 
+2468 
+2471 
+2496 
+2476 
+2461 
+2477 
+2483 
+2453 
+2419 
+2403 
+2405 
+2365 
+2318 
+2286 
+2246 
+2189 
+2135 
+2147 
+2123 
+2106 
+2108 
+2146 
+2180 
+2203 
+2206 
+2246 
+2283 
+2272 
+2263 
+2269 
+2239 
+2204 
+2150 
+2133 
+2097 
+2038 
+1972 
+1954 
+1946 
+1926 
+1869 
+1844 
+1827 
+1800 
+1775 
+1740 
+1763 
+1693 
+1691 
+1694 
+1687 
+1573 
+1605 
+1524 
+1135 
+1832 
+1871 
+1921 
+1977 
+2015 
+2026 
+2068 
+2109 
+2079 
+2041 
+2061 
+2087 
+2065 
+2021 
+2011 
+2030 
+2036 
+2035 
+2046 
+2064 
+2050 
+2045 
+2062 
+2094 
+2071 
+2016 
+2015 
+2028 
+2018 
+1975 
+1989 
+1997 
+2003 
+2020 
+2067 
+2110 
+2130 
+2147 
+2181 
+2232 
+2249 
+2251 
+2250 
+2241 
+2210 
+2169 
+2160 
+2183 
+2156 
+2117 
+2114 
+2133 
+2109 
+2077 
+2080 
+2106 
+2089 
+2066 
+2072 
+2076 
+2060 
+2026 
+2037 
+2072 
+2068 
+2030 
+2050 
+2086 
+2116 
+2130 
+2185 
+2252 
+2293 
+2309 
+2357 
+2412 
+2456 
+2434 
+2394 
+2425 
+2438 
+2416 
+2421 
+2453 
+2444 
+2423 
+2436 
+2450 
+2452 
+2373 
+2355 
+2359 
+2310 
+2242 
+2203 
+2184 
+2115 
+2055 
+2037 
+2005 
+1974 
+1953 
+1973 
+2005 
+2008 
+2020 
+2041 
+2096 
+2086 
+2093 
+2089 
+2112 
+2078 
+2044 
+2051 
+2062 
+2003 
+1977 
+1959 
+1960 
+1947 
+1920 
+1922 
+1939 
+1919 
+1939 
+1962 
+1971 
+1959 
+1933 
+1960 
+1990 
+1962 
+1941 
+1956 
+1994 
+2034 
+2069 
+2109 
+2173 
+2218 
+2256 
+2307 
+2358 
+2374 
+2355 
+2353 
+2361 
+2367 
+2376 
+2379 
+2377 
+2345 
+2340 
+2354 
+2355 
+2322 
+2306 
+2303 
+2287 
+2272 
+2249 
+2215 
+2203 
+2153 
+2149 
+2132 
+2124 
+2106 
+2119 
+2139 
+2171 
+2183 
+2217 
+2250 
+2271 
+2291 
+2310 
+2323 
+2312 
+2255 
+2253 
+2208 
+2200 
+2145 
+2106 
+2074 
+2044 
+2032 
+2008 
+1976 
+1940 
+1936 
+1931 
+1923 
+1903 
+1895 
+1880 
+1876 
+1889 
+1879 
+1848 
+1851 
+1860 
+1905 
+1943 
+1971 
+2009 
+2065 
+2100 
+2117 
+2170 
+2191 
+2183 
+2177 
+2180 
+2198 
+2196 
+2183 
+2159 
+2164 
+2176 
+2161 
+2189 
+2198 
+2204 
+2188 
+2205 
+2233 
+2234 
+2207 
+2182 
+2185 
+2175 
+2138 
+2137 
+2119 
+2134 
+2119 
+2144 
+2194 
+2229 
+2242 
+2265 
+2319 
+2354 
+2358 
+2375 
+2393 
+2363 
+2336 
+2326 
+2338 
+2315 
+2275 
+2250 
+2282 
+2271 
+2230 
+2229 
+2239 
+2245 
+2197 
+2208 
+2207 
+2184 
+2126 
+2124 
+2150 
+2132 
+2078 
+2087 
+2131 
+2154 
+2176 
+2222 
+2286 
+2317 
+2351 
+2393 
+2441 
+2472 
+2425 
+2392 
+2431 
+2426 
+2402 
+2386 
+2390 
+2379 
+2351 
+2343 
+2346 
+2306 
+2252 
+2197 
+2201 
+2143 
+2065 
+2005 
+1971 
+1925 
+1887 
+1845 
+1806 
+1804 
+1794 
+1818 
+1845 
+1856 
+1870 
+1886 
+1905 
+1933 
+1902 
+1886 
+1859 
+1843 
+1791 
+1766 
+1708 
+1695 
+1667 
+1641 
+1635 
+1654 
+1635 
+1635 
+1657 
+1687 
+1689 
+1670 
+1670 
+1687 
+1708 
+1686 
+1681 
+1717 
+1736 
+1758 
+1810 
+1865 
+1915 
+1947 
+1993 
+2056 
+2076 
+2095 
+2119 
+2131 
+2113 
+2088 
+2113 
+2112 
+2115 
+2079 
+2089 
+2117 
+2124 
+2081 
+2081 
+2079 
+2067 
+2022 
+1999 
+2001 
+1955 
+1911 
+1908 
+1903 
+1868 
+1847 
+1845 
+1894 
+1894 
+1909 
+1936 
+1980 
+2000 
+1989 
+2015 
+2042 
+2032 
+1987 
+1970 
+1966 
+1928 
+1878 
+1854 
+1839 
+1817 
+1788 
+1771 
+1777 
+1720 
+1681 
+1684 
+1684 
+1669 
+1649 
+1620 
+1604 
+1607 
+1597 
+1581 
+1559 
+1552 
+1598 
+1620 
+1665 
+1698 
+1740 
+1786 
+1826 
+1873 
+1893 
+1910 
+1918 
+1909 
+1919 
+1933 
+1936 
+1929 
+1920 
+1927 
+1942 
+1964 
+1952 
+1962 
+1958 
+1984 
+1991 
+1967 
+1954 
+1945 
+1926 
+1906 
+1881 
+1862 
+1843 
+1846 
+1841 
+1873 
+1903 
+1932 
+1964 
+1994 
+2031 
+2054 
+2076 
+2090 
+2086 
+2074 
+2047 
+2043 
+2027 
+2000 
+1971 
+1947 
+1943 
+1937 
+1920 
+1906 
+1879 
+1876 
+1880 
+1860 
+1858 
+1817 
+1801 
+1798 
+1791 
+1803 
+1778 
+1782 
+1805 
+1848 
+1879 
+1924 
+1961 
+2017 
+2059 
+2096 
+2125 
+2149 
+2144 
+2117 
+2103 
+2102 
+2095 
+2079 
+2047 
+2039 
+2040 
+2033 
+2027 
+2020 
+1982 
+1919 
+1915 
+1892 
+1843 
+1801 
+1764 
+1742 
+1711 
+1682 
+1656 
+1649 
+1656 
+1666 
+1688 
+1712 
+1737 
+1759 
+1776 
+1804 
+1837 
+1819 
+1802 
+1787 
+1760 
+1728 
+1711 
+1657 
+1663 
+1629 
+1627 
+1619 
+1626 
+1625 
+1619 
+1643 
+1691 
+1693 
+1703 
+1724 
+1738 
+1740 
+1747 
+1761 
+1789 
+1784 
+1803 
+1846 
+1900 
+1946 
+1986 
+2047 
+2108 
+2154 
+2185 
+2226 
+2267 
+2280 
+2273 
+2265 
+2282 
+2307 
+2311 
+2303 
+2323 
+2331 
+2344 
+2353 
+2355 
+2340 
+2338 
+2328 
+2324 
+2326 
+2283 
+2248 
+2240 
+2207 
+2200 
+2170 
+2165 
+2143 
+2142 
+2175 
+2206 
+2246 
+2272 
+2294 
+2309 
+2362 
+2376 
+2390 
+2390 
+2363 
+2349 
+2348 
+2326 
+2302 
+2282 
+2259 
+2238 
+2243 
+2235 
+2208 
+2174 
+2145 
+2145 
+2145 
+2125 
+2095 
+2080 
+2082 
+2062 
+2055 
+2033 
+2028 
+2017 
+2036 
+2077 
+2126 
+2159 
+2183 
+2236 
+2296 
+2334 
+2339 
+2364 
+2386 
+2404 
+2401 
+2400 
+2429 
+2420 
+2383 
+2374 
+2405 
+2424 
+2417 
+2418 
+2425 
+2440 
+2407 
+2407 
+2415 
+2398 
+2367 
+2345 
+2334 
+2329 
+2290 
+2284 
+2307 
+2332 
+2343 
+2370 
+2418 
+2465 
+2478 
+2491 
+2527 
+2542 
+2549 
+2512 
+2504 
+2504 
+2475 
+2454 
+2428 
+2401 
+2365 
+2343 
+2345 
+2350 
+2326 
+2312 
+2330 
+2327 
+2326 
+2314 
+2306 
+2312 
+2322 
+2322 
+2335 
+2331 
+2338 
+2373 
+2407 
+2460 
+2502 
+2543 
+2592 
+2635 
+2688 
+2721 
+2736 
+2744 
+2726 
+2718 
+2706 
+2709 
+2701 
+2678 
+2658 
+2658 
+2662 
+2664 
+2650 
+2620 
+2596 
+2574 
+2545 
+2515 
+2484 
+2449 
+2408 
+2370 
+2349 
+2329 
+2302 
+2294 
+2317 
+2333 
+2349 
+2368 
+2402 
+2420 
+2442 
+2455 
+2466 
+2464 
+2444 
+2407 
+2403 
+2388 
+2346 
+2305 
+2295 
+2296 
+2284 
+2277 
+2292 
+2300 
+2307 
+2321 
+2356 
+2371 
+2375 
+2380 
+2387 
+2405 
+2398 
+2393 
+2425 
+2420 
+2436 
+2478 
+2533 
+2578 
+2625 
+2668 
+2733 
+2791 
+2810 
+2848 
+2880 
+2895 
+2873 
+2873 
+2901 
+2935 
+2911 
+2920 
+2947 
+2945 
+2955 
+2952 
+2957 
+2924 
+2891 
+2894 
+2885 
+2845 
+2764 
+2735 
+2748 
+2675 
+2626 
+2630 
+2632 
+2639 
+2645 
+2676 
+2718 
+2739 
+2749 
+2773 
+2811 
+2813 
+2768 
+2763 
+2752 
+2715 
+2661 
+2624 
+2623 
+2578 
+2554 
+2542 
+2524 
+2469 
+2406 
+2392 
+2384 
+2365 
+2330 
+2288 
+2290 
+2260 
+2243 
+2219 
+2197 
+2202 
+2200 
+2244 
+2832 
+2536 
+2464 
+2488 
+2524 
+2509 
+2558 
+2541 
+2509 
+2537 
+2477 
+2466 
+2459 
+2430 
+2430 
+2409 
+2431 
+2432 
+2404 
+2407 
+2405 
+2429 
+2394 
+2401 
+2366 
+2348 
+2333 
+2303 
+2304 
+2297 
+2279 
+2294 
+2321 
+2362 
+2374 
+2396 
+2428 
+2473 
+2487 
+2490 
+2491 
+2496 
+2469 
+2425 
+2418 
+2403 
+2376 
+2306 
+2306 
+2323 
+2304 
+2256 
+2257 
+2274 
+2247 
+2223 
+2229 
+2258 
+2227 
+2189 
+2209 
+2246 
+2233 
+2177 
+2213 
+2261 
+2287 
+2294 
+2345 
+2408 
+2450 
+2463 
+2494 
+2558 
+2576 
+2538 
+2537 
+2577 
+2550 
+2512 
+2521 
+2538 
+2521 
+2478 
+2488 
+2501 
+2499 
+2414 
+2386 
+2391 
+2359 
+2288 
+2250 
+2218 
+2186 
+2098 
+2065 
+2072 
+2040 
+2007 
+2033 
+2077 
+2081 
+2069 
+2097 
+2156 
+2177 
+2145 
+2169 
+2188 
+2163 
+2105 
+2104 
+2105 
+2084 
+2011 
+2018 
+2034 
+2039 
+1994 
+2007 
+2032 
+2034 
+2033 
+2054 
+2078 
+2071 
+2028 
+2053 
+2085 
+2053 
+2036 
+2052 
+2107 
+2123 
+2158 
+2205 
+2275 
+2308 
+2339 
+2389 
+2457 
+2479 
+2462 
+2457 
+2477 
+2480 
+2468 
+2471 
+2496 
+2476 
+2461 
+2477 
+2483 
+2453 
+2419 
+2403 
+2405 
+2365 
+2318 
+2286 
+2246 
+2189 
+2135 
+2147 
+2123 
+2106 
+2108 
+2146 
+2180 
+2203 
+2206 
+2246 
+2283 
+2272 
+2263 
+2269 
+2239 
+2204 
+2150 
+2133 
+2097 
+2038 
+1972 
+1954 
+1946 
+1926 
+1869 
+1844 
+1827 
+1800 
+1775 
+1740 
+1763 
+1693 
+1691 
+1694 
+1687 
+1573 
+1605 
+1524 
+1135 
+1832 
+1871 
+1921 
+1977 
+2015 
+2026 
+2068 
+2109 
+2079 
+2041 
+2061 
+2087 
+2065 
+2021 
+2011 
+2030 
+2036 
+2035 
+2046 
+2064 
+2050 
+2045 
+2062 
+2094 
+2071 
+2016 
+2015 
+2028 
+2018 
+1975 
+1989 
+1997 
+2003 
+2020 
+2067 
+2110 
+2130 
+2147 
+2181 
+2232 
+2249 
+2251 
+2250 
+2241 
+2210 
+2169 
+2160 
+2183 
+2156 
+2117 
+2114 
+2133 
+2109 
+2077 
+2080 
+2106 
+2089 
+2066 
+2072 
+2076 
+2060 
+2026 
+2037 
+2072 
+2068 
+2030 
+2050 
+2086 
+2116 
+2130 
+2185 
+2252 
+2293 
+2309 
+2357 
+2412 
+2456 
+2434 
+2394 
+2425 
+2438 
+2416 
+2421 
+2453 
+2444 
+2423 
+2436 
+2450 
+2452 
+2373 
+2355 
+2359 
+2310 
+2242 
+2203 
+2184 
+2115 
+2055 
+2037 
+2005 
+1974 
+1953 
+1973 
+2005 
+2008 
+2020 
+2041 
+2096 
+2086 
+2093 
+2089 
+2112 
+2078 
+2044 
+2051 
+2062 
+2003 
+1977 
+1959 
+1960 
+1947 
+1920 
+1922 
+1939 
+1919 
+1939 
+1962 
+1971 
+1959 
+1933 
+1960 
+1990 
+1962 
+1941 
+1956 
+1994 
+2034 
+2069 
+2109 
+2173 
+2218 
+2256 
+2307 
+2358 
+2374 
+2355 
+2353 
+2361 
+2367 
+2376 
+2379 
+2377 
+2345 
+2340 
+2354 
+2355 
+2322 
+2306 
+2303 
+2287 
+2272 
+2249 
+2215 
+2203 
+2153 
+2149 
+2132 
+2124 
+2106 
+2119 
+2139 
+2171 
+2183 
+2217 
+2250 
+2271 
+2291 
+2310 
+2323 
+2312 
+2255 
+2253 
+2208 
+2200 
+2145 
+2106 
+2074 
+2044 
+2032 
+2008 
+1976 
+1940 
+1936 
+1931 
+1923 
+1903 
+1895 
+1880 
+1876 
+1889 
+1879 
+1848 
+1851 
+1860 
+1905 
+1943 
+1971 
+2009 
+2065 
+2100 
+2117 
+2170 
+2191 
+2183 
+2177 
+2180 
+2198 
+2196 
+2183 
+2159 
+2164 
+2176 
+2161 
+2189 
+2198 
+2204 
+2188 
+2205 
+2233 
+2234 
+2207 
+2182 
+2185 
+2175 
+2138 
+2137 
+2119 
+2134 
+2119 
+2144 
+2194 
+2229 
+2242 
+2265 
+2319 
+2354 
+2358 
+2375 
+2393 
+2363 
+2336 
+2326 
+2338 
+2315 
+2275 
+2250 
+2282 
+2271 
+2230 
+2229 
+2239 
+2245 
+2197 
+2208 
+2207 
+2184 
+2126 
+2124 
+2150 
+2132 
+2078 
+2087 
+2131 
+2154 
+2176 
+2222 
+2286 
+2317 
+2351 
+2393 
+2441 
+2472 
+2425 
+2392 
+2431 
+2426 
+2402 
+2386 
+2390 
+2379 
+2351 
+2343 
+2346 
+2306 
+2252 
+2197 
+2201 
+2143 
+2065 
+2005 
+1971 
+1925 
+1887 
+1845 
+1806 
+1804 
+1794 
+1818 
+1845 
+1856 
+1870 
+1886 
+1905 
+1933 
+1902 
+1886 
+1859 
+1843 
+1791 
+1766 
+1708 
+1695 
+1667 
+1641 
+1635 
+1654 
+1635 
+1635 
+1657 
+1687 
+1689 
+1670 
+1670 
+1687 
+1708 
+1686 
+1681 
+1717 
+1736 
+1758 
+1810 
+1865 
+1915 
+1947 
+1993 
+2056 
+2076 
+2095 
+2119 
+2131 
+2113 
+2088 
+2113 
+2112 
+2115 
+2079 
+2089 
+2117 
+2124 
+2081 
+2081 
+2079 
+2067 
+2022 
+1999 
+2001 
+1955 
+1911 
+1908 
+1903 
+1868 
+1847 
+1845 
+1894 
+1894 
+1909 
+1936 
+1980 
+2000 
+1989 
+2015 
+2042 
+2032 
+1987 
+1970 
+1966 
+1928 
+1878 
+1854 
+1839 
+1817 
+1788 
+1771 
+1777 
+1720 
+1681 
+1684 
+1684 
+1669 
+1649 
+1620 
+1604 
+1607 
+1597 
+1581 
+1559 
+1552 
+1598 
+1620 
+1665 
+1698 
+1740 
+1786 
+1826 
+1873 
+1893 
+1910 
+1918 
+1909 
+1919 
+1933 
+1936 
+1929 
+1920 
+1927 
+1942 
+1964 
+1952 
+1962 
+1958 
+1984 
+1991 
+1967 
+1954 
+1945 
+1926 
+1906 
+1881 
+1862 
+1843 
+1846 
+1841 
+1873 
+1903 
+1932 
+1964 
+1994 
+2031 
+2054 
+2076 
+2090 
+2086 
+2074 
+2047 
+2043 
+2027 
+2000 
+1971 
+1947 
+1943 
+1937 
+1920 
+1906 
+1879 
+1876 
+1880 
+1860 
+1858 
+1817 
+1801 
+1798 
+1791 
+1803 
+1778 
+1782 
+1805 
+1848 
+1879 
+1924 
+1961 
+2017 
+2059 
+2096 
+2125 
+2149 
+2144 
+2117 
+2103 
+2102 
+2095 
+2079 
+2047 
+2039 
+2040 
+2033 
+2027 
+2020 
+1982 
+1919 
+1915 
+1892 
+1843 
+1801 
+1764 
+1742 
+1711 
+1682 
+1656 
+1649 
+1656 
+1666 
+1688 
+1712 
+1737 
+1759 
+1776 
+1804 
+1837 
+1819 
+1802 
+1787 
+1760 
+1728 
+1711 
+1657 
+1663 
+1629 
+1627 
+1619 
+1626 
+1625 
+1619 
+1643 
+1691 
+1693 
+1703 
+1724 
+1738 
+1740 
+1747 
+1761 
+1789 
+1784 
+1803 
+1846 
+1900 
+1946 
+1986 
+2047 
+2108 
+2154 
+2185 
+2226 
+2267 
+2280 
+2273 
+2265 
+2282 
+2307 
+2311 
+2303 
+2323 
+2331 
+2344 
+2353 
+2355 
+2340 
+2338 
+2328 
+2324 
+2326 
+2283 
+2248 
+2240 
+2207 
+2200 
+2170 
+2165 
+2143 
+2142 
+2175 
+2206 
+2246 
+2272 
+2294 
+2309 
+2362 
+2376 
+2390 
+2390 
+2363 
+2349 
+2348 
+2326 
+2302 
+2282 
+2259 
+2238 
+2243 
+2235 
+2208 
+2174 
+2145 
+2145 
+2145 
+2125 
+2095 
+2080 
+2082 
+2062 
+2055 
+2033 
+2028 
+2017 
+2036 
+2077 
+2126 
+2159 
+2183 
+2236 
+2296 
+2334 
+2339 
+2364 
+2386 
+2404 
+2401 
+2400 
+2429 
+2420 
+2383 
+2374 
+2405 
+2424 
+2417 
+2418 
+2425 
+2440 
+2407 
+2407 
+2415 
+2398 
+2367 
+2345 
+2334 
+2329 
+2290 
+2284 
+2307 
+2332 
+2343 
+2370 
+2418 
+2465 
+2478 
+2491 
+2527 
+2542 
+2549 
+2512 
+2504 
+2504 
+2475 
+2454 
+2428 
+2401 
+2365 
+2343 
+2345 
+2350 
+2326 
+2312 
+2330 
+2327 
+2326 
+2314 
+2306 
+2312 
+2322 
+2322 
+2335 
+2331 
+2338 
+2373 
+2407 
+2460 
+2502 
+2543 
+2592 
+2635 
+2688 
+2721 
+2736 
+2744 
+2726 
+2718 
+2706 
+2709 
+2701 
+2678 
+2658 
+2658 
+2662 
+2664 
+2650 
+2620 
+2596 
+2574 
+2545 
+2515 
+2484 
+2449 
+2408 
+2370 
+2349 
+2329 
+2302 
+2294 
+2317 
+2333 
+2349 
+2368 
+2402 
+2420 
+2442 
+2455 
+2466 
+2464 
+2444 
+2407 
+2403 
+2388 
+2346 
+2305 
+2295 
+2296 
+2284 
+2277 
+2292 
+2300 
+2307 
+2321 
+2356 
+2371 
+2375 
+2380 
+2387 
+2405 
+2398 
+2393 
+2425 
+2420 
+2436 
+2478 
+2533 
+2578 
+2625 
+2668 
+2733 
+2791 
+2810 
+2848 
+2880 
+2895 
+2873 
+2873 
+2901 
+2935 
+2911 
+2920 
+2947 
+2945 
+2955 
+2952 
+2957 
+2924 
+2891 
+2894 
+2885 
+2845 
+2764 
+2735 
+2748 
+2675 
+2626 
+2630 
+2632 
+2639 
+2645 
+2676 
+2718 
+2739 
+2749 
+2773 
+2811 
+2813 
+2768 
+2763 
+2752 
+2715 
+2661 
+2624 
+2623 
+2578 
+2554 
+2542 
+2524 
+2469 
+2406 
+2392 
+2384 
+2365 
+2330 
+2288 
+2290 
+2260 
+2243 
+2219 
+2197 
+2202 
+2200 
+2244 
+2832 
+2536 
+2464 
+2488 
+2524 
+2509 
+2558 
+2541 
+2509 
+2537 
+2477 
+2466 
+2459 
+2430 
+2430 
+2409 
+2431 
+2432 
+2404 
+2407 
+2405 
+2429 
+2394 
+2401 
+2366 
+2348 
+2333 
+2303 
+2304 
+2297 
+2279 
+2294 
+2321 
+2362 
+2374 
+2396 
+2428 
+2473 
+2487 
+2490 
+2491 
+2496 
+2469 
+2425 
+2418 
+2403 
+2376 
+2306 
+2306 
+2323 
+2304 
+2256 
+2257 
+2274 
+2247 
+2223 
+2229 
+2258 
+2227 
+2189 
+2209 
+2246 
+2233 
+2177 
+2213 
+2261 
+2287 
+2294 
+2345 
+2408 
+2450 
+2463 
+2494 
+2558 
+2576 
+2538 
+2537 
+2577 
+2550 
+2512 
+2521 
+2538 
+2521 
+2478 
+2488 
+2501 
+2499 
+2414 
+2386 
+2391 
+2359 
+2288 
+2250 
+2218 
+2186 
+2098 
+2065 
+2072 
+2040 
+2007 
+2033 
+2077 
+2081 
+2069 
+2097 
+2156 
+2177 
+2145 
+2169 
+2188 
+2163 
+2105 
+2104 
+2105 
+2084 
+2011 
+2018 
+2034 
+2039 
+1994 
+2007 
+2032 
+2034 
+2033 
+2054 
+2078 
+2071 
+2028 
+2053 
+2085 
+2053 
+2036 
+2052 
+2107 
+2123 
+2158 
+2205 
+2275 
+2308 
+2339 
+2389 
+2457 
+2479 
+2462 
+2457 
+2477 
+2480 
+2468 
+2471 
+2496 
+2476 
+2461 
+2477 
+2483 
+2453 
+2419 
+2403 
+2405 
+2365 
+2318 
+2286 
+2246 
+2189 
+2135 
+2147 
+2123 
+2106 
+2108 
+2146 
+2180 
+2203 
+2206 
+2246 
+2283 
+2272 
+2263 
+2269 
+2239 
+2204 
+2150 
+2133 
+2097 
+2038 
+1972 
+1954 
+1946 
+1926 
+1869 
+1844 
+1827 
+1800 
+1775 
+1740 
+1763 
+1693 
+1691 
+1694 
+1687 
+1573 
+1605 
+1524 
+1135 
+1832 
+1871 
+1921 
+1977 
+2015 
+2026 
+2068 
+2109 
+2079 
+2041 
+2061 
+2087 
+2065 
+2021 
+2011 
+2030 
+2036 
+2035 
+2046 
+2064 
+2050 
+2045 
+2062 
+2094 
+2071 
+2016 
+2015 
+2028 
+2018 
+1975 
+1989 
+1997 
+2003 
+2020 
+2067 
+2110 
+2130 
+2147 
+2181 
+2232 
+2249 
+2251 
+2250 
+2241 
+2210 
+2169 
+2160 
+2183 
+2156 
+2117 
+2114 
+2133 
+2109 
+2077 
+2080 
+2106 
+2089 
+2066 
+2072 
+2076 
+2060 
+2026 
+2037 
+2072 
+2068 
+2030 
+2050 
+2086 
+2116 
+2130 
+2185 
+2252 
+2293 
+2309 
+2357 
+2412 
+2456 
+2434 
+2394 
+2425 
+2438 
+2416 
+2421 
+2453 
+2444 
+2423 
+2436 
+2450 
+2452 
+2373 
+2355 
+2359 
+2310 
+2242 
+2203 
+2184 
+2115 
+2055 
+2037 
+2005 
+1974 
+1953 
+1973 
+2005 
+2008 
+2020 
+2041 
+2096 
+2086 
+2093 
+2089 
+2112 
+2078 
+2044 
+2051 
+2062 
+2003 
+1977 
+1959 
+1960 
+1947 
+1920 
+1922 
+1939 
+1919 
+1939 
+1962 
+1971 
+1959 
+1933 
+1960 
+1990 
+1962 
+1941 
+1956 
+1994 
+2034 
+2069 
+2109 
+2173 
+2218 
+2256 
+2307 
+2358 
+2374 
+2355 
+2353 
+2361 
+2367 
+2376 
+2379 
+2377 
+2345 
+2340 
+2354 
+2355 
+2322 
+2306 
+2303 
+2287 
+2272 
+2249 
+2215 
+2203 
+2153 
+2149 
+2132 
+2124 
+2106 
+2119 
+2139 
+2171 
+2183 
+2217 
+2250 
+2271 
+2291 
+2310 
+2323 
+2312 
+2255 
+2253 
+2208 
+2200 
+2145 
+2106 
+2074 
+2044 
+2032 
+2008 
+1976 
+1940 
+1936 
+1931 
+1923 
+1903 
+1895 
+1880 
+1876 
+1889 
+1879 
+1848 
+1851 
+1860 
+1905 
+1943 
+1971 
+2009 
+2065 
+2100 
+2117 
+2170 
+2191 
+2183 
+2177 
+2180 
+2198 
+2196 
+2183 
+2159 
+2164 
+2176 
+2161 
+2189 
+2198 
+2204 
+2188 
+2205 
+2233 
+2234 
+2207 
+2182 
+2185 
+2175 
+2138 
+2137 
+2119 
+2134 
+2119 
+2144 
+2194 
+2229 
+2242 
+2265 
+2319 
+2354 
+2358 
+2375 
+2393 
+2363 
+2336 
+2326 
+2338 
+2315 
+2275 
+2250 
+2282 
+2271 
+2230 
+2229 
+2239 
+2245 
+2197 
+2208 
+2207 
+2184 
+2126 
+2124 
+2150 
+2132 
+2078 
+2087 
+2131 
+2154 
+2176 
+2222 
+2286 
+2317 
+2351 
+2393 
+2441 
+2472 
+2425 
+2392 
+2431 
+2426 
+2402 
+2386 
+2390 
+2379 
+2351 
+2343 
+2346 
+2306 
+2252 
+2197 
+2201 
+2143 
+2065 
+2005 
+1971 
+1925 
+1887 
+1845 
+1806 
+1804 
+1794 
+1818 
+1845 
+1856 
+1870 
+1886 
+1905 
+1933 
+1902 
+1886 
+1859 
+1843 
+1791 
+1766 
+1708 
+1695 
+1667 
+1641 
+1635 
+1654 
+1635 
+1635 
+1657 
+1687 
+1689 
+1670 
+1670 
+1687 
+1708 
+1686 
+1681 
+1717 
+1736 
+1758 
+1810 
+1865 
+1915 
+1947 
+1993 
+2056 
+2076 
+2095 
+2119 
+2131 
+2113 
+2088 
+2113 
+2112 
+2115 
+2079 
+2089 
+2117 
+2124 
+2081 
+2081 
+2079 
+2067 
+2022 
+1999 
+2001 
+1955 
+1911 
+1908 
+1903 
+1868 
+1847 
+1845 
+1894 
+1894 
+1909 
+1936 
+1980 
+2000 
+1989 
+2015 
+2042 
+2032 
+1987 
+1970 
+1966 
+1928 
+1878 
+1854 
+1839 
+1817 
+1788 
+1771 
+1777 
+1720 
+1681 
+1684 
+1684 
+1669 
+1649 
+1620 
+1604 
+1607 
+1597 
+1581 
+1559 
+1552 
+1598 
+1620 
+1665 
+1698 
+1740 
+1786 
+1826 
+1873 
+1893 
+1910 
+1918 
+1909 
+1919 
+1933 
+1936 
+1929 
+1920 
+1927 
+1942 
+1964 
+1952 
+1962 
+1958 
+1984 
+1991 
+1967 
+1954 
+1945 
+1926 
+1906 
+1881 
+1862 
+1843 
+1846 
+1841 
+1873 
+1903 
+1932 
+1964 
+1994 
+2031 
+2054 
+2076 
+2090 
+2086 
+2074 
+2047 
+2043 
+2027 
+2000 
+1971 
+1947 
+1943 
+1937 
+1920 
+1906 
+1879 
+1876 
+1880 
+1860 
+1858 
+1817 
+1801 
+1798 
+1791 
+1803 
+1778 
+1782 
+1805 
+1848 
+1879 
+1924 
+1961 
+2017 
+2059 
+2096 
+2125 
+2149 
+2144 
+2117 
+2103 
+2102 
+2095 
+2079 
+2047 
+2039 
+2040 
+2033 
+2027 
+2020 
+1982 
+1919 
+1915 
+1892 
+1843 
+1801 
+1764 
+1742 
+1711 
+1682 
+1656 
+1649 
+1656 
+1666 
+1688 
+1712 
+1737 
+1759 
+1776 
+1804 
+1837 
+1819 
+1802 
+1787 
+1760 
+1728 
+1711 
+1657 
+1663 
+1629 
+1627 
+1619 
+1626 
+1625 
+1619 
+1643 
+1691 
+1693 
+1703 
+1724 
+1738 
+1740 
+1747 
+1761 
+1789 
+1784 
+1803 
+1846 
+1900 
+1946 
+1986 
+2047 
+2108 
+2154 
+2185 
+2226 
+2267 
+2280 
+2273 
+2265 
+2282 
+2307 
+2311 
+2303 
+2323 
+2331 
+2344 
+2353 
+2355 
+2340 
+2338 
+2328 
+2324 
+2326 
+2283 
+2248 
+2240 
+2207 
+2200 
+2170 
+2165 
+2143 
+2142 
+2175 
+2206 
+2246 
+2272 
+2294 
+2309 
+2362 
+2376 
+2390 
+2390 
+2363 
+2349 
+2348 
+2326 
+2302 
+2282 
+2259 
+2238 
+2243 
+2235 
+2208 
+2174 
+2145 
+2145 
+2145 
+2125 
+2095 
+2080 
+2082 
+2062 
+2055 
+2033 
+2028 
+2017 
+2036 
+2077 
+2126 
+2159 
+2183 
+2236 
+2296 
+2334 
+2339 
+2364 
+2386 
+2404 
+2401 
+2400 
+2429 
+2420 
+2383 
+2374 
+2405 
+2424 
+2417 
+2418 
+2425 
+2440 
+2407 
+2407 
+2415 
+2398 
+2367 
+2345 

+ 1 - 0
Simulink/init_model.m

@@ -8,6 +8,7 @@ Ts                  = 1e-6;                         % [s] Model sampling time (2
 f_ctrl              = 20e3;                         % [Hz] Controller frequency = 1/Ts_ctrl (20 kHz)
 Ts_ctrl             = 1/f_ctrl;                     % [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;
 n_spdctl_count      = f_ctrl/f_speed_ctrl;         % [count] Delay for f_speed_ctrl of the FOC controller
 i_pwm_count         = 3000;
 n_hall_count_ps     = 1/Ts;    % counts of per second

+ 2 - 0
Simulink/myfilter.m

@@ -1,4 +1,6 @@
 Fir=Fir_angle;
+in=csvread('angle.csv');
+in=in';
 angle_off=filter(Fir.Numerator, 1, in);
 out=single(angle_off);
 t=0:3071;

+ 11 - 0
Simulink/myfilter2.m

@@ -0,0 +1,11 @@
+Fir=Fir_angle;
+in=csvread('angle2.csv');
+in=in';
+angle_off=filter(Fir.Numerator, 1, in);
+out=single(angle_off);
+t=0:3071;
+plot(t, in);
+hold;
+%plot(t-298, out);
+plot(t-477, out);
+out_off=out';