![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LGstaandart by
Diff: SPI.c
- Revision:
- 216:189b0ea1dc38
- Parent:
- 215:b58b887fd367
- Child:
- 217:15cd8752bb6c
--- a/SPI.c Tue Aug 29 06:33:08 2017 +0000 +++ b/SPI.c Mon Sep 04 12:09:55 2017 +0000 @@ -21,8 +21,8 @@ int SinPls=0,SinMns=0; int TSinPls=0,TSinMns=0; int timer=750; -int sum=0,znak=0; - unsigned int testcount=0; +int sum=0; + unsigned int testcount=0,faza, fazaFlag=0; unsigned int ADC5New; unsigned int Buff_ADC_1 [32]; unsigned int Buff_ADC_2 [32]; @@ -50,109 +50,93 @@ //unsigned int Buff_AMP64P [256]; unsigned int TypeMod=0; 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]; -unsigned int Mod=0; +unsigned int ModArrayTriangle [64]; +unsigned int ModArraySaw [64]; +unsigned int Mod=0; +int znak; void InitMOD(void) { - for (int i = 0; i < 64; i++ ) + /* for (int i = 0; i < 64; i++ ) { - /*if(i<32) { ModArrayTriangle[i]=Mod; Mod+=3;} - else { ModArrayTriangle[i]=Mod; Mod-=3;}*/ + if(i<32) { ModArrayTriangle[i]=Mod; Mod+=3;} + else { ModArrayTriangle[i]=Mod; Mod-=3;} } for (int i = 0; i < 16; i++ ) { - /* ModArraySaw[i]=Mod; - Mod+=1;*/ - } + ModArraySaw[i]=Mod; + Mod+=1; + }*/ } void Modulator(void) { - if(!MODFlag) - { switch(TypeMod) { - 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 0: LPC_DAC->DACR = (ModArraySin [(CountV64-Gyro.PLC_Gain)&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; } - - - - - - } } void PLCRegul(void) -{ - unsigned int temp, Temp_Dac_B=0,Side=0; - static int CountFaza; - +{ +static unsigned int Flag_64=0, count; +static int CountFaza,Sin; - if(conuntPLS<30) - { - // Temp_Dac_B=(0xffff-Spi.DAC_B);Buff_Restored_Mod[CountV64] BuffADC_1Point[CountV255] - /* if( (ModArraySin[(CountV64)&0x3f]-50)>0) znak=1; - else znak = -1; - for (CountFaza = 0; CountFaza <32; CountFaza++) SinPls += ((Buff_Restored_Mod[ (CountFaza - Gyro.PLC_Phase) & 0x3f]))>>5; - for (CountFaza = 32; CountFaza <64; CountFaza++) SinMns += ((Buff_Restored_Mod[ (CountFaza - Gyro.PLC_Phase) & 0x3f]))>>5;*/ - /* for (CountFaza = 0; CountFaza <32; CountFaza++) SinPls += (( BuffADC_1Point[ (CountFaza - Gyro.PLC_Phase) & 0x3f]))>>5; - for (CountFaza = 32; CountFaza <64; CountFaza++) SinMns += (( BuffADC_1Point[ (CountFaza - Gyro.PLC_Phase) & 0x3f]))>>5; */ - /*for (CountFaza = 0; CountFaza <64; CountFaza++) - { - if(Buff_Restored_Mod[CountFaza]>0) SinPls+=(Buff_Restored_Mod[CountFaza])>>5; - else SinMns+=(Buff_Restored_Mod[CountFaza])>>5; - sum += (Buff_Restored_Mod[CountFaza])>>5; - }*/ + for (CountFaza = 0; CountFaza <64; CountFaza++) + { + Sin=(ModArraySin[CountFaza] - 50); + if(Sin < 0) znak = -1; + else znak = 1; + BuffADC_znak[CountFaza] = znak; + } + if(Flag_64) + { + for (CountFaza = 0; CountFaza <32; CountFaza++) + { + SinPls+= ((Buff_Restored_Mod[(CountFaza - Gyro.PLC_Phase) & 0x3f])*BuffADC_znak[CountFaza]); + } + for (CountFaza = 32; CountFaza <64; CountFaza++) + { + SinMns-= ((Buff_Restored_Mod[(CountFaza - Gyro.PLC_Phase) & 0x3f])*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; + } + } + else count++; + + Flag_64=0; + } + else Flag_64++; - conuntPLS++; - } - else{ - - TSinPls=SinPls; - TSinMns=SinMns; - conuntPLS=0; - Gyro.PLC_Eror = (TSinMns+TSinPls)>>5; - sum+=Gyro.PLC_Eror ; - sprintf((Time)," %d %d %d %d\r\n", Buff_Restored_Mod[ (CountV64 - Gyro.PLC_Phase) & 0x3f], Buff_Restored_Mod[ (CountV64 - Gyro.PLC_Phase+1) & 0x3f],Buff_Restored_Mod[ (CountV64 - Gyro.PLC_Phase+2) & 0x3f], Buff_Restored_Mod[ (CountV64 - Gyro.PLC_Phase+23) & 0x3f]); - WriteCon(Time); - SinPls=0; - SinMns=0; - - - - /* if(Gyro.PLC_Eror>0) {Gyro.PLC_regul--;} - else {Gyro.PLC_regul++;} -*/ - - if(Gyro.RgConA&0x8) - { - Spi.DAC_B-=(Gyro.PLC_Eror>>4)*Gyro.PLC_Gain; - /* if(Gyro.PLC_Eror>0) {Spi.DAC_B+=Gyro.PLC_Eror*Gyro.PLC_Gain;} - else {Spi.DAC_B-=Gyro.PLC_Eror*Gyro.PLC_Gain;}*/ - } - - if(Gyro.PLC_Eror>0){ Gyro.PLC_Eror_count++;} - else {Gyro.PLC_Eror_count--;} - - Gyro.PLC_Eror=0; - - 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; - } - } - + + + + 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; + } } @@ -162,7 +146,7 @@ static int CountFaza; temp = MODCount; - /* for (CountFaza = 0; CountFaza <16; CountFaza++) SinPls+= (Buff_Restored_Mod[ (CountFaza - Gyro.PLC_Phase) & 0x3f]); + /*for (CountFaza = 0; CountFaza <16; CountFaza++) SinPls+= (Buff_Restored_Mod[ (CountFaza - Gyro.PLC_Phase) & 0x3f]); for (CountFaza = 16; CountFaza <32; CountFaza++) SinMns-= (Buff_Restored_Mod[ (CountFaza - Gyro.PLC_Phase) & 0x3f]); for (CountFaza = 32; CountFaza <48; CountFaza++) SinPls+= (Buff_Restored_Mod[ (CountFaza - Gyro.PLC_Phase) & 0x3f]); for (CountFaza = 48; CountFaza <64; CountFaza++) SinMns-= (Buff_Restored_Mod[ (CountFaza - Gyro.PLC_Phase) & 0x3f]);*/ @@ -188,31 +172,27 @@ } void HFORegul(void) { - - RegulADC=32767-Spi.ADC5; - DeltaRegul+=((Gyro.HFO_ref-RegulADC)); - //tempDeltaRegul+=((Gyro.HFO_ref-RegulADC)); - //if(DeltaRegul>50)DeltaRegul=50; - - if(timer) timer--; - else - { - /*sprintf((Time),"%d %d %d %d %d %d \r\n", Gyro.HFO_Min , Spi.DAC_A,Gyro.HFO_Max,tempDeltaRegul>>10, Spi.DAC_B, Gyro.CuruAngle); - WriteCon(Time); - Gyro.CuruAngle=0;*/ - //tempDeltaRegul=0; - if(Gyro.RgConA&0x2) - { - DeltaRegul=DeltaRegul>>10; - tempDeltaRegul=DeltaRegul>>10; - Spi.DAC_A-=DeltaRegul*Gyro.HFO_Gain; - timer=10; - } - else DeltaRegul=0; - } +static unsigned int countHFO; + if(countHFO<128) + { + RegulADC=(32767-Spi.ADC5); + DeltaRegul+=((Gyro.HFO_ref-RegulADC)); + countHFO++; + } + else + { + countHFO=0; + if(Gyro.RgConA&0x2) + { + DeltaRegul=DeltaRegul>>17; + tempDeltaRegul=DeltaRegul>>17; + Spi.DAC_A-=DeltaRegul*Gyro.HFO_Gain; + timer=10; + } + else DeltaRegul=0; + } if(Spi.DAC_A>Gyro.HFO_Min-1) Spi.DAC_A=Gyro.HFO_Min-2; else if(Spi.DAC_A<Gyro.HFO_Max+1) Spi.DAC_A=Gyro.HFO_Max+2; - } @@ -297,47 +277,37 @@ } if(Time1Hz>6) { - BuffADC_1Point[CountV255]=ADC5New;//(0x7fff-ADC5New)&0x7fff; + BuffADC_1Point[CountV255] =(0x7fff-ADC5New)&0x7fff; + BuffADC_1Point_64[CountV64]=(0x7fff-ADC5New)&0x7fff; + ADC_64Point += BuffADC_1Point[CountV255]; - ADC_64Point -= BuffADC_1Point[(CountV255 - 64) & 0xff]; // заполнение буфера накопленых приращений за 64 тактов + ADC_64Point -= BuffADC_1Point[(CountV255 - 128) & 0xff]; // заполнение буфера накопленых приращений за 64 тактов BuffADC_64Point[CountV64] = ADC_64Point; - ADC_32PointD += BuffADC_1Point[CountV255]; + /*ADC_32PointD += BuffADC_1Point[CountV255]; ADC_32PointD -= BuffADC_1Point[(CountV255 - 32) & 0xff]; // заполнение буфера накопленых приращений за 32 тактов ADC_32PointD += BuffADC_1Point[(CountV255 - 64) & 0xff]; - ADC_32PointD -= BuffADC_1Point[(CountV255 - 96) & 0xff]; - BuffADC_32PointD[CountV64] = ADC_32PointD; + ADC_32PointD -= BuffADC_1Point[(CountV255 - 96) & 0xff];*/ + // BuffADC_32PointD[CountV64] = ADC_32PointD; + /* ADC_16Point += BuffADC_1Point[CountV255]; ADC_16Point -= BuffADC_1Point[(CountV255 - 16) & 0xff]; BuffADC_16Point [CountV64] = ADC_16Point; - + */ - Buff_Restored_Mod[CountV64] =(int)(BuffADC_32PointD[CountV64] - BuffADC_64Point[CountV64]); - - - - /* if( (ModArraySin[(CountV64)&0x3f]-50)>0) znak=1; - else znak = -1;*/ - if (CountV64<32) SinPls += (Buff_Restored_Mod[ (CountV64 - Gyro.PLC_Phase) & 0x3f]/*znak*/)>>5; - else SinMns += (Buff_Restored_Mod[ (CountV64 - Gyro.PLC_Phase) & 0x3f]/*znak*/)>>5; - } - - /*if(Gyro.LogMod) - { - sprintf((Time),"%i\r\n", Buff_Restored_Mod[CountV64]); - WriteCon(Time); - }*/ - - - // BuffADC_64Point[CountV64]=ADC5New; - // Buff_ADC_5[CountV255] = (0x7fff-ADC5New)<<2; - - + // 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)); + + + + // SinPls += (Buff_Restored_Mod[ (CountV64 - Gyro.PLC_Phase) & 0x3f]/*znak*/)>>5; + // SinMns += (Buff_Restored_Mod[ (CountV64 - Gyro.PLC_Phase) & 0x3f]/*znak*/)>>5; + } } void ShowMod(void)//технологическая функция для просмотра в ориджине мод на всем диапазпне цап