diff --git a/Inu/Src/main_matlab/init28335.c b/Inu/Src/main_matlab/init28335.c
index 756ee53..af74fd7 100644
--- a/Inu/Src/main_matlab/init28335.c
+++ b/Inu/Src/main_matlab/init28335.c
@@ -21,6 +21,9 @@ void init28335(void) {
 
     Init_Adc_Variables();
 
+    //svgen_pwm24_1.phase_sequence = SIMULINK_SEQUENCE;
+    //svgen_pwm24_2.phase_sequence = SIMULINK_SEQUENCE;
+
 } //void init28335(void)
 
 void edrk_init_variables_matlab(void)
diff --git a/Inu/Src/main_matlab/main_matlab.c b/Inu/Src/main_matlab/main_matlab.c
index eb2bc3f..6fe85ef 100644
--- a/Inu/Src/main_matlab/main_matlab.c
+++ b/Inu/Src/main_matlab/main_matlab.c
@@ -28,6 +28,7 @@ void mcu_simulate_step(void)
 {
 	int ff = 0;
 	static _iq Uzad1 = 0, Fzad = 0, Uzad2 = 0, Izad_out = 0, Uzad_from_master = 0;
+	int pwm_enable_calc_main;
 	_iq wd;
 
 	if (edrk.flag_second_PCH == 0) {
@@ -37,23 +38,18 @@ void mcu_simulate_step(void)
 		wd = uf_alg.winding_displacement_bs2;
 	}
 
-	//parse_parameters_from_all_control_station();
-
-	//ff = control_station.active_array_cmd[CONTROL_STATION_CMD_SET_ROTOR];
-	//control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_SET_ROTOR] = ff;
-	//control_station.array_cmd[CONTROL_STATION_VPU_CAN][CONTROL_STATION_CMD_SET_ROTOR] = ff;
-	//control_station.array_cmd[CONTROL_STATION_ZADATCHIK_CAN][CONTROL_STATION_CMD_SET_ROTOR] = ff;
-
-	//ff = control_station.active_array_cmd[CONTROL_STATION_CMD_SET_POWER];
-	//control_station.array_cmd[CONTROL_STATION_INGETEAM_PULT_RS485][CONTROL_STATION_CMD_SET_POWER] = ff;
+	detect_level_interrupt(edrk.flag_second_PCH);
+	if (xpwm_time.where_interrupt == PWM_LOW_LEVEL_INTERRUPT ||
+		xpwm_time.one_or_two_interrupts_run == PWM_ONE_INTERRUPT_RUN)
+	{
+		pwm_enable_calc_main = 1;
+	}
+	else
+	{
+		pwm_enable_calc_main = 0;
+	}
 
 
-	//if (control_station.active_array_cmd[CONTROL_STATION_CMD_ROTOR_POWER])
-	//{
-	//	control_station.array_cmd[CONTROL_STATION_ZADATCHIK_CAN][CONTROL_STATION_CMD_SET_ROTOR] = 0;
-	//	control_station.array_cmd[CONTROL_STATION_VPU_CAN][CONTROL_STATION_CMD_SET_ROTOR] = 0;
-	//}
-	//parse_analog_data_from_active_control_station_to_alg();
 
 	calc_norm_ADC_0(0);
 
@@ -77,6 +73,16 @@ void mcu_simulate_step(void)
 	analog.PowerFOC = edrk.P_to_master;
 	Fzad = vect_control.iqFstator;
 	Izad_out = edrk.Iq_to_slave;
+
+	if (xpwm_time.one_or_two_interrupts_run == PWM_ONE_INTERRUPT_RUN)
+		write_swgen_pwm_times(PWM_MODE_RELOAD_FORCE);
+	else
+	{
+		if (pwm_enable_calc_main)
+			write_swgen_pwm_times(PWM_MODE_RELOAD_LEVEL_HIGH);
+		else
+			write_swgen_pwm_times(PWM_MODE_RELOAD_LEVEL_LOW);
+	}
 }
 
 
diff --git a/Inu/Src/main_matlab/param.c b/Inu/Src/main_matlab/param.c
index 24392f4..ef4357a 100644
--- a/Inu/Src/main_matlab/param.c
+++ b/Inu/Src/main_matlab/param.c
@@ -50,4 +50,67 @@ void readInputParameters(const real_T *u) {
 
 
 void writeOutputParameters(real_T* xD) {
+	int nn = 0;
+
+	xD[nn++] = t1sim.ciA;
+	xD[nn++] = t2sim.ciA;
+	xD[nn++] = t1sim.ciB;
+	xD[nn++] = t2sim.ciB;
+
+	xD[nn++] = t3sim.ciA;
+	xD[nn++] = t4sim.ciA;
+	xD[nn++] = t3sim.ciB;
+	xD[nn++] = t4sim.ciB;
+
+	xD[nn++] = t5sim.ciA;
+	xD[nn++] = t6sim.ciA;
+	xD[nn++] = t5sim.ciB;
+	xD[nn++] = t6sim.ciB;
+	
+
+	xD[nn++] = t7sim.ciA;
+	xD[nn++] = t8sim.ciA;
+	xD[nn++] = t7sim.ciB;
+	xD[nn++] = t8sim.ciB;
+
+	xD[nn++] = t9sim.ciA;
+	xD[nn++] = t10sim.ciA;
+	xD[nn++] = t9sim.ciB;
+	xD[nn++] = t10sim.ciB;
+
+	xD[nn++] = t11sim.ciA;
+	xD[nn++] = t12sim.ciA;
+	xD[nn++] = t11sim.ciB;
+	xD[nn++] = t12sim.ciB;
+
+	// ������ ��� ���������
+	xD[nn++] = _IQtoF(0);
+	xD[nn++] = _IQtoF(0);
+
+	xD[nn++] = 0;
+	xD[nn++] = 0;
+	xD[nn++] = 0;
+
+	xD[nn++] = 0;
+	xD[nn++] = 0;
+
+	xD[nn++] = 0;
+	xD[nn++] = _IQtoF(0);//rs.wmZ;
+	xD[nn++] = _IQtoF(0) * NORMA_FROTOR * 60.0 / N_BAZ;//csp.wmLimZi;
+
+	xD[nn++] = 0;///P_NOM;
+	xD[nn++] = 0;///P_NOM;
+	xD[nn++] = 0;///P_NOM;
+
+	xD[nn++] = _IQtoF(vect_control.iqId2);//_IQtoF(vect_control.iqPzad);
+	xD[nn++] = _IQtoF(vect_control.iqIq2);// * NORMA_ACP;
+	xD[nn++] = _IQtoF(vect_control.iqId1);//_IQtoF(vect_control.iqUqCompensation1);//
+	xD[nn++] = _IQtoF(vect_control.iqIq1);
+	xD[nn++] = _IQtoF(vect_control.Iq_zad1);
+	xD[nn++] = _IQtoF(vect_control.Id_zad1);//iqZ;
+
+	xD[nn++] = 0;
+
+	xD[nn++] = xpwm_time.Ta0_0;
+	xD[nn++] = xpwm_time.Ta0_1;
 }
\ No newline at end of file
diff --git a/Inu/controller.c b/Inu/controller.c
index ef0e290..1a5f80f 100644
--- a/Inu/controller.c
+++ b/Inu/controller.c
@@ -15,46 +15,13 @@
 #include "param.h"
 
 
-extern UMotorMeasure motor;
-
-extern TimerSimHandle t1sim;
-extern TimerSimHandle t2sim;
-extern TimerSimHandle t3sim;
-extern TimerSimHandle t4sim;
-extern TimerSimHandle t5sim;
-extern TimerSimHandle t6sim;
-extern TimerSimHandle t7sim;
-extern TimerSimHandle t8sim;
-extern TimerSimHandle t9sim;
-extern TimerSimHandle t10sim;
-extern TimerSimHandle t11sim;
-extern TimerSimHandle t12sim;
-
-extern DeadBandSimHandle dt1sim;
-extern DeadBandSimHandle dt2sim;
-extern DeadBandSimHandle dt3sim;
-extern DeadBandSimHandle dt4sim;
-extern DeadBandSimHandle dt5sim;
-extern DeadBandSimHandle dt6sim;
-extern DeadBandSimHandle dt7sim;
-extern DeadBandSimHandle dt8sim;
-extern DeadBandSimHandle dt9sim;
-extern DeadBandSimHandle dt10sim;
-extern DeadBandSimHandle dt11sim;
-extern DeadBandSimHandle dt12sim;
-
-extern void init28335(void);
-extern void detcoeff(void);
-extern void isr(void);
-extern void input_param(unsigned short num, unsigned short val);
-// extern void init_DQ_pid();
-int calcAlgUpr = 0;
-
-int timers_adc = 0;
-int timers_pwm = 0;
-
-
+UMotorMeasure motor; 
+double dt;
 
+// ��� �������� ������ � ��
+int j;
+unsigned short paramNo;
+unsigned short paramNew[PAR_NUMBER];
 void processSFunctionIfChanged(SimStruct *S, int_T *iW) {
 
 	// ������������ ��������� S-Function ������ ���, ����� ��� ����������
@@ -83,7 +50,7 @@ void processSFunctionIfChanged(SimStruct *S, int_T *iW) {
 		}
 		// ��������� (begin)
 		int nn = 0;
-		double dt = paramScal[nn++];//��� ������������� (������ ������ ������������ � S-function ���������!)
+		dt = paramScal[nn++];//��� ������������� (������ ������ ������������ � S-function ���������!)
 		// ��������� (end)
 	} //if ( iW[0] == 1 )
 
@@ -94,216 +61,13 @@ void initialisationOnStart(int_T *iW) {
 	// ���-��� ��������� ���� ��� ��� ������� ������
 	if ( iW[1] == 1 ) {
 		iW[1] = 0;
-
+		Init_Timers();
 		init28335();
 	} //if ( iW[1] == 1 )
 
 
 }
 
-void simulatePWMcounterAndReadComarators(void) {
-
-	//// ���������� Time-Base Submodule, Counter-Compare Submodule �
-	//// Event-Trigger Submodule
-	//// ePWM1 (up-down-count mode)
-	//// -------------------------
-	//t1cntAuxPrev = t1cntAux;
-	//t1cntAux += TxCntPlus;
-	//if ( t1cntAux > T1Pr ) {
-	//	t1cntAux -= T1Pr*2.;
-	//	// active CMPA load from shadow when TBCTR == TBPRD
-	//	cmp1A = (double)EPwm1Regs.CMPA.half.CMPA;
-	//	// ������ ���
-	//	// tAdc = Tadc;
-	//	// nAdc = 0;
-	//	calcAlgUpr = 1; // ��� ����������
-	//}
-	//if ( (t1cntAuxPrev < 0) && (t1cntAux >= 0) ) {
-	//	// active CMPA load from shadow when TBCTR == 0
-	//	cmp1A = (double)EPwm1Regs.CMPA.half.CMPA;
-	//	// ������ ���
-	//	// tAdc = Tadc;
-	//	// nAdc = 0;
-	//	calcAlgUpr = 1; // ��� ����������
-	//}
-	//t1cnt = fabs(t1cntAux);
-
-	//// ePWM2 (up-down-count mode)
-	//// -------------------------
-	//t2cntAuxPrev = t2cntAux;
-	//t2cntAux += TxCntPlus;
-	//if ( t2cntAux > T2Pr ) {
-	//	t2cntAux -= T2Pr*2.;
-	//	// active CMPA load from shadow when TBCTR == TBPRD
-	//	cmp2A = (double)EPwm2Regs.CMPA.half.CMPA;
-	//}
-	//if ( (t2cntAuxPrev < 0) && (t2cntAux >= 0) ) {
-	//	// active CMPA load from shadow when TBCTR == 0
-	//	cmp2A = (double)EPwm2Regs.CMPA.half.CMPA;
-	//}
-	//t2cnt = fabs(t2cntAux);
-
-	//// ePWM3 (up-down-count mode)
-	//// -------------------------
-	//t3cntAuxPrev = t3cntAux;
-	//t3cntAux += TxCntPlus;
-	//if ( t3cntAux > T3Pr ) {
-	//	t3cntAux -= T3Pr*2.;
-	//	// active CMPA load from shadow when TBCTR == TBPRD
-	//	cmp3A = (double)EPwm3Regs.CMPA.half.CMPA;
-	//}
-	//if ( (t3cntAuxPrev < 0) && (t3cntAux >= 0) ) {
-	//	// active CMPA load from shadow when TBCTR == 0
-	//	cmp3A = (double)EPwm3Regs.CMPA.half.CMPA;
-	//}
-	//t3cnt = fabs(t3cntAux);
-
-	//// ePWM4 (up-down-count mode)
-	//// -------------------------
-	//t4cntAuxPrev = t4cntAux;
-	//t4cntAux += TxCntPlus;
-	//if ( t4cntAux > T4Pr ) {
-	//	t4cntAux -= T4Pr*2.;
-	//	// active CMPA load from shadow when TBCTR == TBPRD
-	//	cmp4A = (double)EPwm4Regs.CMPA.half.CMPA;
-	//}
-	//if ( (t4cntAuxPrev < 0) && (t4cntAux >= 0) ) {
-	//	// active CMPA load from shadow when TBCTR == 0
-	//	cmp4A = (double)EPwm4Regs.CMPA.half.CMPA;
-	//}
-	//t4cnt = fabs(t4cntAux);
-
-	//// ePWM5 (up-down-count mode)
-	//// -------------------------
-	//t5cntAuxPrev = t5cntAux;
-	//t5cntAux += TxCntPlus;
-	//if ( t5cntAux > T5Pr ) {
-	//	t5cntAux -= T5Pr*2.;
-	//	// active CMPA load from shadow when TBCTR == TBPRD
-	//	cmp5A = (double)EPwm5Regs.CMPA.half.CMPA;
-	//}
-	//if ( (t5cntAuxPrev < 0) && (t5cntAux >= 0) ) {
-	//	// active CMPA load from shadow when TBCTR == 0
-	//	cmp5A = (double)EPwm5Regs.CMPA.half.CMPA;
-	//}
-	//t5cnt = fabs(t5cntAux);
-
-	//// ePWM6 (up-down-count mode)
-	//// -------------------------
-	//t6cntAuxPrev = t6cntAux;
-	//t6cntAux += TxCntPlus;
-	//if ( t6cntAux > T6Pr ) {
-	//	t6cntAux -= T6Pr*2.;
-	//	// active CMPA load from shadow when TBCTR == TBPRD
-	//	cmp6A = (double)EPwm6Regs.CMPA.half.CMPA;
-	//}
-	//if ( (t6cntAuxPrev < 0) && (t6cntAux >= 0) ) {
-	//	// active CMPA load from shadow when TBCTR == 0
-	//	cmp6A = (double)EPwm6Regs.CMPA.half.CMPA;
-	//}
-	//t6cnt = fabs(t6cntAux);
-
-	//// ePWM7 (up-down-count mode)
-	//// -------------------------
-	//t7cntAuxPrev = t7cntAux;
-	//t7cntAux += TxCntPlus;
-	//if (t7cntAux > T7Pr) {
-	//	t7cntAux -= T7Pr*2.;
-	//	// active CMPA load from shadow when TBCTR == TBPRD
-	//	cmp7A = (double)EPwm7Regs.CMPA.half.CMPA;
-	//}
-	//if ( (t7cntAuxPrev < 0) && (t7cntAux >= 0) ) {
-	//	// active CMPA load from shadow when TBCTR == 0
-	//	cmp7A = (double)EPwm7Regs.CMPA.half.CMPA;
-	//}
-	//t7cnt = fabs(t7cntAux);
-
-	//// ePWM8 (up-down-count mode)
-	//// -------------------------
-	//t8cntAuxPrev = t8cntAux;
-	//t8cntAux += TxCntPlus;
-	//if(t8cntAux > T8Pr) {
-	//	t8cntAux -= T8Pr*2.;
-	//	// active CMPA load from shadow when TBCTR == TBPRD
-	//	cmp8A = (double)EPwm8Regs.CMPA.half.CMPA;
-	//}
-	//if((t8cntAuxPrev < 0) && (t8cntAux >= 0)) {
-	//	// active CMPA load from shadow when TBCTR == 0
-	//	cmp8A = (double)EPwm8Regs.CMPA.half.CMPA;
-	//}
-	//t8cnt = fabs(t8cntAux);
-
-	//// ePWM9 (up-down-count mode)
-	//// -------------------------
-	//t9cntAuxPrev = t9cntAux;
-	//t9cntAux += TxCntPlus;
-	//if(t9cntAux > T9Pr) {
-	//	t9cntAux -= T9Pr*2.;
-	//	// active CMPA load from shadow when TBCTR == TBPRD
-	//	cmp9A = (double)EPwm9Regs.CMPA.half.CMPA;
-	//}
-	//if((t9cntAuxPrev < 0) && (t9cntAux >= 0)) {
-	//	// active CMPA load from shadow when TBCTR == 0
-	//	cmp9A = (double)EPwm9Regs.CMPA.half.CMPA;
-	//}
-	//t9cnt = fabs(t9cntAux);
-
-	//// ePWM10 (up-down-count mode)
-	//// -------------------------
-	//t10cntAuxPrev = t10cntAux;
-	//t10cntAux += TxCntPlus;
-	//if(t10cntAux > T10Pr) {
-	//	t10cntAux -= T10Pr*2.;
-	//	// active CMPA load from shadow when TBCTR == TBPRD
-	//	cmp10A = (double)EPwm10Regs.CMPA.half.CMPA;
-	//}
-	//if((t10cntAuxPrev < 0) && (t10cntAux >= 0)) {
-	//	// active CMPA load from shadow when TBCTR == 0
-	//	cmp10A = (double)EPwm10Regs.CMPA.half.CMPA;
-	//}
-	//t10cnt = fabs(t10cntAux);
-
-	//// ePWM11 (up-down-count mode)
-	//// -------------------------
-	//t11cntAuxPrev = t11cntAux;
-	//t11cntAux += TxCntPlus;
-	//if(t11cntAux > T11Pr) {
-	//	t11cntAux -= T11Pr*2.;
-	//	// active CMPA load from shadow when TBCTR == TBPRD
-	//	cmp11A = (double)EPwm11Regs.CMPA.half.CMPA;
-	//}
-	//if((t11cntAuxPrev < 0) && (t11cntAux >= 0)) {
-	//	// active CMPA load from shadow when TBCTR == 0
-	//	cmp11A = (double)EPwm11Regs.CMPA.half.CMPA;
-	//}
-	//t11cnt = fabs(t11cntAux);
-
-	//// ePWM12 (up-down-count mode)
-	//// -------------------------
-	//t12cntAuxPrev = t12cntAux;
-	//t12cntAux += TxCntPlus;
-	//if(t12cntAux > T12Pr) {
-	//	t12cntAux -= T12Pr*2.;
-	//	// active CMPA load from shadow when TBCTR == TBPRD
-	//	cmp12A = (double)EPwm12Regs.CMPA.half.CMPA;
-	//}
-	//if((t12cntAuxPrev < 0) && (t12cntAux >= 0)) {
-	//	// active CMPA load from shadow when TBCTR == 0
-	//	cmp12A = (double)EPwm12Regs.CMPA.half.CMPA;
-	//}
-	//t12cnt = fabs(t12cntAux);
-
-
-	//// ���������� ������ �������� � eQEP
-	//qposcnt += wm_ml/PI2*NOP*4.*dt;
-	//if ( qposcnt >= (Qposmax + 1.) )
-	//	qposcnt -= (Qposmax + 1.);
-	//else if ( qposcnt < 0 )
-	//	qposcnt += (Qposmax + 1.);
-	//EQep2Regs.QPOSCNT = (short)qposcnt;
-
-}
-
 
 void update_norm_ADC_array()
 {
@@ -463,461 +227,6 @@ void simulateAdcAndCallIsr() {
 
 }
 
-void simulateActionActionQualifierSubmodule(void) {
-	//// ���������� Action-Qualifier Submodule
-	//// ... ePWM1
-	//if ( cmp1A > t1cnt ) {
-	//	ci1A = 0;
-	//	ci1B = 1; 
-	//}
-	//else if ( cmp1A < t1cnt ) {
-	//	ci1A = 1;
-	//	ci1B = 0;
-	//}
-	//// ... ePWM2
-	//if ( cmp2A > t2cnt ) {
-	//	ci2A = 0;
-	//	ci2B = 1;
-	//}
-	//else if ( cmp2A < t2cnt ) {
-	//	ci2A = 1;
-	//	ci2B = 0;
-	//}
-	//// ... ePWM3
-	//if ( cmp3A > t3cnt ) {
-	//	ci3A = 0;
-	//	ci3B = 1;
-	//}
-	//else if ( cmp3A < t3cnt ) {
-	//	ci3A = 1;
-	//	ci3B = 0;
-	//}
-	//// ... ePWM4
-	//if ( cmp4A > t4cnt ) {
-	//	ci4A = 0;
-	//	ci4B = 1;
-	//}
-	//else if ( cmp4A < t4cnt ) {
-	//	ci4A = 1;
-	//	ci4B = 0;
-	//}
-	//// ... ePWM5
-	//if ( cmp5A > t5cnt ) {
-	//	ci5A = 0;
-	//	ci5B = 1;
-	//}
-	//else if ( cmp5A < t5cnt ) {
-	//	ci5A = 1;
-	//	ci5B = 0;
-	//}
-	//// ... ePWM6
-	//if ( cmp6A > t6cnt ) {
-	//	ci6A = 0;
-	//	ci6B = 1;
-	//}
-	//else if ( cmp6A < t6cnt ) {
-	//	ci6A = 1;
-	//	ci6B = 0;
-	//}
-	//// ... ePWM7
-	//if ( cmp7A > t7cnt ) {
-	//	ci7A = 0;
-	//	ci7B = 1;
-	//}
-	//else if ( cmp7A < t7cnt ) {
-	//	ci7A = 1;
-	//	ci7B = 0;
-	//}
-	//// ... ePWM8
-	//if ( cmp8A > t8cnt ) {
-	//	ci8A = 0;
-	//	ci8B = 1;
-	//}
-	//else if ( cmp8A < t8cnt ) {
-	//	ci8A = 1;
-	//	ci8B = 0;
-	//}
-	//// ... ePWM9
-	//if ( cmp9A > t9cnt ) {
-	//	ci9A = 0;
-	//	ci9B = 1;
-	//}
-	//else if ( cmp9A < t9cnt ) {
-	//	ci9A = 1;
-	//	ci9B = 0;
-	//}
-	//// ... ePWM10
-	//if ( cmp10A > t10cnt ) {
-	//	ci10A = 0;
-	//	ci10B = 1;
-	//}
-	//else if ( cmp10A < t10cnt ) {
-	//	ci10A = 1;
-	//	ci10B = 0;
-	//}
-	//// ... ePWM11
-	//if ( cmp11A > t11cnt ) {
-	//	ci11A = 0;
-	//	ci11B = 1;
-	//}
-	//else if ( cmp11A < t11cnt ) {
-	//	ci11A = 1;
-	//	ci11B = 0;
-	//}
-	//// ... ePWM12
-	//if ( cmp12A > t12cnt ) {
-	//	ci12A = 0;
-	//	ci12B = 1;
-	//}
-	//else if ( cmp12A < t12cnt ) {
-	//	ci12A = 1;
-	//	ci12B = 0;
-	//}
-
-
-}
-
-void simulateDeadBendSubmodule(void) {
-
-	//// ���������� Dead-Band Submodule
-	//// ... ePWM1
-	//if ( stateDt1 == 1 ) {
-	//	ci1A_DT = ci1A;
-	//	ci1B_DT = 0;
-	//	if ( ci1A == 1 )
-	//		cntDt1 = CntDt;
-	//	if ( cntDt1 > 0 )
-	//		cntDt1--;
-	//	else
-	//		stateDt1 = 2;
-	//}
-	//else if ( stateDt1 == 2 ) {
-	//	ci1A_DT = 0;
-	//	ci1B_DT = ci1B;
-	//	if ( ci1B == 1 )
-	//		cntDt1 = CntDt;
-	//	if ( cntDt1 > 0 )
-	//		cntDt1--;
-	//	else
-	//		stateDt1 = 1;
-	//}
-	//// ... ePWM2
-	//if ( stateDt2 == 1 ) {
-	//	ci2A_DT = ci2A;
-	//	ci2B_DT = 0;
-	//	if ( ci2A == 1 )
-	//		cntDt2 = CntDt;
-	//	if ( cntDt2 > 0 )
-	//		cntDt2--;
-	//	else
-	//		stateDt2 = 2;
-	//}
-	//else if ( stateDt2 == 2 ) {
-	//	ci2A_DT = 0;
-	//	ci2B_DT = ci2B;
-	//	if ( ci2B == 1 )
-	//		cntDt2 = CntDt;
-	//	if ( cntDt2 > 0 )
-	//		cntDt2--;
-	//	else
-	//		stateDt2 = 1;
-	//}
-	//// ... ePWM3
-	//if ( stateDt3 == 1 ) {
-	//	ci3A_DT = ci3A;
-	//	ci3B_DT = 0;
-	//	if ( ci3A == 1 )
-	//		cntDt3 = CntDt;
-	//	if ( cntDt3 > 0 )
-	//		cntDt3--;
-	//	else
-	//		stateDt3 = 2;
-	//}
-	//else if ( stateDt3 == 2 ) {
-	//	ci3A_DT = 0;
-	//	ci3B_DT = ci3B;
-	//	if ( ci3B == 1 )
-	//		cntDt3 = CntDt;
-	//	if ( cntDt3 > 0 )
-	//		cntDt3--;
-	//	else
-	//		stateDt3 = 1;
-	//}
-	//// ... ePWM4
-	//if ( stateDt4 == 1 ) {
-	//	ci4A_DT = ci4A;
-	//	ci4B_DT = 0;
-	//	if ( ci4A == 1 )
-	//		cntDt4 = CntDt;
-	//	if ( cntDt4 > 0 )
-	//		cntDt4--;
-	//	else
-	//		stateDt4 = 2;
-	//}
-	//else if ( stateDt4 == 2 ) {
-	//	ci4A_DT = 0;
-	//	ci4B_DT = ci4B;
-	//	if ( ci4B == 1 )
-	//		cntDt4 = CntDt;
-	//	if ( cntDt4 > 0 )
-	//		cntDt4--;
-	//	else
-	//		stateDt4 = 1;
-	//}
-	//// ... ePWM5
-	//if ( stateDt5 == 1 ) {
-	//	ci5A_DT = ci5A;
-	//	ci5B_DT = 0;
-	//	if ( ci5A == 1 )
-	//		cntDt5 = CntDt;
-	//	if ( cntDt5 > 0 )
-	//		cntDt5--;
-	//	else
-	//		stateDt5 = 2;
-	//}
-	//else if ( stateDt5 == 2 ) {
-	//	ci5A_DT = 0;
-	//	ci5B_DT = ci5B;
-	//	if ( ci5B == 1 )
-	//		cntDt5 = CntDt;
-	//	if ( cntDt5 > 0 )
-	//		cntDt5--;
-	//	else
-	//		stateDt5 = 1;
-	//}
-	//// ... ePWM6
-	//if ( stateDt6 == 1 ) {
-	//	ci6A_DT = ci6A;
-	//	ci6B_DT = 0;
-	//	if ( ci6A == 1 )
-	//		cntDt6 = CntDt;
-	//	if ( cntDt6 > 0 )
-	//		cntDt6--;
-	//	else
-	//		stateDt6 = 2;
-	//}
-	//else if ( stateDt6 == 2 ) {
-	//	ci6A_DT = 0;
-	//	ci6B_DT = ci6B;
-	//	if ( ci6B == 1 )
-	//		cntDt6 = CntDt;
-	//	if ( cntDt6 > 0 )
-	//		cntDt6--;
-	//	else
-	//		stateDt6 = 1;
-	//}
-	//// ... ePWM7
-	//if ( stateDt7 == 1 ) {
-	//	ci7A_DT = ci7A;
-	//	ci7B_DT = 0;
-	//	if ( ci7A == 1 )
-	//		cntDt7 = CntDt;
-	//	if ( cntDt7 > 0 )
-	//		cntDt7--;
-	//	else
-	//		stateDt7 = 2;
-	//}
-	//else if ( stateDt7 == 2 ) {
-	//	ci7A_DT = 0;
-	//	ci7B_DT = ci7B;
-	//	if ( ci7B == 1 )
-	//		cntDt7 = CntDt;
-	//	if ( cntDt7 > 0 )
-	//		cntDt7--;
-	//	else
-	//		stateDt7 = 1;
-	//}
-	//// ... ePWM8
-	//if ( stateDt8 == 1 ) {
-	//	ci8A_DT = ci8A;
-	//	ci8B_DT = 0;
-	//	if ( ci8A == 1 )
-	//		cntDt8 = CntDt;
-	//	if ( cntDt8 > 0 )
-	//		cntDt8--;
-	//	else
-	//		stateDt8 = 2;
-	//}
-	//else if ( stateDt8 == 2 ) {
-	//	ci8A_DT = 0;
-	//	ci8B_DT = ci8B;
-	//	if ( ci8B == 1 )
-	//		cntDt8 = CntDt;
-	//	if ( cntDt8 > 0 )
-	//		cntDt8--;
-	//	else
-	//		stateDt8 = 1;
-	//}
-	//// ... ePWM9
-	//if ( stateDt9 == 1 ) {
-	//	ci9A_DT = ci9A;
-	//	ci9B_DT = 0;
-	//	if ( ci9A == 1 )
-	//		cntDt9 = CntDt;
-	//	if ( cntDt9 > 0 )
-	//		cntDt9--;
-	//	else
-	//		stateDt9 = 2;
-	//}
-	//else if ( stateDt9 == 2 ) {
-	//	ci9A_DT = 0;
-	//	ci9B_DT = ci9B;
-	//	if ( ci9B == 1 )
-	//		cntDt9 = CntDt;
-	//	if ( cntDt9 > 0 )
-	//		cntDt9--;
-	//	else
-	//		stateDt9 = 1;
-	//}
-	//// ... ePWM10
-	//if ( stateDt10 == 1 ) {
-	//	ci10A_DT = ci10A;
-	//	ci10B_DT = 0;
-	//	if ( ci10A == 1 )
-	//		cntDt10 = CntDt;
-	//	if ( cntDt10 > 0 )
-	//		cntDt10--;
-	//	else
-	//		stateDt10 = 2;
-	//}
-	//else if ( stateDt10 == 2 ) {
-	//	ci10A_DT = 0;
-	//	ci10B_DT = ci10B;
-	//	if ( ci10B == 1 )
-	//		cntDt10 = CntDt;
-	//	if ( cntDt10 > 0 )
-	//		cntDt10--;
-	//	else
-	//		stateDt10 = 1;
-	//}
-	//// ... ePWM11
-	//if ( stateDt11 == 1 ) {
-	//	ci11A_DT = ci11A;
-	//	ci11B_DT = 0;
-	//	if ( ci11A == 1 )
-	//		cntDt11 = CntDt;
-	//	if ( cntDt11 > 0 )
-	//		cntDt11--;
-	//	else
-	//		stateDt11 = 2;
-	//}
-	//else if ( stateDt11 == 2 ) {
-	//	ci11A_DT = 0;
-	//	ci11B_DT = ci11B;
-	//	if ( ci11B == 1 )
-	//		cntDt11 = CntDt;
-	//	if ( cntDt11 > 0 )
-	//		cntDt11--;
-	//	else
-	//		stateDt11 = 1;
-	//}
-	//// ... ePWM12
-	//if ( stateDt12 == 1 ) {
-	//	ci12A_DT = ci12A;
-	//	ci12B_DT = 0;
-	//	if ( ci12A == 1 )
-	//		cntDt12 = CntDt;
-	//	if ( cntDt12 > 0 )
-	//		cntDt12--;
-	//	else
-	//		stateDt12 = 2;
-	//}
-	//else if ( stateDt12 == 2 ) {
-	//	ci12A_DT = 0;
-	//	ci12B_DT = ci12B;
-	//	if ( ci12B == 1 )
-	//		cntDt12 = CntDt;
-	//	if ( cntDt12 > 0 )
-	//		cntDt12--;
-	//	else
-	//		stateDt12 = 1;
-	//}
-
-}
-
-
-void simulateTripZoneSubmodule(void) {
-
-//// ���������� Trip-Zone Submodule
-//	// ... clear flag for one-shot trip latch
-//	if ( EPwm1Regs.TZCLR.all == 0x0004 ) {
-//		EPwm1Regs.TZCLR.all = 0x0000;
-//		EPwm1Regs.TZFRC.all = 0x0000;
-//	}
-//	if ( EPwm2Regs.TZCLR.all == 0x0004 ) {
-//		EPwm2Regs.TZCLR.all = 0x0000;
-//		EPwm2Regs.TZFRC.all = 0x0000;
-//	}
-//	if ( EPwm3Regs.TZCLR.all == 0x0004 ) {
-//		EPwm3Regs.TZCLR.all = 0x0000;
-//		EPwm3Regs.TZFRC.all = 0x0000;
-//	}
-//	if ( EPwm4Regs.TZCLR.all == 0x0004 ) {
-//		EPwm4Regs.TZCLR.all = 0x0000;
-//		EPwm4Regs.TZFRC.all = 0x0000;
-//	}
-//	if ( EPwm5Regs.TZCLR.all == 0x0004 ) {
-//		EPwm5Regs.TZCLR.all = 0x0000;
-//		EPwm5Regs.TZFRC.all = 0x0000;
-//	}
-//	if ( EPwm6Regs.TZCLR.all == 0x0004 ) {
-//		EPwm6Regs.TZCLR.all = 0x0000;
-//		EPwm6Regs.TZFRC.all = 0x0000;
-//	}
-//	if ( EPwm7Regs.TZCLR.all == 0x0004 ) {
-//		EPwm7Regs.TZCLR.all = 0x0000;
-//		EPwm7Regs.TZFRC.all = 0x0000;
-//	}
-//	if ( EPwm8Regs.TZCLR.all == 0x0004 ) {
-//		EPwm8Regs.TZCLR.all = 0x0000;
-//		EPwm8Regs.TZFRC.all = 0x0000;
-//	}
-//	if ( EPwm9Regs.TZCLR.all == 0x0004 ) {
-//		EPwm9Regs.TZCLR.all = 0x0000;
-//		EPwm9Regs.TZFRC.all = 0x0000;
-//	}
-//	if ( EPwm10Regs.TZCLR.all == 0x0004 ) {
-//		EPwm10Regs.TZCLR.all = 0x0000;
-//		EPwm10Regs.TZFRC.all = 0x0000;
-//	}
-//	if ( EPwm11Regs.TZCLR.all == 0x0004 ) {
-//		EPwm11Regs.TZCLR.all = 0x0000;
-//		EPwm11Regs.TZFRC.all = 0x0000;
-//	}
-//	if ( EPwm12Regs.TZCLR.all == 0x0004 ) {
-//		EPwm12Regs.TZCLR.all = 0x0000;
-//		EPwm12Regs.TZFRC.all = 0x0000;
-//	}
-//	// ... forces a one-shot trip event
-//	if ( EPwm1Regs.TZFRC.all == 0x0004 )
-//		ci1A_DT = ci1B_DT = 0;
-//	if ( EPwm2Regs.TZFRC.all == 0x0004 )
-//		ci2A_DT = ci2B_DT = 0;
-//	if ( EPwm3Regs.TZFRC.all == 0x0004 )
-//		ci3A_DT = ci3B_DT = 0;
-//	if ( EPwm4Regs.TZFRC.all == 0x0004 )
-//		ci4A_DT = ci4B_DT = 0;
-//	if ( EPwm5Regs.TZFRC.all == 0x0004 )
-//		ci5A_DT = ci5B_DT = 0;
-//	if ( EPwm6Regs.TZFRC.all == 0x0004 )
-//		ci6A_DT = ci6B_DT = 0;
-//	if ( EPwm7Regs.TZFRC.all == 0x0004 )
-//		ci7A_DT = ci7B_DT = 0;
-//	if ( EPwm8Regs.TZFRC.all == 0x0004 )
-//		ci8A_DT = ci8B_DT = 0;
-//	if ( EPwm9Regs.TZFRC.all == 0x0004 )
-//		ci9A_DT = ci9B_DT = 0;
-//	if ( EPwm10Regs.TZFRC.all == 0x0004 )
-//		ci10A_DT = ci10B_DT = 0;
-//	if ( EPwm11Regs.TZFRC.all == 0x0004 )
-//		ci11A_DT = ci11B_DT = 0;
-//	if ( EPwm12Regs.TZFRC.all == 0x0004 )
-//		ci12A_DT = ci12B_DT = 0;
-
-
-}
-
-
 
 
 void controller(SimStruct *S, const real_T *u, real_T *xD, real_T *rW, int_T *iW) {
@@ -927,17 +236,11 @@ void controller(SimStruct *S, const real_T *u, real_T *xD, real_T *rW, int_T *iW
 	processSFunctionIfChanged(S, iW);
 	initialisationOnStart(iW);
 
-	simulatePWMcounterAndReadComarators();
+	Simulate_Timers();
 
 	
 	simulateAdcAndCallIsr();
-	simulateActionActionQualifierSubmodule();
 
-	// convertSVGenTimesToTkLines();
-	simulateDeadBendSubmodule();
-
-	// xilinxPwm3LevelSimulation();
-	simulateTripZoneSubmodule();
 
 
 	writeOutputParameters(xD);
diff --git a/Inu/controller.h b/Inu/controller.h
index a16fe3b..a5f0e99 100644
--- a/Inu/controller.h
+++ b/Inu/controller.h
@@ -2,6 +2,10 @@
 
 #include "wrapper_inu.h"
 #include "def.h"
+#include "pwm_sim.h"
+
+
+
 #include "edrk_main.h"
 #include "vector.h"
 #include "vector_control.h"
@@ -15,6 +19,7 @@
 #include "CAN_Setup.h"
 #include "RS_Functions.h"
 #include "master_slave.h"
+#include "xp_write_xpwm_time.h"
 
 #include <params.h>
 #include <params_alg.h>
@@ -54,190 +59,4 @@ typedef struct
 }UMotorMeasure;
 extern UMotorMeasure motor;
 
-// ��� �������� ������ � ��
-int j;
-unsigned short paramNo;
-unsigned short paramNew[PAR_NUMBER];
-
-// ��� ������������� Event Manager
-// ... Time-Base Submodule, Counter-Compare Submodule � Event-Trigger Submodule
-typedef struct
-{
-	double TxCntPlus;
-	double TPr;
-	double tcntAux;
-	double tcntAuxPrev;
-	double tcnt;
-	double cmp1A;
-	double cmp1B;
-}TimerSimHandle;
-extern TimerSimHandle t1sim;
-extern TimerSimHandle t2sim;
-extern TimerSimHandle t3sim;
-extern TimerSimHandle t4sim;
-extern TimerSimHandle t5sim;
-extern TimerSimHandle t6sim;
-extern TimerSimHandle t7sim;
-extern TimerSimHandle t8sim;
-extern TimerSimHandle t9sim;
-extern TimerSimHandle t10sim;
-extern TimerSimHandle t11sim;
-extern TimerSimHandle t12sim;
-
-
-// ... Action-Qualifier Submodule
-int ci1A;
-int ci1B;
-int ci2A;
-int ci2B;
-int ci3A;
-int ci3B;
-int ci4A;
-int ci4B;
-int ci5A;
-int ci5B;
-int ci6A;
-int ci6B;
-int ci7A;
-int ci7B;
-int ci8A;
-int ci8B;
-int ci9A;
-int ci9B;
-int ci10A;
-int ci10B;
-int ci11A;
-int ci11B;
-int ci12A;
-int ci12B;
-// ... Dead-Band Submodule
-typedef struct
-{
-	int CntDt;
-	int stateDt;
-	int cntDt;
-	int ciA_DT;
-	int ciB_DT;
-}DeadBandSimHandle;
-extern DeadBandSimHandle dt1sim;
-extern DeadBandSimHandle dt2sim;
-extern DeadBandSimHandle dt3sim;
-extern DeadBandSimHandle dt4sim;
-extern DeadBandSimHandle dt5sim;
-extern DeadBandSimHandle dt6sim;
-extern DeadBandSimHandle dt7sim;
-extern DeadBandSimHandle dt8sim;
-extern DeadBandSimHandle dt9sim;
-extern DeadBandSimHandle dt10sim;
-extern DeadBandSimHandle dt11sim;
-extern DeadBandSimHandle dt12sim;
-
-// ��� ������������� eQEP
-double Qposmax;
-double qposcnt;
-
-// ��� ������������� ADC
-int tAdc;
-int Tadc;
-int nAdc;
-//#########################################################################
-// ����������, ������� ���������� � controller.c (end)
-
-
-
-
-// ����������, ������� ��������� � controller.c (begin)
-//#########################################################################
-// ��� isr.c
-//-------------------------------------------------------------------------
-extern struct Offset offset;
-extern volatile struct Result result;
-extern volatile short state;
-extern volatile short faultNo;
-extern volatile struct Out out;
-// Udc
-extern float Kudc;
-extern volatile float udc1Nf;
-extern volatile float udc1;
-extern volatile float udc2Nf;
-extern volatile float udc2;
-// Iac
-extern volatile float ia1Nf;
-extern volatile float ib1Nf;
-extern volatile float ix1;
-extern volatile float iy1;
-extern volatile float iac1Nf;
-extern volatile float ia2Nf;
-extern volatile float ib2Nf;
-extern volatile float ix2;
-extern volatile float iy2;
-extern volatile float iac2Nf;
-// Wm
-extern float Kwm;
-extern volatile float wmNf;
-extern volatile float wm;
-extern volatile float wmAbs;
-// Me
-extern volatile float kMe;
-extern float KmeCorr;
-extern float Kme;
-extern volatile float meNf;
-extern volatile float me;
-// Pm
-extern volatile float pm;
-// ������
-extern struct Protect protect;
-extern volatile struct Emerg emerg;
-extern short csmSuccess;
-// ����������� ������
-extern volatile short onceShutdown;
-extern volatile short testParamFaultNo;
-extern volatile short onceFaultReset;
-extern volatile short stopPause;
-extern volatile short inuWork;
-// �����
-extern struct Mst mst;
-
-
-
-// ��� main.c
-//-------------------------------------------------------------------------
-extern struct Eprom eprom;
-
-
-
-// ��� upr.c
-//-------------------------------------------------------------------------
-extern volatile short onceUpr;
-extern struct SgmPar sgmPar;
-extern struct Rf rf;
-extern struct Rs rs;
-extern struct Rp rp;
-
-extern float IzLim;
-extern volatile float psi;
-extern float idZ;
-extern float iqZ;
-extern float iZ;
-extern float ws;
-extern float sinTheta;
-extern float cosTheta;
-extern float id1;
-extern float iq1;
-extern float id2;
-extern float iq2;
-extern struct Cc cc;
-extern struct Cf cf;
-extern struct Csp csp;
-extern struct Ivc ivc;
-extern struct Ip ip;
-
-
-
-// ��� param.c
-//-------------------------------------------------------------------------
-extern unsigned short param[];
-//#########################################################################
-// ����������, ������� ��������� � controller.c (end)
-
 #endif //__WRAPPER_CONTROLLER_H
\ No newline at end of file
diff --git a/Inu/main.c b/Inu/main.c
deleted file mode 100644
index 05cade6..0000000
--- a/Inu/main.c
+++ /dev/null
@@ -1,144 +0,0 @@
-/**************************************************************************
-	Description: ��������� ���������� INU.
-	�������� �/� ������������� ���������� � �/� ������.
-
-	�����: ���������� �.�.
-	���� ���������� ����������: 2021.10.05
-**************************************************************************/
-
-
-#include "def.h"
-#include "main.h"
-
-
-void control_processor_led(void);
-void talk_with_desk(void);
-void talk_with_mst(void);
-void write_eeprom(void);
-extern void detcoeff(void);
-extern void init28335(void);
-
-
-#ifndef ML
-void main(void) {
-	// disable the watchdog
-	EALLOW;
-	SysCtrlRegs.WDCR = 0x0068;
-	EDIS;
-
-	// ������������� ����������
-	init28335();
-
-	// ������������� ���������
-	detcoeff();
-
-	// re-enable the watchdog
-	EALLOW;
-	SysCtrlRegs.WDCR = 0x00A8;
-	// ... clear the WD counter
-	SysCtrlRegs.WDKEY = 0x55;
-	SysCtrlRegs.WDKEY = 0xAA;
-	EDIS;
-
-	// clear Interrupt Flag ADC Sequencer 1
-	AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
-	// clear PIEIFR1 register
-	PieCtrlRegs.PIEIFR1.all = 0;
-
-	// before we can start we have to enable interrupt mask in the PIE unit
-	PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
-	// core line 1 (INT1)
-	IER |= M_INT1;
-	// enable global interrupts and higher priority real-time debug events
-	EINT;
-	ERTM;
-
-	// ��������� ������� (up-down-count mode)
-	EPwm1Regs.TBCTL.bit.CTRMODE = 2;
-	EPwm2Regs.TBCTL.bit.CTRMODE = 2;
-	EPwm3Regs.TBCTL.bit.CTRMODE = 2;
-	EPwm4Regs.TBCTL.bit.CTRMODE = 2;
-	EPwm5Regs.TBCTL.bit.CTRMODE = 2;
-	EPwm6Regs.TBCTL.bit.CTRMODE = 2;
-#ifdef ML
-	EPwm7Regs.TBCTL.bit.CTRMODE = 2;
-	EPwm8Regs.TBCTL.bit.CTRMODE = 2;
-	EPwm9Regs.TBCTL.bit.CTRMODE = 2;
-	EPwm10Regs.TBCTL.bit.CTRMODE = 2;
-	EPwm11Regs.TBCTL.bit.CTRMODE = 2;
-	EPwm12Regs.TBCTL.bit.CTRMODE = 2;
-#endif
-
-	// loop forever
-	while(1) {
-		// ����� � ��
-		// ( -> mst)
-		talk_with_mst();
-		// ����� � ��
-		// ( -> param[], eprom.writeRequestNumber)
-		talk_with_desk();
-		// ������ � EEPROM
-		// (param[], eprom.writeRequestNumber -> eprom.writeRequestNumber)
-		if ( eprom.writeRequestNumber > 0 ) {
-			write_eeprom();
-		}
-
-		// ��������� ������������ �� ������������ �����
-		control_processor_led();
-	} //while(1)
-} //void main(void)
-
-
-
-// ��������� ������������ �� ������������ �����
-void control_processor_led(void) {
-	static unsigned short Tled = (unsigned short)(0.5/TY);
-	static unsigned short tLed = 0;
-
-	if ( tLed < Tled ) {
-		tLed++;
-	}
-	else {
-		tLed = 1;
-		// � ��������� ���. ������� ������� �����������
-		if ( state == STATE_SHUTDOWN ) {
-			LED_GREEN1_OFF;
-			LED_GREEN2_OFF;
-			LED_RED_TOGGLE;
-		}
-		// � ���. ��������� ������� ������ ������ �����������
-		else if ( state == STATE_STOP ) {
-			LED_GREEN1_TOGGLE;
-			LED_GREEN2_OFF;
-			LED_RED_OFF;
-		}
-		// � ������� ���. ������� ������ ������ �����������
-		else {
-			LED_GREEN1_OFF;
-			LED_GREEN2_TOGGLE;
-			LED_RED_OFF;
-		}
-	}
-} //void control_processor_led(void)
-
-
-
-// �������� ��������� � ��
-// ( -> param[], eprom.writeRequestNumber)
-void talk_with_desk(void) {
-}
-
-
-
-// �������� ������� � ��
-// ( -> mst)
-void talk_with_mst(void) {
-}
-
-
-
-// ���������� ��������� � EEPROM
-// (param[], eprom.writeRequestNumber -> eprom.writeRequestNumber)
-void write_eeprom(void) {
-}
-#endif //ML
diff --git a/Inu/main.h b/Inu/main.h
deleted file mode 100644
index f93fa02..0000000
--- a/Inu/main.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef MAIN
-#define MAIN
-
-// ����������, ������� ���������� � main.c (begin)
-//#########################################################################
-struct Eprom eprom;
-//#########################################################################
-// ����������, ������� ���������� � main.c (end)
-
-
-
-// ����������, ������� ��������� � main.c (begin)
-//#########################################################################
-extern volatile short state;
-//#########################################################################
-// ����������, ������� ��������� � main.c (end)
-#endif //MAIN
diff --git a/Inu/pwm_sim.c b/Inu/pwm_sim.c
new file mode 100644
index 0000000..ecc2b63
--- /dev/null
+++ b/Inu/pwm_sim.c
@@ -0,0 +1,153 @@
+#include "pwm_sim.h"
+#include "xp_write_xpwm_time.h"
+#include "main_matlab.h"
+#include "wrapper_inu.h"
+#include "params_pwm24.h"
+#include "def.h"
+
+TimerSimHandle t1sim;
+TimerSimHandle t2sim;
+TimerSimHandle t3sim;
+TimerSimHandle t4sim;
+TimerSimHandle t5sim;
+TimerSimHandle t6sim;
+TimerSimHandle t7sim;
+TimerSimHandle t8sim;
+TimerSimHandle t9sim;
+TimerSimHandle t10sim;
+TimerSimHandle t11sim;
+TimerSimHandle t12sim;
+
+void Simulate_Timers(void)
+{
+	SimulateMainPWM(&t1sim, xpwm_time.Ta0_0);
+	SimulatePWM(&t2sim, xpwm_time.Ta0_1);
+	SimulatePWM(&t3sim, xpwm_time.Tb0_0);
+	SimulatePWM(&t4sim, xpwm_time.Tb0_1);
+	SimulatePWM(&t5sim, xpwm_time.Tc0_0);
+	SimulatePWM(&t6sim, xpwm_time.Tc0_1);
+	SimulatePWM(&t7sim, xpwm_time.Ta1_0);
+	SimulatePWM(&t8sim, xpwm_time.Ta1_1);
+	SimulatePWM(&t9sim, xpwm_time.Tb1_0);
+	SimulatePWM(&t10sim, xpwm_time.Tb1_1);
+	SimulatePWM(&t11sim, xpwm_time.Tc1_0);
+	SimulatePWM(&t12sim, xpwm_time.Tc1_1);
+}
+
+void Init_Timers(void)
+{
+	initSimulateTim(&t1sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
+	initSimulateTim(&t2sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
+	initSimulateTim(&t3sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
+	initSimulateTim(&t4sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
+	initSimulateTim(&t5sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
+	initSimulateTim(&t6sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
+	initSimulateTim(&t7sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
+	initSimulateTim(&t8sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
+	initSimulateTim(&t9sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
+	initSimulateTim(&t10sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
+	initSimulateTim(&t11sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
+	initSimulateTim(&t12sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
+}
+
+
+
+
+void initSimulateTim(TimerSimHandle* tsim, int period, double step)
+{
+	tsim->dtsim.stateDt = 1;
+	tsim->TPr = period/2;
+	tsim->TxCntPlus = step;
+	tsim->dtsim.DtCntPeriod = (int)(DT / dt);
+}
+
+void SimulateMainPWM(TimerSimHandle* tsim, int compare)
+{
+	if (simulateTimAndGetCompare(tsim, compare))
+		mcu_simulate_step();
+	simulateActionActionQualifierSubmodule(tsim);
+	simulateDeadBendSubmodule(tsim);
+	simulateTripZoneSubmodule(tsim);
+}
+
+void SimulatePWM(TimerSimHandle* tsim, int compare)
+{
+	simulateTimAndGetCompare(tsim, compare);
+	simulateActionActionQualifierSubmodule(tsim);
+	tsim->ciA = tsim->dtsim.ciA_DT;
+	tsim->ciB = tsim->dtsim.ciB_DT;
+	//simulateDeadBendSubmodule(tsim);
+	//simulateTripZoneSubmodule(tsim);
+}
+
+
+int simulateTimAndGetCompare(TimerSimHandle *tsim, int compare)
+{
+	int interruptflag = 0;
+	tsim->tcntAuxPrev = tsim->tcntAux;
+	tsim->tcntAux += tsim->TxCntPlus;
+
+	if (tsim->tcntAux > tsim->TPr) {
+		tsim->tcntAux -= tsim->TPr * 2.;
+		tsim->cmpA = compare;
+		interruptflag = 1;
+	}
+	if ((tsim->tcntAuxPrev < 0) && (tsim->tcntAux >= 0)) {
+		tsim->cmpA = compare;
+		interruptflag = 1;
+	}
+	tsim->tcnt = fabs(tsim->tcntAux);
+	return interruptflag;
+}
+
+
+
+void simulateActionActionQualifierSubmodule(TimerSimHandle* tsim)
+{
+	// ���������� Action-Qualifier Submodule
+	if (tsim->cmpA > tsim->tcnt) {
+		tsim->dtsim.ciA_DT = 0;
+		tsim->dtsim.ciB_DT = 1;
+	}
+	else if (tsim->cmpA < tsim->tcnt) {
+		tsim->dtsim.ciA_DT = 1;
+		tsim->dtsim.ciB_DT = 0;
+	}
+}
+
+void simulateDeadBendSubmodule(TimerSimHandle* tsim)
+{
+	// ���������� Dead-Band Submodule
+	if (tsim->dtsim.stateDt == 1) {
+		tsim->ciA = tsim->dtsim.ciA_DT;
+		tsim->ciB = 0;
+		if (tsim->dtsim.ciA_DT == 1)
+			tsim->dtsim.dtcnt = tsim->dtsim.DtCntPeriod;
+		if (tsim->dtsim.dtcnt > 0)
+			tsim->dtsim.dtcnt--;
+		else
+			tsim->dtsim.stateDt = 2;
+	}
+	else if (tsim->dtsim.stateDt == 2) {
+		tsim->ciA = 0;
+		tsim->ciB = tsim->dtsim.ciB_DT;
+		if (tsim->dtsim.ciB_DT == 1)
+			tsim->dtsim.dtcnt = tsim->dtsim.DtCntPeriod;
+		if (tsim->dtsim.dtcnt > 0)
+			tsim->dtsim.dtcnt--;
+		else
+			tsim->dtsim.stateDt = 1;
+	}
+}
+
+void simulateTripZoneSubmodule(TimerSimHandle* tsim)
+{
+	//// ���������� Trip-Zone Submodule
+	//	// ... clear flag for one-shot trip latch
+	//if (EPwm1Regs.TZCLR.all == 0x0004) {
+	//	EPwm1Regs.TZCLR.all = 0x0000;
+	//	EPwm1Regs.TZFRC.all = 0x0000;
+	//}	// ... forces a one-shot trip event
+	//if (EPwm1Regs.TZFRC.all == 0x0004)
+	//	ci1A_DT = ci1B_DT = 0;
+}
\ No newline at end of file
diff --git a/Inu/pwm_sim.h b/Inu/pwm_sim.h
new file mode 100644
index 0000000..5cb7e28
--- /dev/null
+++ b/Inu/pwm_sim.h
@@ -0,0 +1,60 @@
+#include "DSP281x_Device.h"
+#include "v_pwm24_v2.h"
+
+#ifndef PWM_SIM
+#define PWM_SIM
+
+
+// ��� ������������� Event Manager
+// ... Dead-Band Submodule
+typedef struct
+{
+	int DtCntPeriod;
+	int stateDt;
+	int dtcnt;
+	int ciA_DT;
+	int ciB_DT;
+}DeadBandSimHandle;
+// ... Time-Base Submodule, Counter-Compare Submodule � Event-Trigger Submodule
+typedef struct
+{
+
+	double TxCntPlus;
+	double TPr;
+	double tcntAux;
+	double tcntAuxPrev;
+	double tcnt;
+	double cmpA;
+	double cmpB;
+	int ciA;
+	int ciB;
+	DeadBandSimHandle dtsim;
+}TimerSimHandle;
+
+extern TimerSimHandle t1sim;
+extern TimerSimHandle t2sim;
+extern TimerSimHandle t3sim;
+extern TimerSimHandle t4sim;
+extern TimerSimHandle t5sim;
+extern TimerSimHandle t6sim;
+extern TimerSimHandle t7sim;
+extern TimerSimHandle t8sim;
+extern TimerSimHandle t9sim;
+extern TimerSimHandle t10sim;
+extern TimerSimHandle t11sim;
+extern TimerSimHandle t12sim;
+
+
+
+void Simulate_Timers(void);
+void Init_Timers(void);
+
+
+void initSimulateTim(TimerSimHandle* tsim, int period, double step);
+void SimulateMainPWM(TimerSimHandle* tsim, int compare);
+void SimulatePWM(TimerSimHandle* tsim, int compare);
+int simulateTimAndGetCompare(TimerSimHandle* tsim, int compare);
+void simulateActionActionQualifierSubmodule(TimerSimHandle* tsim);
+void simulateDeadBendSubmodule(TimerSimHandle* tsim);
+void simulateTripZoneSubmodule(TimerSimHandle* tsim);
+#endif //PWM_SIM
diff --git a/Inu/wrapper_inu.h b/Inu/wrapper_inu.h
index 5ee02d5..ff0dcb2 100644
--- a/Inu/wrapper_inu.h
+++ b/Inu/wrapper_inu.h
@@ -21,5 +21,5 @@
 void controller(SimStruct *S, const real_T *u, real_T *xD, real_T *rW,
 				int_T *iW);
 
-
+extern double dt;
 #endif
diff --git a/inu_im_2wnd_3lvl.slx b/inu_im_2wnd_3lvl.slx
index 38a1ae1..a0cb9bd 100644
Binary files a/inu_im_2wnd_3lvl.slx and b/inu_im_2wnd_3lvl.slx differ
diff --git a/run_mex.bat b/run_mex.bat
index fd9494e..fdc23ce 100644
--- a/run_mex.bat
+++ b/run_mex.bat
@@ -21,6 +21,7 @@ set params_i=-I"..\device_support_ml\include"^
 set params_o=-outdir "."
 
 set params_wrapper_c=.\Inu\controller.c^
+ .\Inu\pwm_sim.c^
  .\Inu\Src\main_matlab\init28335.c^
  .\Inu\Src\main_matlab\param.c^
  .\Inu\Src\main_matlab\main_matlab.c^