fork

Dependencies:   mbed

Fork of LG by igor Apu

Revision:
1:f2adcae3d304
Parent:
0:8ad47e2b6f00
Child:
21:bc8c1cec3da6
--- a/PLC_reg.c	Sat Jan 30 13:00:39 2016 +0000
+++ b/PLC_reg.c	Sat Jan 30 13:53:19 2016 +0000
@@ -13,33 +13,30 @@
 **
 **--------------------------------------------------------------------------------------------------------       
 *********************************************************************************************************/
-#include "mathDSP.h"
-#include "CyclesSync.h"
-#include "ThermoCalc.h"
-#include "CntrlGLD.h"
-#include "InputOutput.h"
-#include <math.h>
+#include "Global.h"
+
 
-#define CONFIG_HFO_REG	//r. èçìåíÿåì êîýôôèöèåíò ïåðåäà÷è êîíòóðà ÃÂ× îò íîìèíàëüíîãî íà âðåìÿ îáíóëåíèÿ
+
+#define CONFIG_HFO_REG	//r. �������� ����������� �������� ������� ��� �� ������������ �� ����� ���������
 #define WP_TRANSITION_ENA //
  
-	//e.--- constants for the CPLC regulator ------------------------------------------------------- //r.--- êîíñòàíòû äëÿ êîíòóðà ÑÐÏ -------------------------------------------------------
+	//e.--- constants for the CPLC regulator ------------------------------------------------------- //r.--- ��������� ��� ������� ��� -------------------------------------------------------
 
 #define  PLC_SHIFT				(6) 	
-#define	 PLC_PHASE_DET_SHIFT	(18)	//e. 18 - for analog output //r. 18 - äëÿ àíàëîãîâîãî 
+#define	 PLC_PHASE_DET_SHIFT	(18)	//e. 18 - for analog output //r. 18 - ��� ����������� 
 
-#define  PLC_RESET_THRESHOLD 	(-3276) //e. correspond to the voltage +1.2 Volts //r. ñîîòâåòñòâóåò íàïðÿæåíèþ +1.2 âîëüòà
+#define  PLC_RESET_THRESHOLD 	(-3276) //e. correspond to the voltage +1.2 Volts //r. ������������� ���������� +1.2 ������
 #define	 WP_REG32MAX_SATURATION (32767 << PLC_SHIFT)
 #define	 WP_REG32MIN_NEW_SATURATION (PLC_RESET_THRESHOLD << PLC_SHIFT)
-#define  WP_TMP_THRESHOLD		(7) //e. temperature threshold, defining heats up or cool down the device //r. òåìïåðàòóðíûé ïîðîã, îïðåäåëÿþùèé íàãðåâàåòñÿ èëè îõëàæäàåòñÿ ïðèáîð
+#define  WP_TMP_THRESHOLD		(7) //e. temperature threshold, defining heats up or cool down the device //r. ������������� �����, ������������ ����������� ��� ����������� ������
 
 
 #define debugPLC
 
 	   int WP_reg32;
-	   int WP_Phase_Det; 		//e. output of the phase detector of the CPLC (in a digital kind)//r. âûõîä ôàçîâîãî äåòåêòîðà ÑÐÏ (â öèôðîâîì âèäå)
-	   int WP_reset_heating;	//e. voltage of reset at heating //r. íàïðÿæåíèå ñáðîñà ïðè íàãðåâàíèè
-	   int WP_reset_cooling;	//e. voltage of reset at cooling //r. íàïðÿæåíèå ñáðîñà ïðè îõëàæäåíèè
+	   int WP_Phase_Det; 		//e. output of the phase detector of the CPLC (in a digital kind)//r. ����� �������� ��������� ��� (� �������� ����)
+	   int WP_reset_heating;	//e. voltage of reset at heating //r. ���������� ������ ��� ����������
+	   int WP_reset_cooling;	//e. voltage of reset at cooling //r. ���������� ������ ��� ����������
 	   int MaxDelayPLC;
  	   int sin_func[100];
 
@@ -59,38 +56,38 @@
 void init_PLC(void)
 {
 	int i;
-	                           //( 1,2 âîëüòà)
-	if (Device_blk.Str.WP_reset < PLC_RESET_THRESHOLD) //e. íàïðÿæåíèå ïîñëå ñáðîñà íà íàãðåâàòåëå íå äîëæíî ïðåâûøàòü 1,2 âîëüòà. 
-		//(èñõîäíîå çíà÷åíèå ðåãóëÿòîðà ÑÐÏ (ïîñëå ñáðîñà)) < (-3276).
+	                           //( 1,2 ������)
+	if (Device_blk.Str.WP_reset < PLC_RESET_THRESHOLD) //e. ���������� ����� ������ �� ����������� �� ������ ��������� 1,2 ������. 
+		//(�������� �������� ���������� ��� (����� ������)) < (-3276).
 	{
 		Device_blk.Str.WP_reset = PLC_RESET_THRESHOLD + 1;//(-3275)
 	}
-//íàïðÿæåíèå íà ÑÐÏ =  (ìèí. çíà÷åíèå íà íàãðåâàòåëå + ìàõ. çíà÷åíèå íà íàãðåâàòåëå)/2
+//���������� �� ��� =  (���. �������� �� ����������� + ���. �������� �� �����������)/2
 	Output.Str.WP_reg = (Device_blk.Str.WP_rup + Device_blk.Str.WP_rdw) >> 1; //e. WP_reg start voltage is (WP_rup - WP_rdw)/2	
 
-	//        íàïðÿæåíèå íà ÑÐÏ <<   6 
+	//        ���������� �� ��� <<   6 
 	WP_reg32 = Output.Str.WP_reg<<PLC_SHIFT;
 		   
- 	if ((Device_blk.Str.PI_b3>100)||(Device_blk.Str.PI_b3<10))	//e. Åñëè òðåáóåìàÿ ÷àñòîòà ìîäóëÿòîðà ÑÐÏ áîëüøå 1kHz èëè ìåíüøå 100Hz
-	      Device_blk.Str.PI_b3 = 40;			                			//e. Óñòàíîâèòü ÷àñòîòó â 250Hz (÷àñòîòà äðåáåçäåíèÿ) 
+ 	if ((Device_blk.Str.PI_b3>100)||(Device_blk.Str.PI_b3<10))	//e. ���� ��������� ������� ���������� ��� ������ 1kHz ��� ������ 100Hz
+	      Device_blk.Str.PI_b3 = 40;			                			//e. ���������� ������� � 250Hz (������� �����������) 
   
-  for (i = 0; i<Device_blk.Str.PI_b3; i++)			   //e. Ñêàíèðîâàíèå ÑÐÏ ñèãíàëà
+  for (i = 0; i<Device_blk.Str.PI_b3; i++)			   //e. ������������ ��� �������
    {
-     float temp = sin((float)i*2.0*PI/(float)Device_blk.Str.PI_b3); /// âû÷èñëåíèå çíà÷åíèé ñèíóñà
-                                                                    /// äëÿ ÷àñòîòû ìîäóëÿòîðà ñðï (PI_b3),
-     sin_func[i] = (int)(temp*32767);                               /// è êàëèáðîâêà ýòèõ çíà÷åíèé äëÿ ÀÖÏ.
+     float temp = sin((float)i*2.0*PI/(float)Device_blk.Str.PI_b3); /// ���������� �������� ������
+                                                                    /// ��� ������� ���������� ��� (PI_b3),
+     sin_func[i] = (int)(temp*32767);                               /// � ���������� ���� �������� ��� ���.
       if (sin_func[i] < 0)
        sin_func[i] += 65536;  
     }
 	 
       //e. calculation of filter coefficients for PLC		            
 //                                250 Hz                                	10 KHz
-		init_BandPass( 1.0/(float)Device_blk.Str.PI_b3, 10.0/(float)(DEVICE_SAMPLE_RATE_HZ), PLC);	//ïîëîñîôîé ôèëüòð äëÿ âûäåëåíèÿ ÷àñòîòû êîëåáàíèÿ ìîäóëÿòîðà
-		                                                                                            //è îïðåäåëåíèå êîýôèöèåíòîâ(aPLC[0-2] è bPLC[0-2]) 
-		                                                                                            //(äðåáåçäåíèå ñðï äëÿ îïðåäåëåíèÿ ãðåòü èëè îõëîæäàòü îñíîâíîé ýëåìåíò óïðàâëåíèÿ.)
+		init_BandPass( 1.0/(float)Device_blk.Str.PI_b3, 10.0/(float)(DEVICE_SAMPLE_RATE_HZ), PLC);	//��������� ������ ��� ��������� ������� ��������� ����������
+		                                                                                            //� ����������� ������������(aPLC[0-2] � bPLC[0-2]) 
+		                                                                                            //(����������� ��� ��� ����������� ����� ��� ��������� �������� ������� ����������.)
 
 	Device_blk.Str.WP_scl <<=  1; //e. during fist 10 seconds after start we state	Device_blk.Str.WP_scl = 2*Device_blk.Str.WP_scl
-                                // ïåðâûå 10 ñåêóíä ðàáîòàòü ñ êîýôèöèåíòîì ïåðåäà÷è * 2
+                                // ������ 10 ������ �������� � ������������ �������� * 2
 		
 	MaxDelayPLC = Device_blk.Str.PI_b3>>1;	//e. max expected delay for phase detector output
 } // init_PLC
@@ -113,10 +110,10 @@
 		return (flag);
 	}
 	
-	//e. check whether delay exceeds the greatest possible value //r. ïðîâåðêà íå ïðåâîñõîäèò ëè çàäåðæêà ìàêñèìàëüíî âîçìîæíóþ
+	//e. check whether delay exceeds the greatest possible value //r. �������� �� ����������� �� �������� ����������� ���������
 	if (Device_blk.Str.WP_ref > MaxDelayPLC) { Device_blk.Str.WP_ref = MaxDelayPLC; }
 	
-	if (flag) //e. outgoing poz_sin_flag flag, which delayed by the WP_ref //r. ôîðìèðîâàíèå çàäåðæàííîãî íà âåëè÷èíó WP_ref ôëàãà poz_sin_flag
+	if (flag) //e. outgoing poz_sin_flag flag, which delayed by the WP_ref //r. ������������ ������������ �� �������� WP_ref ����� poz_sin_flag
 	{
   		neg_counter = 0;
   		poz_counter++;
@@ -151,10 +148,10 @@
 			
 	static int plc_reset32;
 	static enum 
-	{		//r. ñîñòîÿíèå ëèíåéíîãî ïåðåõîäà ïðè îáíóëåíèè ÑÐÏ
-		FINISHED, 		  //r. ëèíåéíûé ïåðåõîä çàâåðøåí
-	  TRANS_HEATING,  //r. ïåðåõîä âûïîëíÿåòñÿ ïðè íàãðåâàíèè
-		TRANS_COOLING	  //r. ïåðåõîä âûïîëíÿåòñÿ ïðè îõëàæäåíèè
+	{		//r. ��������� ��������� �������� ��� ��������� ���
+		FINISHED, 		  //r. �������� ������� ��������
+	  TRANS_HEATING,  //r. ������� ����������� ��� ����������
+		TRANS_COOLING	  //r. ������� ����������� ��� ����������
 	} plc_transiton = FINISHED; 
 
 //	int i;
@@ -168,7 +165,7 @@
 		         poz_sin_flag = 1;
            }
 
-					 //r. ïîëîñîâîé ôèëüòð äëÿ êîíòóðà ÑÐÏ
+					 //r. ��������� ������ ��� ������� ���
 	WP_Phase_Det = PLC_PhaseDetFilt(/*Output.Str.WP_sin*/Input.StrIn.WP_sel);
 
 	
@@ -191,34 +188,34 @@
 	}  
 	// from this WP_Phase_Det - demodulated signal like LIDEM_DIG
   
-	if (!is_zeroing)  //r. Íå ïîðà âûïîëíÿòü îáíóëåíèå
-	{				//r. íåò îáíóëåíèÿ
-			if ((WP_reg32 > (Device_blk.Str.WP_rup << PLC_SHIFT)) && IsHeating) //r. ïðîèñõîäèò íàãðåâàíèå
+	if (!is_zeroing)  //r. �� ���� ��������� ���������
+	{				//r. ��� ���������
+			if ((WP_reg32 > (Device_blk.Str.WP_rup << PLC_SHIFT)) && IsHeating) //r. ���������� ����������
 			{
 	  			is_zeroing = 1;
-				 //r. íàïðÿæåíèå ñáðîñà ïðè íàãðåâàíèè
+				 //r. ���������� ������ ��� ����������
 				WP_reset_heating = CPL_reset_calc(Device_blk.Str.WP_reset, Device_blk.Str.K_WP_rst_heating, Temp_Aver, Device_blk.Str.TemperNormal);
   			plc_transiton = TRANS_HEATING;
   			plc_reset32 = WP_reset_heating << PLC_SHIFT;;
 
-				Device_blk.Str.HF_scl = Device_blk.Str.HF_scl_2; //r. èçìåíÿåì êîýôôèöèåíò ïåðåäà÷è êîíòóðà ÃÂ× îò íîìèíàëüíîãî íà âðåìÿ îáíóëåíèÿ	
+				Device_blk.Str.HF_scl = Device_blk.Str.HF_scl_2; //r. �������� ����������� �������� ������� ��� �� ������������ �� ����� ���������	
 	  	} 			
-  			else if ((WP_reg32 < (Device_blk.Str.WP_rdw << PLC_SHIFT)) && !IsHeating)	//r. îõëàæäåíèå
+  			else if ((WP_reg32 < (Device_blk.Str.WP_rdw << PLC_SHIFT)) && !IsHeating)	//r. ����������
 			{
 	  		is_zeroing = 1;
-				//r. íàïðÿæåíèå ñáðîñà ïðè îõëàæäåíèè
+				//r. ���������� ������ ��� ����������
 				WP_reset_cooling = CPL_reset_calc(Device_blk.Str.WP_reset2, Device_blk.Str.K_WP_rst_cooling, Temp_Aver, Device_blk.Str.TemperNormal);
 
 	  		plc_transiton = TRANS_COOLING;
 	  		plc_reset32 = WP_reset_cooling << PLC_SHIFT;
 
-  			Device_blk.Str.HF_scl = Device_blk.Str.HF_scl_2; //r. èçìåíÿåì êîýôôèöèåíò ïåðåäà÷è êîíòóðà ÃÂ× îò íîìèíàëüíîãî íà âðåìÿ îáíóëåíèÿ
+  			Device_blk.Str.HF_scl = Device_blk.Str.HF_scl_2; //r. �������� ����������� �������� ������� ��� �� ������������ �� ����� ���������
 			}
-			else  //r. ïîðîãè íå ïðåâûøåíû, îáû÷íàÿ ðàáîòà êîíòóðà
+			else  //r. ������ �� ���������, ������� ������ �������
 				WP_reg32 = L_mac(WP_reg32, phase_Digital, Device_blk.Str.WP_scl ); // WP_reg32 += phase_Digital * Device_blk.Str.WP_scl;
 
 	}
-	else  //r. ôëàã óñòàíîâëåí (1) - ðåæèì îáíóëåíèÿ
+	else  //r. ���� ���������� (1) - ����� ���������
 	{ 
 
 		if (plc_transiton != FINISHED)
@@ -251,32 +248,32 @@
   		{
   			zero_delay++;
   		}
-  		else //e. resetting was completed //r. îáíóëåíèå çàêîí÷èëîñü
+  		else //e. resetting was completed //r. ��������� �����������
   		{
   			is_zeroing = 0;
-  			//e. save the temperature for further comparison //r. çàïîìèíàåì òåìïåðàòóðó äëÿ äàëüíåéøåãî ñðàâíåíèÿ
+  			//e. save the temperature for further comparison //r. ���������� ����������� ��� ����������� ���������
 		//	TempOfReset = Temp_Aver; //r.x. Temp5_Aver; //r. Tmp_Out[TSENS_NUMB]; // T4;
-			//r.x	Zero_Numb_dbg++; // òàê ìîæíî ïîäñ÷èòûâàòü ÷èñëî îáíóëåíèé
+			//r.x	Zero_Numb_dbg++; // ��� ����� ������������ ����� ���������
 
-		//	DithFreqRangeCalc(); //e. calculation of range of the division factor for the dither drive frequency, depending on current temperature //r. ðàñ÷åò ãðàíèö êîýôôèöèåíòà äåëåíèÿ äëÿ ÷àñòîòû âèáðîïðèâîäà, çàâèñÿùèõ îò òåêóùåé òåìïåðàòóðû
+		//	DithFreqRangeCalc(); //e. calculation of range of the division factor for the dither drive frequency, depending on current temperature //r. ������ ������ ������������ ������� ��� ������� ������������, ��������� �� ������� �����������
   		}
 	}
 
-		Saturation(WP_reg32, WP_REG32MAX_SATURATION, WP_REG32MIN_NEW_SATURATION); //e. the minimum corresponds to a small negative number, appropriate to PLC_RESET_THRESHOLD //r. ìèíèìóì ñîîòâåòñòâóåò íåáîëüøîìó îòðèöàòåëüíîìó ÷èñëó, ñîîòâ-ìó PLC_RESET_THRESHOLD
+		Saturation(WP_reg32, WP_REG32MAX_SATURATION, WP_REG32MIN_NEW_SATURATION); //e. the minimum corresponds to a small negative number, appropriate to PLC_RESET_THRESHOLD //r. ������� ������������� ���������� �������������� �����, �����-�� PLC_RESET_THRESHOLD
 
 	
-	if ( loop_is_closed(WP_REG_ON) )	//e. the regulator loop is closed //r. êîíòóð çàìêíóò
+	if ( loop_is_closed(WP_REG_ON) )	//e. the regulator loop is closed //r. ������ �������
 	{
-		Output.Str.WP_reg = (int)(WP_reg32 >> PLC_SHIFT); //e. we use as controlling - voltages of the integrator //r. èñïîëüçóåì êàê óïðàâëÿþùåå - íàïðÿæåíèÿ èíòåãðàòîðà
+		Output.Str.WP_reg = (int)(WP_reg32 >> PLC_SHIFT); //e. we use as controlling - voltages of the integrator //r. ���������� ��� ����������� - ���������� �����������
 
 	}
-	else 					//e. the regulator loop is open //r. êîíòóð ðàçîìêíóò
+	else 					//e. the regulator loop is open //r. ������ ���������
 	{
-		WP_reg32 = Output.Str.WP_reg << PLC_SHIFT; 	//e. set the previous value of the WP_reg  //r. ïðèñâàèâàåì ïðåäûäóùåå çíà÷åíèå WP_reg 
+		WP_reg32 = Output.Str.WP_reg << PLC_SHIFT; 	//e. set the previous value of the WP_reg  //r. ����������� ���������� �������� WP_reg 
 
 	}
 
-	//e. integartion of output of the PD of the CPLC regulator for the technological output on the Rate command //r. èíòåãðèðîâàíèå âûõîäà ÔÄ êîíòóðà ÑÐÏ äëÿ òåõíîëîãè÷åñêîãî âûâîäà ïî êîìàíäå Rate
+	//e. integartion of output of the PD of the CPLC regulator for the technological output on the Rate command //r. �������������� ������ �� ������� ��� ��� ���������������� ������ �� ������� Rate
 
 	Output.Str.WP_pll = WP_PhaseDetectorRate( WP_Phase_Det, time_1_Sec); 
 	
@@ -291,7 +288,7 @@
 ** Returned value:	code to DAC	
 ** 
 ******************************************************************************/
-int Signal_2_Oscill() //e. the signal for the control by scope on DAC output  (was DS) //r. ñèãíàë äëÿ êîíòðîëÿ îñöèëëîãðàôîì íà âûõîäå ÖÀÏ (áûâøèé ÄÓÏ)
+int Signal_2_Oscill() //e. the signal for the control by scope on DAC output  (was DS) //r. ������ ��� �������� ������������� �� ������ ��� (������ ���)
 {
 	// Scope_Mode var not used now, reserved for future applications
 	return (-WP_Phase_Det << 2);