![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork
Fork of LG by
Diff: SPI.c
- Revision:
- 208:19150d2b528f
- Parent:
- 207:d1ce992f5d17
- Child:
- 209:224e7331a061
--- a/SPI.c Fri Jan 13 08:27:28 2017 +0000 +++ b/SPI.c Tue Feb 07 10:11:35 2017 +0000 @@ -74,48 +74,56 @@ } } void PLCRegul(void) -{ - if (CountV64 == 0) - { - for (int i = 0; i < 32; i++ ) +{ + unsigned int temp; + static int CountFaza; + if(Gyro.RgConA&0x8) + { + for (CountFaza = 0; CountFaza <32; CountFaza++ ) { - SinPls+= BuffADC_64Point[i]; - } - for (int i = 32; i < 64; i++ ) + SinPls+= BuffADC_64Point[ (CountFaza + Gyro.PLC_Phase) & 0x3f]; + } + for (CountFaza = 32; CountFaza <64; CountFaza++) { - SinMns+= BuffADC_64Point[i]; - } - ADCDIF = SinPls - SinMns; - // Spi.DAC_B-=ADCDIF>>6; - - if(ADCDIF>0) Spi.DAC_B-=3; - else Spi.DAC_B+=3; - - if ( Spi.DAC_B < 15300 ) Spi.DAC_B = 32000; //проверка на переваливание за границу. - else if ( Spi.DAC_B > 53000 ) Spi.DAC_B = 32000; -/* sprintf((Time),"%d %d %d %d %d \r\n", SinPls, SinMns, ADCDIF, ADCDIF>>5, Spi.DAC_B);//выдаем в терминал для постройки граффика регулировки периметра. - WriteCon(Time); - */ + SinMns+= BuffADC_64Point[(CountFaza + Gyro.PLC_Phase) & 0x3f]; + } + ADCDIF = SinMns-SinPls; + /*sprintf((Time),"%d\r\n",Gyro.PLC_Phase); + WriteCon(Time);*/ + if(ADCDIF>0) Spi.DAC_B+=1 * Gyro.PLC_Gain; + else Spi.DAC_B-=1 * Gyro.PLC_Gain; + + if ( Spi.DAC_B < 15300 ) Spi.DAC_B = 32000; //проверка на переваливание за границу. + else if ( Spi.DAC_B > 53000 ) Spi.DAC_B = 32000; + SinPls=0; SinMns=0; - } + } } + + + + + +// Spi.DAC_B-=ADCDIF>>6; + void ADS_Acum(void) { Spi.ADC_NewData = 0; - Gyro.Termo = Spi.ADC1; - Gyro.In1 = Spi.ADC2; - Gyro.In2 = Spi.ADC3; - Gyro.DeltaT = Spi.ADC4; - + Gyro.Termo = (unsigned int)(((Spi.ADC1>>1) + Gyro.Tmp_OffsetT4) * Gyro.Tmp_scaleT4); + Gyro.In1 = Spi.ADC2; + Gyro.In2 = Spi.ADC3; + Gyro.DeltaT = (unsigned int)(((Spi.ADC4>>1) + Gyro.Tmp_OffsetT5) * Gyro.Tmp_scaleT5); + + TempA = (0xffff - Spi.ADC5); // перевернем знак и умножим на два (было 32000...0 стало 0 ...32000 /*сдвиг(<<1) стало 0 ...64000*/) TempTermLM = Spi.ADC1; Gyro.ADF_Accum += TempA; Gyro.ADS_Accum += TempA; - Gyro.ADS_AccumTermLM+=TempTermLM; + /// Gyro.ADS_AccumTermLM+=TempTermLM; Gyro.ADF_Count ++; Gyro.ADS_Count ++; @@ -132,6 +140,8 @@ Gyro.ADS_Accum = 0; Gyro.ADS_AccumTermLM=0; Gyro.ADS_NewData = 1; + /* sprintf((Time),"%d\r\n",Spi.ADC5); + WriteCon(Time);*/ //srand(Gyro.AD_Slow); } } @@ -174,7 +184,7 @@ BuffADC_64Point[CountV64]=ADC5New; Buff_ADC_5[CountV255] = (0x7fff-ADC5New)<<2; - PLCRegul(); + /* PulseADC_16Point += Buff_ADC_5[CountV255]; @@ -486,7 +496,7 @@ void DAC_OutPut(void)//выдача в цапы { - Modulator(); + if(Gyro.RgConA&0x10) Modulator(); LPC_SSP0->DR=0x5555; LPC_SSP0->DR=0x5555; LPC_SSP0->DR=0x5555; @@ -497,7 +507,7 @@ } else { //если такт четный. LPC_SSP0->DR = WRITE_DAC1 ; //e.команда для ЦАП_1 передавать. LPC_SSP0->DR = (Spi.DAC_B); - temp9 = Spi.DAC_B;//для вывода. + // t//emp9 = Spi.DAC_B;//для вывода. /* switch( Gyro.StrayPLC_flag) {