![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
Diff: SPI.c
- Revision:
- 211:ac8251b067d2
- Parent:
- 209:224e7331a061
- Child:
- 212:8d6784491bae
--- a/SPI.c Mon Apr 24 05:43:54 2017 +0000 +++ b/SPI.c Mon Jul 03 05:50:08 2017 +0000 @@ -18,7 +18,7 @@ unsigned int Temp_ADC_5; unsigned int TempA; unsigned int TempTermLM; - +unsigned int conuntPLS; int ADC5Old,ADCDIF=0; int DACModReg; int SinPls=0,SinMns=0; @@ -28,7 +28,7 @@ unsigned int Buff_ADC_3 [32]; unsigned int Buff_ADC_4 [32]; - +int RegulADC,DeltaRegul; unsigned int Buff_ADC_5 [512]; unsigned int BuffADC_16Point [64]; unsigned int BuffADC_32Point [64]; @@ -44,7 +44,7 @@ unsigned int Buff_AMP [256]; unsigned int Buff_AMP64P [256]; -unsigned int TypeMod=0; +unsigned int TypeMod=2; unsigned int ModArraySin [64] = {50,55,59,64,68,73,77,81,85,88,91,94,96,98,99,99,100,99,99,98,96,94,91,88,85,81,77,73,68,64,59,55,50,45,41,36,32,27,23,19,16,12,9,7,4,2,1,1,0,1,1,2,4,7,9,12,16,19,23,27,32,36,41,45}; unsigned int ModArrayTriangle [64]; unsigned int ModArraySaw [64]; @@ -70,37 +70,52 @@ { switch(TypeMod) { - case 0: LPC_DAC->DACR = (ModArraySin [CountV64]*Gyro.ModAmp); break; + case 0: LPC_DAC->DACR = (ModArraySin [(CountV64-2)&0x3f]*Gyro.ModAmp); break; case 1: LPC_DAC->DACR = (ModArraySaw [CountV64]*Gyro.ModAmp); break; - case 2: LPC_DAC->DACR = (ModArrayTriangle [CountV64]*Gyro.ModAmp); break; + case 2: LPC_DAC->DACR = (ModArrayTriangle [(CountV64-2)&0x3f]*Gyro.ModAmp); break; } } } void PLCRegul(void) { - unsigned int temp; + unsigned int temp, Temp_Dac_B=0,Side=0; static int CountFaza; - + + + // Temp_Dac_B=(0xffff-Spi.DAC_B); + if(conuntPLS<10) + { for (CountFaza = 0; CountFaza <32; CountFaza++ ) SinPls+= BuffADC_64Point[ (CountFaza + Gyro.PLC_Phase) & 0x3f]; for (CountFaza = 32; CountFaza <64; CountFaza++) SinMns+= BuffADC_64Point[ (CountFaza + Gyro.PLC_Phase) & 0x3f]; - Gyro.PLC_Eror = SinMns-SinPls; - - /*sprintf((Time),"%d\r\n",Gyro.PLC_Phase); - WriteCon(Time);*/ - if(Gyro.RgConA&0x8) - { - if(Gyro.PLC_Eror>0) {Spi.DAC_B+=1 * Gyro.PLC_Gain;} - else {Spi.DAC_B-=1 * Gyro.PLC_Gain;} - } - if(Gyro.PLC_Eror>0) {Gyro.PLC_Eror_count++;} - else {Gyro.PLC_Eror_count--;} - - if ( Spi.DAC_B < 10300 ) Spi.DAC_B = 32000; //проверка на переваливание за границу. - else if ( Spi.DAC_B > 57000 ) Spi.DAC_B = 32000; - - SinPls=0; + conuntPLS++; + } + else + { + conuntPLS=0; + Gyro.PLC_Eror = SinMns-SinPls; + if(Gyro.RgConA&0x8) + { + if(Gyro.PLC_Eror>0) {Spi.DAC_B+=Gyro.PLC_Gain;} + else {Spi.DAC_B-=Gyro.PLC_Gain;} + } + if(Gyro.PLC_Eror>0) {Gyro.PLC_Eror_count++;} + else {Gyro.PLC_Eror_count--;} + + if(Gyro.LG_Type==1) + { + if ( Spi.DAC_B < Gyro.HighTreshold ) Spi.DAC_B = (Gyro.ResetLevelHeat); + else if ( Spi.DAC_B > Gyro.DownTreshold ) Spi.DAC_B = (Gyro.ResetLevelCool); + + } + else + { + if ( Spi.DAC_B < 10300 ) Spi.DAC_B = 32000; //проверка на переваливание за границу. + else if ( Spi.DAC_B > 57000 ) Spi.DAC_B = 32000; + } + + SinPls=0; SinMns=0; - + } } @@ -112,7 +127,7 @@ for (CountFaza = 0; CountFaza <32; CountFaza++ ) SinPls+= BuffADC_64Point[ (CountFaza + Gyro.PLC_Phase) & 0x3f]; for (CountFaza = 32; CountFaza <64; CountFaza++) SinMns+= BuffADC_64Point[ (CountFaza + Gyro.PLC_Phase) & 0x3f]; Gyro.PLC_Eror = SinMns-SinPls; - /*sprintf((Time)," %d %d %d\r\n",SinPls, SinMns, Gyro.PLC_Eror); + /* sprintf((Time)," %d %d %d %d %d\r\n",Spi.ADC5, Spi.DAC_B, SinPls, SinMns, Gyro.PLC_Eror); WriteCon(Time);*/ if(Gyro.RgConA&0x8) { @@ -128,7 +143,18 @@ SinPls=0; SinMns=0; } - +void HFORegul(void) +{ + RegulADC=32767-Spi.ADC5; + DeltaRegul=((Gyro.HFO_ref-RegulADC)>>11); + if(Gyro.RgConA&0x2) + { + Spi.DAC_A-=DeltaRegul*Gyro.HFO_Gain; + if(Spi.DAC_A>Gyro.HFO_Min) Spi.DAC_A-=0xfff; + else if(Spi.DAC_A<Gyro.HFO_Max) Spi.DAC_A+=0xfff; + } + +} @@ -145,7 +171,7 @@ Gyro.DeltaT = (unsigned int)(Spi.ADC4>>1); TempA = (0xffff - Spi.ADC5); // перевернем знак и умножим на два (было 32000...0 стало 0 ...32000 /*сдвиг(<<1) стало 0 ...64000*/) - TempTermLM = Spi.ADC1; + Gyro.TermLM = Spi.ADC1; Gyro.ADF_Accum += TempA; Gyro.ADS_Accum += TempA; /// Gyro.ADS_AccumTermLM+=TempTermLM; @@ -157,8 +183,6 @@ if (Gyro.ADM_Count > 255) { Gyro.In1 = Gyro.IN1_Accum>>8; Gyro.In2 = Gyro.IN2_Accum>>8; - /* sprintf((Time),"%d %i %d %d\r\n", Gyro.In1, Gyro.In2, GyroP.Str.DAC_current_Work, Spi.DAC_A ); - WriteCon(Time);*/ Gyro.IN1_Accum=0; Gyro.IN2_Accum=0; Gyro.ADM_Count=0; @@ -172,7 +196,7 @@ } if (Gyro.ADS_Count > 255) { // если прошло 256 тактов виброподвеса Gyro.AD_Slow = Gyro.ADS_Accum << 7; //обновляем данные и приводим в один масштаб - Gyro.TermLM = Gyro.ADS_AccumTermLM << 3; + // Gyro.TermLM = Gyro.ADS_AccumTermLM << 3; Gyro.ADS_Count = 0; Gyro.ADS_Accum = 0; Gyro.ADS_AccumTermLM=0; @@ -244,17 +268,22 @@ } void ShowMod2(void)//технологическая функция для просмотра в ориджине мод на всем диапазпне цап { - unsigned int step = 30, ENDMOD=53000; + if(dispersion>3) + { + unsigned int step = 50, ENDMOD=32767; sprintf((Time),"%d %d %d %d %d %d %d\r\n", Gyro.CuruAngle, Spi.DAC_B, Gyro.AD_Slow, Spi.ADC5, 0xfFFf-Spi.ADC1, Spi.ADC1, Gyro.Termo); Gyro.CuruAngle=0; WriteCon(Time); - Spi.DAC_B+=step; - if(Spi.DAC_B>ENDMOD) - { - Gyro.LogMod=0; - PlcON - Spi.DAC_B = 32000; + Spi.DAC_B-=step; + if(Spi.DAC_B<ENDMOD) + { + Gyro.LogMod=0; + PlcON + Spi.DAC_B = 32000; + } + dispersion=0; } + else dispersion++; } void DAC_OutPut(void)//выдача в цапы {