![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LGstaandart by
Diff: SPI.c
- Revision:
- 218:b4067cac75c0
- Parent:
- 217:15cd8752bb6c
- Child:
- 220:04c54405b82d
--- a/SPI.c Mon Sep 04 12:55:13 2017 +0000 +++ b/SPI.c Mon Sep 25 10:35:56 2017 +0000 @@ -48,8 +48,9 @@ //unsigned int Buff_AMP [256]; //unsigned int Buff_AMP64P [256]; -unsigned int TypeMod=0; +unsigned int TypeMod=4; 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 ModArraySin32 [32] = {50,59,68,77,85,91,96,99,100,99,96,91,85,77,68,59,50,41,32,23,16,9,4,1,0,1,4,9,16,23,32,41}; unsigned int ModArrayTriangle [64]; unsigned int ModArraySaw [64]; unsigned int Mod=0; @@ -73,11 +74,12 @@ { switch(TypeMod) { - case 0: LPC_DAC->DACR = (ModArraySin [(CountV64-Gyro.PLC_Gain)&0x3f]*Gyro.ModAmp); break; + case 0: LPC_DAC->DACR = (ModArraySin [(CountV64)&0x3f]*Gyro.ModAmp); break; case 1: LPC_DAC->DACR = (ModArraySaw [CountV64]*Gyro.ModAmp); break; case 2: LPC_DAC->DACR = (ModArrayTriangle [(CountV64-2)&0x3f]*Gyro.ModAmp); break; case 3: LPC_DAC->DACR = (ModArrayTriangle [(CountV64-2)&0x3f]*Gyro.ModAmp); break; - case 4: break; + case 4: LPC_DAC->DACR = ((ModArraySin32 [(CountV31)&0x1f]+150)*Gyro.ModAmp); break; + case 5: break; } } void PLCRegul(void) @@ -86,46 +88,34 @@ static unsigned int Flag_64=0, count; static int CountFaza,Sin; - for (CountFaza = 0; CountFaza <64; CountFaza++) + for (CountFaza = 0; CountFaza <32; CountFaza++) { - Sin=(ModArraySin[CountFaza] - 50); + Sin=(ModArraySin32[CountFaza] - 50); if(Sin < 0) znak = -1; else znak = 1; BuffADC_znak[CountFaza] = znak; } - if(Flag_64) - { - for (CountFaza = 0; CountFaza <32; CountFaza++) + + for (CountFaza = 0; CountFaza <16; CountFaza++) { - SinPls+= ((Buff_Restored_Mod[(CountFaza - Gyro.PLC_Phase) & 0x3f])*BuffADC_znak[CountFaza]); + SinPls+= ((Buff_Restored_Mod[(CountFaza - Gyro.PLC_Phase) & 0x1f])*BuffADC_znak[CountFaza]); } - for (CountFaza = 32; CountFaza <64; CountFaza++) + for (CountFaza = 16; CountFaza <32; CountFaza++) { - SinMns-= ((Buff_Restored_Mod[(CountFaza - Gyro.PLC_Phase) & 0x3f])*BuffADC_znak[CountFaza]); - } - - + SinMns-= ((Buff_Restored_Mod[(CountFaza - Gyro.PLC_Phase) & 0x1f])*BuffADC_znak[CountFaza]); + } if(count>128) { count=0; Gyro.PLC_Eror_count = (SinMns+SinPls)>>7; - /*sprintf((Time)," %d %d %d %d \r\n",SinPls>>7,(SinMns>>7), Gyro.PLC_Eror_count,Gyro.PLC_Phase); - WriteCon(Time);*/ SinPls=0; SinMns=0; - if(Gyro.RgConA&0x8) - { - Spi.DAC_B-=Gyro.PLC_Eror_count>>1; - } + if(Gyro.RgConA&0x8) + { + if( DeltaRegul<8) Spi.DAC_B+=(Gyro.PLC_Eror_count>>3)*Gyro.PLC_Gain; + } } else count++; - - Flag_64=0; - } - else Flag_64++; - - - if(Gyro.LG_Type==1) { @@ -173,24 +163,35 @@ void HFORegul(void) { static unsigned int countHFO; - if(countHFO<128) + if(countHFO<32) { RegulADC=(32767-Spi.ADC5); DeltaRegul+=((Gyro.HFO_ref-RegulADC)); countHFO++; } - else + else { countHFO=0; if(Gyro.RgConA&0x2) { - DeltaRegul=DeltaRegul>>17; + DeltaRegul=DeltaRegul>>14; + tempDeltaRegul=DeltaRegul; + + + switch(DeltaRegul) { + case 1: DeltaRegul=0; break; + case 2: DeltaRegul=0; break; + case 3: DeltaRegul=0; break; + //case 4: DeltaRegul=0; break; + case -1: DeltaRegul=0; break; + case -2: DeltaRegul=0; break; + case -3: DeltaRegul=0; break; + //case -4: DeltaRegul=0; break; + } + /*sprintf((Time)," %d %d \r\n",DeltaRegul,tempDeltaRegul); + WriteCon(Time);*/ - sprintf((Time)," %d %d \r\n",DeltaRegul,DeltaRegul>>16); - WriteCon(Time); - - tempDeltaRegul=DeltaRegul>>16; Spi.DAC_A-=DeltaRegul*Gyro.HFO_Gain; timer=10; } @@ -283,7 +284,7 @@ if(Time1Hz>6) { BuffADC_1Point[CountV255] =(0x7fff-ADC5New)&0x7fff; - BuffADC_1Point_64[CountV64]=(0x7fff-ADC5New)&0x7fff; + BuffADC_1Point_64[CountV31]=(0x7fff-ADC5New)&0x7fff; ADC_64Point += BuffADC_1Point[CountV255]; @@ -306,7 +307,7 @@ */ // Buff_Restored_Mod[CountV64] =(int)(BuffADC_32PointD[CountV64]*2 - BuffADC_64Point[CountV64]); - Buff_Restored_Mod[CountV64] =(int)(BuffADC_1Point_64[CountV64] - ((BuffADC_64Point[CountV64])>>7)); + Buff_Restored_Mod[CountV31] =(int)(BuffADC_1Point_64[CountV31] - ((BuffADC_64Point[CountV64])>>7)); @@ -368,13 +369,13 @@ if (CountV31 & 1) { //если нечетный такт то - LPC_SSP0->DR = WRITE_DAC0; //e.команда для ЦАП_0 передавать. - LPC_SSP0->DR = (Spi.DAC_A); //e. передача 12 бит + LPC_SSP0->DR = WRITE_DAC0; //e.команда для ЦАП_0 передавать. + LPC_SSP0->DR = (Spi.DAC_A)+ Gyro.Debag2; //e. передача 12 бит } else { //если такт четный. LPC_SSP0->DR = WRITE_DAC1 ; //e.команда для ЦАП_1 передавать. - LPC_SSP0->DR = (Spi.DAC_B); + LPC_SSP0->DR = (Spi.DAC_B) + Gyro.Debag; } }