forkd

Dependencies:   mbed

Fork of LGstaandart by Dmitry Kovalev

Revision:
227:2774b56bfab0
Parent:
226:4a4d5bd5fcd7
Child:
228:a8195e1b1123
--- a/SPI.c	Tue Dec 26 05:14:09 2017 +0000
+++ b/SPI.c	Fri Jan 05 08:14:38 2018 +0000
@@ -14,6 +14,9 @@
 int start=10;
 int dispersion=0,side=1,tempstrafe=15000;
 int ADC_5_T;
+int PLC_ERR_DAC,PLC_ERR_DAC_F;
+
+
 unsigned int TempA;
 unsigned int TempTermLM;
 unsigned int conuntPLS;
@@ -32,7 +35,7 @@
 int Buff_OUT1	[64];
 int Buff_OUT	[64];
 int RegulADC,DeltaRegul,tempDeltaRegul;
-int count10HFO=0, count10v=0, AmpWorms,MinWorms,MaxWorms,AMPSUM,AMPSUMP,AMPSUMM,AMPSUM_DESP,AMPSUMPout,AMPSUMMout,AMPSUMout,SumDelta,PLC_EROR,PLC_Flag,HFO_Flag,HFOdelta,HFOregul,HFOSumDelta;
+int count10HFO=0, count10v=0, AmpWorms,MinWorms,MaxWorms,AMPSUM,AMPSUMP,AMPSUMM,AMPSUMPout,AMPSUMMout,AMPSUMout,SumDelta,PLC_EROR,PLC_Flag,HFO_Flag,HFOdelta,HFOregul,HFOSumDelta;
 
 
 //int BuffADC_32Point	[64];		
@@ -57,7 +60,7 @@
 unsigned int ModArraySaw	  [64];
 unsigned int Mod=0;     
 int znak;                                              
-
+unsigned int HFO_AVR;
 void InitMOD(void)
 {
     for (int i = 0; i < 64; i++ ) 
@@ -125,13 +128,14 @@
 {
     Spi.ADC_NewData = 0;
    // Gyro.Termo 	= (unsigned int)(((Spi.ADC1>>1) +  Gyro.Tmp_OffsetT4) *  Gyro.Tmp_scaleT4);
-    Gyro.Termo 	= (unsigned int)(Spi.ADC1>>1);
+    Gyro.Termo 	= (unsigned int)((((Spi.ADC1>>1)*100)*0.0122)-27300);
+    //Gyro.Termo 	= 
     Gyro.IN1_Accum	+=  Spi.ADC2;
     Gyro.IN2_Accum	+=  Spi.ADC3;
    // Gyro.DeltaT = (unsigned int)(((Spi.ADC4>>1) +  Gyro.Tmp_OffsetT5) *  Gyro.Tmp_scaleT5);
     switch(Gyro.LG_Type) 
     {
-     	case 1:  	Gyro.DeltaT = (unsigned int)(Spi.ADC2>>1); break;
+     	case 1:  	Gyro.DeltaT = (unsigned int)((((Spi.ADC2>>1)*100)*0.0122)-27300); break;
      	
      	case 0:     Gyro.DeltaT = (unsigned int)(Spi.ADC4>>1); break;
 	}
@@ -172,31 +176,21 @@
 
 void HFOFilt(void)
 {
-	      if (count10HFO>=64*8)
- 		 	 {
- 		  		count10HFO=0;
- 		  		for(int q=0; q<64; q++)
-      	    	{
-      	    	 	AMPSUM+=BuffADC_10v[q];
-      	    	}
-      	    AMPSUM=AMPSUM>>6;
-          	AMPSUM=AMPSUM>>3; 
-        	//AMPSUM=AMPSUM>>3;
-        
-           	AMPSUM_DESP=AMPSUM;
-           	HFOdelta=(int)((Gyro.HFO_ref)-AMPSUM);
-           	
-           	
+
+	      
+	       /* HFO_AVR+=(BuffADC_10v[CountV64]>>4);
+	        HFO_AVR-=(BuffADC_10v[CountV64 - 32]>>4);
+	        */  
+ 		    HFOdelta=(int)((Gyro.HFO_ref)-(BuffADC_128Point[CountV64]>>7));	  	       
+
            	HFOSumDelta+=HFOdelta;
            	HFOregul=HFOSumDelta/(int)(Gyro.HFO_Gain);
-           	
+
            	HFOSumDelta-=Gyro.HFO_Gain*HFOregul;
-           	
-	     //   tempDeltaRegul = HFOregul;
 	        tempDeltaRegul += HFOregul;
 	        AMPSUM=0;
 	        HFO_Flag=1;
- 		  }
+ 		 
 }
 
 void PLCFilt(void)
@@ -205,7 +199,8 @@
 	     
          if (count10v>=64*32)
  		  {
- 		 
+ 		    C_PLC_F++;
+	        C_PLC_F = C_PLC_F & 0xf;
  	        count10v=0;
         
  	        for(int q=0; q<32; q++)
@@ -227,7 +222,7 @@
        	               
     	    for(int q=0; q<64; q++)
       	    	{
-      	    	 //	AMPSUM+=BuffADC_10v[q];
+      	    	 	AMPSUM+=BuffADC_10v[q];
       	    	 	AMPSUMout+=BuffADC_10v_F[q];   	    	 	
 	       	 		BuffADC_10v_OLD[q]= BuffADC_10v[q];
     	   		 	BuffADC_10v[q] =0;				
@@ -239,7 +234,11 @@
            		
             /*sprintf((Time),"%d  \r\n",  Spi.DAC_A);
             WriteCon(Time);*/
-          	   
+     
+      	    AMPSUM=AMPSUM>>6;
+          	AMPSUM=AMPSUM>>3; 
+        	AMPSUM=AMPSUM>>3;  
+        	 
        	    AMPSUMPout=AMPSUMP>>1;
        	    AMPSUMMout=AMPSUMM>>1;
        	    AMPSUMout=AMPSUM;
@@ -255,6 +254,13 @@
           	
           	PLC_EROR+=Gyro.PLC_Eror_count;
           	
+          	BuffPLC_FILT[C_PLC_F] = Gyro.PLC_Eror_count;
+          	if(Time1Hz>10)
+          	{
+          	PLC_ERR_DAC_F += BuffPLC_FILT[C_PLC_F];
+          	PLC_ERR_DAC_F -= BuffPLC_FILT[(C_PLC_F-8)&0xf];
+          	}
+          	PLC_ERR_DAC = PLC_ERR_DAC_F>>3;
             PLC_Flag=1;
     	 	AMPSUMM=0;
     	 	AMPSUMP=0;
@@ -315,9 +321,9 @@
         BuffADC_1Point[CountV255] = (0x7fff-ADC5New)&0x7fff;
         BuffADC_1Point_64[CountV31]=(0x7fff-ADC5New)&0x7fff;
 
-       /* ADC_128Point += BuffADC_1Point[CountV255];
+        ADC_128Point += BuffADC_1Point[CountV255];
         ADC_128Point -= BuffADC_1Point[(CountV255 - 128) & 0xff];						// заполнение буфера накопленых приращений за 64 тактов
-        BuffADC_128Point[CountV64] = ADC_128Point;*/
+        BuffADC_128Point[CountV64] = ADC_128Point;
 
 		
      //   Buff_Restored_Mod[CountV31] =(int)(BuffADC_1Point_64[CountV31] - ((BuffADC_128Point[CountV64])>>7));       
@@ -372,30 +378,35 @@
 	  	  	 	{
 
 	  	  	 	}
-	  	  	 	else Spi.DAC_B+=(Gyro.PLC_Eror_count); 	  		
+	  	  	 	else 
+	  	  	 	{
+	  	  	 	/*		 if(Gyro.PLC_Eror_count>600)	Gyro.PLC_Eror_count=0;
+	  	  	 		else if(Gyro.PLC_Eror_count<(-600)) Gyro.PLC_Eror_count=0;*/
+
+	  	  	 		Spi.DAC_B+=PLC_ERR_DAC; 	
+	  	  	 		 
+	  	  	 	}  		
 			}
-   		 }   
-   		Gyro.PLC_Eror_count=0;  		 	
-  if(Gyro.LG_Type==1)
- 	{
-   		if(Spi.DAC_B > Gyro.HighTreshold ) 
-   		{
+		if(Spi.DAC_B > Gyro.HighTreshold ) 
+   			{
    			Spi.DAC_B = (Gyro.ResetLevelCool);  
    			Gyro.PLCDelay			= GyroP.Str.PLCDelay; 
-   		}     
-   else if(Spi.DAC_B < Gyro.DownTreshold ) 
-    	{
+   			}     
+   		else if(Spi.DAC_B < Gyro.DownTreshold ) 
+    		{
     		Spi.DAC_B = (Gyro.ResetLevelHeat);
     		Gyro.PLCDelay			= GyroP.Str.PLCDelay; 
-    	}
-    }
-  else
-    {
-    	if      ( Spi.DAC_B < 10300 )	Spi.DAC_B = 32000;            //проверка на переваливание за границу.  
-      	else if ( Spi.DAC_B > 57000 )	Spi.DAC_B = 32000;
-    } 
+    		}
+   		 }   
+   	 		 	
+ 
+   		
+   
     if(PLC_Flag)
 	{  
+	  	  	 		/*sprintf((Time),"%d                 %d        %d\r\n", PLC_ERR_DAC, Spi.DAC_B, Spi.DAC_A);
+      				WriteCon(Time);*/
+    PLC_ERR_DAC=0;
     PLC_Flag=0; 
     }   
 }