![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork
Fork of LG by
SPI.c@214:4c70e452c491, 2017-08-16 (annotated)
- Committer:
- Kovalev_D
- Date:
- Wed Aug 16 09:00:25 2017 +0000
- Revision:
- 214:4c70e452c491
- Parent:
- 213:9953db9543d6
- Child:
- 215:b58b887fd367
fdxcz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 0:8ad47e2b6f00 | 1 | #include "Global.h" |
igor_v | 0:8ad47e2b6f00 | 2 | struct SPI Spi; |
Kovalev_D | 112:4a96133a1311 | 3 | //unsigned int Temp_AMP; |
Kovalev_D | 96:1c8536458119 | 4 | unsigned int Temp_AMP64P; |
Kovalev_D | 196:f76dbc081e63 | 5 | int ttt=1; |
Kovalev_D | 99:3d8f206ceac2 | 6 | unsigned int Count_AMP, ADD_AMP, Cur_Amp; |
Kovalev_D | 99:3d8f206ceac2 | 7 | int Znak_Amp; |
Kovalev_D | 109:ee0cff33ad3b | 8 | int AD_Regul = 0; |
Kovalev_D | 190:289514f730ee | 9 | int temp9,tempADC5; |
Kovalev_D | 148:7ce8c1fd00f7 | 10 | int AD_MAX=0; |
Kovalev_D | 196:f76dbc081e63 | 11 | int k=0,l=0,r=0,n=0;//счетчики для регулировки периметра |
Kovalev_D | 188:4c523cc373cc | 12 | int flagmod=0,Bdelta; |
Kovalev_D | 191:40028201ddad | 13 | int start=10; |
Kovalev_D | 197:7a05523bf588 | 14 | int dispersion=0,side=1,tempstrafe=15000; |
Kovalev_D | 86:398da56ef751 | 15 | unsigned int Temp_ADC_2; |
Kovalev_D | 86:398da56ef751 | 16 | unsigned int Temp_ADC_3; |
Kovalev_D | 86:398da56ef751 | 17 | unsigned int Temp_ADC_4; |
Kovalev_D | 86:398da56ef751 | 18 | unsigned int Temp_ADC_5; |
Kovalev_D | 214:4c70e452c491 | 19 | int ADC_5_T; |
Kovalev_D | 147:1aed74f19a8f | 20 | unsigned int TempA; |
Kovalev_D | 158:0c8342e1837a | 21 | unsigned int TempTermLM; |
Kovalev_D | 211:ac8251b067d2 | 22 | unsigned int conuntPLS; |
Kovalev_D | 197:7a05523bf588 | 23 | int ADC5Old,ADCDIF=0; |
Kovalev_D | 197:7a05523bf588 | 24 | int DACModReg; |
Kovalev_D | 197:7a05523bf588 | 25 | int SinPls=0,SinMns=0; |
Kovalev_D | 214:4c70e452c491 | 26 | int TSinPls=0,TSinMns=0; |
Kovalev_D | 213:9953db9543d6 | 27 | int timer=750; |
Kovalev_D | 214:4c70e452c491 | 28 | unsigned int testcount=0; |
Kovalev_D | 197:7a05523bf588 | 29 | unsigned int ADC5New; |
Kovalev_D | 95:dd51e577e114 | 30 | unsigned int Buff_ADC_1 [32]; |
Kovalev_D | 95:dd51e577e114 | 31 | unsigned int Buff_ADC_2 [32]; |
Kovalev_D | 95:dd51e577e114 | 32 | unsigned int Buff_ADC_3 [32]; |
Kovalev_D | 95:dd51e577e114 | 33 | unsigned int Buff_ADC_4 [32]; |
igor_v | 51:81f47b817071 | 34 | |
Kovalev_D | 213:9953db9543d6 | 35 | int RegulADC,DeltaRegul,tempDeltaRegul; |
Kovalev_D | 214:4c70e452c491 | 36 | |
Kovalev_D | 214:4c70e452c491 | 37 | |
Kovalev_D | 214:4c70e452c491 | 38 | int BuffADC_1Point [255]; |
Kovalev_D | 197:7a05523bf588 | 39 | unsigned int BuffADC_16Point [64]; |
Kovalev_D | 214:4c70e452c491 | 40 | int BuffADC_32Point [64]; |
Kovalev_D | 214:4c70e452c491 | 41 | int BuffADC_64Point [64]; |
Kovalev_D | 214:4c70e452c491 | 42 | unsigned int Buff_ADC_5 [255]; |
Kovalev_D | 214:4c70e452c491 | 43 | unsigned int BuffADC_testPoint [64]; |
Kovalev_D | 214:4c70e452c491 | 44 | int BuffADC_32PointD [64]; |
Kovalev_D | 214:4c70e452c491 | 45 | |
Kovalev_D | 214:4c70e452c491 | 46 | int Buff_Restored_Mod [64]; |
Kovalev_D | 214:4c70e452c491 | 47 | int ADC_1Point; |
Kovalev_D | 214:4c70e452c491 | 48 | int ADC_32PointD; |
Kovalev_D | 214:4c70e452c491 | 49 | int ADC_64Point; |
Kovalev_D | 197:7a05523bf588 | 50 | |
Kovalev_D | 197:7a05523bf588 | 51 | unsigned int PulseADC_16Point; |
Kovalev_D | 197:7a05523bf588 | 52 | unsigned int PulseADC_32Point; |
Kovalev_D | 197:7a05523bf588 | 53 | unsigned int PulseADC_64Point; |
Kovalev_D | 197:7a05523bf588 | 54 | unsigned int PulseADC_32PointD; |
Kovalev_D | 197:7a05523bf588 | 55 | |
Kovalev_D | 197:7a05523bf588 | 56 | |
igor_v | 31:c783288001b5 | 57 | unsigned int Buff_AMP [256]; |
Kovalev_D | 96:1c8536458119 | 58 | unsigned int Buff_AMP64P [256]; |
Kovalev_D | 214:4c70e452c491 | 59 | unsigned int TypeMod=0; |
Kovalev_D | 197:7a05523bf588 | 60 | 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}; |
Kovalev_D | 197:7a05523bf588 | 61 | unsigned int ModArrayTriangle [64]; |
Kovalev_D | 197:7a05523bf588 | 62 | unsigned int ModArraySaw [64]; |
Kovalev_D | 197:7a05523bf588 | 63 | unsigned int Mod=0; |
Kovalev_D | 197:7a05523bf588 | 64 | |
Kovalev_D | 197:7a05523bf588 | 65 | void InitMOD(void) |
Kovalev_D | 197:7a05523bf588 | 66 | { |
Kovalev_D | 209:224e7331a061 | 67 | for (int i = 0; i < 64; i++ ) |
Kovalev_D | 197:7a05523bf588 | 68 | { |
Kovalev_D | 209:224e7331a061 | 69 | if(i<32) { ModArrayTriangle[i]=Mod; Mod+=3;} |
Kovalev_D | 209:224e7331a061 | 70 | else { ModArrayTriangle[i]=Mod; Mod-=3;} |
Kovalev_D | 197:7a05523bf588 | 71 | } |
Kovalev_D | 197:7a05523bf588 | 72 | |
Kovalev_D | 207:d1ce992f5d17 | 73 | for (int i = 0; i < 16; i++ ) |
Kovalev_D | 197:7a05523bf588 | 74 | { |
Kovalev_D | 197:7a05523bf588 | 75 | ModArraySaw[i]=Mod; |
Kovalev_D | 207:d1ce992f5d17 | 76 | Mod+=1; |
Kovalev_D | 197:7a05523bf588 | 77 | } |
Kovalev_D | 197:7a05523bf588 | 78 | } |
Kovalev_D | 197:7a05523bf588 | 79 | void Modulator(void) |
Kovalev_D | 197:7a05523bf588 | 80 | { |
Kovalev_D | 209:224e7331a061 | 81 | if(!MODFlag) |
Kovalev_D | 209:224e7331a061 | 82 | { |
Kovalev_D | 197:7a05523bf588 | 83 | switch(TypeMod) |
Kovalev_D | 197:7a05523bf588 | 84 | { |
Kovalev_D | 214:4c70e452c491 | 85 | case 0: LPC_DAC->DACR = (ModArraySin [(CountV64)&0x3f]*Gyro.ModAmp); break; |
Kovalev_D | 197:7a05523bf588 | 86 | case 1: LPC_DAC->DACR = (ModArraySaw [CountV64]*Gyro.ModAmp); break; |
Kovalev_D | 211:ac8251b067d2 | 87 | case 2: LPC_DAC->DACR = (ModArrayTriangle [(CountV64-2)&0x3f]*Gyro.ModAmp); break; |
Kovalev_D | 197:7a05523bf588 | 88 | } |
Kovalev_D | 209:224e7331a061 | 89 | } |
Kovalev_D | 197:7a05523bf588 | 90 | } |
Kovalev_D | 197:7a05523bf588 | 91 | void PLCRegul(void) |
Kovalev_D | 208:19150d2b528f | 92 | { |
Kovalev_D | 211:ac8251b067d2 | 93 | unsigned int temp, Temp_Dac_B=0,Side=0; |
Kovalev_D | 208:19150d2b528f | 94 | static int CountFaza; |
Kovalev_D | 211:ac8251b067d2 | 95 | |
Kovalev_D | 214:4c70e452c491 | 96 | |
Kovalev_D | 214:4c70e452c491 | 97 | |
Kovalev_D | 211:ac8251b067d2 | 98 | // Temp_Dac_B=(0xffff-Spi.DAC_B); |
Kovalev_D | 211:ac8251b067d2 | 99 | if(conuntPLS<10) |
Kovalev_D | 211:ac8251b067d2 | 100 | { |
Kovalev_D | 214:4c70e452c491 | 101 | /* for (CountFaza = 0; CountFaza <16; CountFaza++) SinPls+= BuffADC_64Point[ (CountFaza - Gyro.PLC_Phase) & 0x3f]; |
Kovalev_D | 214:4c70e452c491 | 102 | for (CountFaza = 16; CountFaza <48; CountFaza++) SinMns+= BuffADC_64Point[ (CountFaza - Gyro.PLC_Phase) & 0x3f]; |
Kovalev_D | 214:4c70e452c491 | 103 | for (CountFaza = 48; CountFaza <64; CountFaza++) SinPls+= BuffADC_64Point[ (CountFaza - Gyro.PLC_Phase) & 0x3f]; |
Kovalev_D | 214:4c70e452c491 | 104 | conuntPLS++;*/ |
Kovalev_D | 211:ac8251b067d2 | 105 | } |
Kovalev_D | 211:ac8251b067d2 | 106 | else |
Kovalev_D | 211:ac8251b067d2 | 107 | { |
Kovalev_D | 211:ac8251b067d2 | 108 | conuntPLS=0; |
Kovalev_D | 214:4c70e452c491 | 109 | Gyro.PLC_Eror = (SinMns-SinPls)>>16; |
Kovalev_D | 214:4c70e452c491 | 110 | /*sprintf((Time)," %d %d %d \r\n", SinMns, SinPls,Gyro.PLC_Eror); |
Kovalev_D | 214:4c70e452c491 | 111 | WriteCon(Time);*/ |
Kovalev_D | 214:4c70e452c491 | 112 | TSinPls= SinPls; |
Kovalev_D | 214:4c70e452c491 | 113 | TSinMns=SinMns; |
Kovalev_D | 214:4c70e452c491 | 114 | SinPls=0; |
Kovalev_D | 214:4c70e452c491 | 115 | SinMns=0; |
Kovalev_D | 211:ac8251b067d2 | 116 | if(Gyro.RgConA&0x8) |
Kovalev_D | 211:ac8251b067d2 | 117 | { |
Kovalev_D | 214:4c70e452c491 | 118 | if(Gyro.PLC_Eror>0) {Spi.DAC_B-=Gyro.PLC_Eror*Gyro.PLC_Gain;} |
Kovalev_D | 214:4c70e452c491 | 119 | else {Spi.DAC_B+=Gyro.PLC_Eror*Gyro.PLC_Gain;} |
Kovalev_D | 211:ac8251b067d2 | 120 | } |
Kovalev_D | 211:ac8251b067d2 | 121 | if(Gyro.PLC_Eror>0) {Gyro.PLC_Eror_count++;} |
Kovalev_D | 211:ac8251b067d2 | 122 | else {Gyro.PLC_Eror_count--;} |
Kovalev_D | 211:ac8251b067d2 | 123 | |
Kovalev_D | 211:ac8251b067d2 | 124 | if(Gyro.LG_Type==1) |
Kovalev_D | 211:ac8251b067d2 | 125 | { |
Kovalev_D | 211:ac8251b067d2 | 126 | if ( Spi.DAC_B < Gyro.HighTreshold ) Spi.DAC_B = (Gyro.ResetLevelHeat); |
Kovalev_D | 211:ac8251b067d2 | 127 | else if ( Spi.DAC_B > Gyro.DownTreshold ) Spi.DAC_B = (Gyro.ResetLevelCool); |
Kovalev_D | 211:ac8251b067d2 | 128 | |
Kovalev_D | 211:ac8251b067d2 | 129 | } |
Kovalev_D | 211:ac8251b067d2 | 130 | else |
Kovalev_D | 211:ac8251b067d2 | 131 | { |
Kovalev_D | 211:ac8251b067d2 | 132 | if ( Spi.DAC_B < 10300 ) Spi.DAC_B = 32000; //проверка на переваливание за границу. |
Kovalev_D | 211:ac8251b067d2 | 133 | else if ( Spi.DAC_B > 57000 ) Spi.DAC_B = 32000; |
Kovalev_D | 211:ac8251b067d2 | 134 | } |
Kovalev_D | 214:4c70e452c491 | 135 | |
Kovalev_D | 211:ac8251b067d2 | 136 | } |
Kovalev_D | 197:7a05523bf588 | 137 | } |
Kovalev_D | 197:7a05523bf588 | 138 | |
Kovalev_D | 208:19150d2b528f | 139 | |
Kovalev_D | 209:224e7331a061 | 140 | void PLCRegul250(void) |
Kovalev_D | 209:224e7331a061 | 141 | { |
Kovalev_D | 209:224e7331a061 | 142 | unsigned int temp; |
Kovalev_D | 209:224e7331a061 | 143 | static int CountFaza; |
Kovalev_D | 209:224e7331a061 | 144 | temp = MODCount; |
Kovalev_D | 214:4c70e452c491 | 145 | /* for (CountFaza = 0; CountFaza <32; CountFaza++ ) SinPls+= BuffADC_64Point[ (CountFaza - Gyro.PLC_Phase) & 0x3f]; |
Kovalev_D | 214:4c70e452c491 | 146 | for (CountFaza = 32; CountFaza <64; CountFaza++) SinMns+= BuffADC_64Point[ (CountFaza - Gyro.PLC_Phase) & 0x3f];*/ |
Kovalev_D | 209:224e7331a061 | 147 | Gyro.PLC_Eror = SinMns-SinPls; |
Kovalev_D | 214:4c70e452c491 | 148 | /* sprintf((Time)," %d %d %d %d %d\r\n",Spi.ADC5, Spi.DAC_B, SinPls, SinMns, Gyro.PLC_Eror); |
Kovalev_D | 209:224e7331a061 | 149 | WriteCon(Time);*/ |
Kovalev_D | 209:224e7331a061 | 150 | if(Gyro.RgConA&0x8) |
Kovalev_D | 209:224e7331a061 | 151 | { |
Kovalev_D | 209:224e7331a061 | 152 | if(Gyro.PLC_Eror>0) {Spi.DAC_B+=1 * Gyro.PLC_Gain;} |
Kovalev_D | 209:224e7331a061 | 153 | else {Spi.DAC_B-=1 * Gyro.PLC_Gain;} |
Kovalev_D | 209:224e7331a061 | 154 | } |
Kovalev_D | 209:224e7331a061 | 155 | if(Gyro.PLC_Eror>0) {Gyro.PLC_Eror_count++;} |
Kovalev_D | 209:224e7331a061 | 156 | else {Gyro.PLC_Eror_count--;} |
Kovalev_D | 209:224e7331a061 | 157 | |
Kovalev_D | 209:224e7331a061 | 158 | if ( Spi.DAC_B < 10300 ) Spi.DAC_B = 32000; //проверка на переваливание за границу. |
Kovalev_D | 209:224e7331a061 | 159 | else if ( Spi.DAC_B > 57000 ) Spi.DAC_B = 32000; |
igor_v | 110:6406b7ac0442 | 160 | |
Kovalev_D | 209:224e7331a061 | 161 | SinPls=0; |
Kovalev_D | 209:224e7331a061 | 162 | SinMns=0; |
Kovalev_D | 209:224e7331a061 | 163 | } |
Kovalev_D | 211:ac8251b067d2 | 164 | void HFORegul(void) |
Kovalev_D | 213:9953db9543d6 | 165 | { |
Kovalev_D | 213:9953db9543d6 | 166 | |
Kovalev_D | 211:ac8251b067d2 | 167 | RegulADC=32767-Spi.ADC5; |
Kovalev_D | 213:9953db9543d6 | 168 | DeltaRegul+=((Gyro.HFO_ref-RegulADC)); |
Kovalev_D | 213:9953db9543d6 | 169 | //tempDeltaRegul+=((Gyro.HFO_ref-RegulADC)); |
Kovalev_D | 213:9953db9543d6 | 170 | //if(DeltaRegul>50)DeltaRegul=50; |
Kovalev_D | 213:9953db9543d6 | 171 | |
Kovalev_D | 213:9953db9543d6 | 172 | if(timer) timer--; |
Kovalev_D | 213:9953db9543d6 | 173 | else |
Kovalev_D | 213:9953db9543d6 | 174 | { |
Kovalev_D | 213:9953db9543d6 | 175 | /*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); |
Kovalev_D | 213:9953db9543d6 | 176 | WriteCon(Time); |
Kovalev_D | 213:9953db9543d6 | 177 | Gyro.CuruAngle=0;*/ |
Kovalev_D | 213:9953db9543d6 | 178 | //tempDeltaRegul=0; |
Kovalev_D | 211:ac8251b067d2 | 179 | if(Gyro.RgConA&0x2) |
Kovalev_D | 211:ac8251b067d2 | 180 | { |
Kovalev_D | 213:9953db9543d6 | 181 | DeltaRegul=DeltaRegul>>10; |
Kovalev_D | 213:9953db9543d6 | 182 | tempDeltaRegul=DeltaRegul>>10; |
Kovalev_D | 211:ac8251b067d2 | 183 | Spi.DAC_A-=DeltaRegul*Gyro.HFO_Gain; |
Kovalev_D | 213:9953db9543d6 | 184 | timer=10; |
Kovalev_D | 213:9953db9543d6 | 185 | } |
Kovalev_D | 213:9953db9543d6 | 186 | else DeltaRegul=0; |
Kovalev_D | 213:9953db9543d6 | 187 | } |
Kovalev_D | 213:9953db9543d6 | 188 | if(Spi.DAC_A>Gyro.HFO_Min-1) Spi.DAC_A=Gyro.HFO_Min-2; |
Kovalev_D | 213:9953db9543d6 | 189 | else if(Spi.DAC_A<Gyro.HFO_Max+1) Spi.DAC_A=Gyro.HFO_Max+2; |
Kovalev_D | 211:ac8251b067d2 | 190 | |
Kovalev_D | 211:ac8251b067d2 | 191 | } |
Kovalev_D | 208:19150d2b528f | 192 | |
Kovalev_D | 208:19150d2b528f | 193 | |
Kovalev_D | 208:19150d2b528f | 194 | |
Kovalev_D | 208:19150d2b528f | 195 | // Spi.DAC_B-=ADCDIF>>6; |
Kovalev_D | 208:19150d2b528f | 196 | |
Kovalev_D | 147:1aed74f19a8f | 197 | void ADS_Acum(void) |
Kovalev_D | 147:1aed74f19a8f | 198 | { |
Kovalev_D | 157:1069c80f4944 | 199 | Spi.ADC_NewData = 0; |
Kovalev_D | 209:224e7331a061 | 200 | // Gyro.Termo = (unsigned int)(((Spi.ADC1>>1) + Gyro.Tmp_OffsetT4) * Gyro.Tmp_scaleT4); |
Kovalev_D | 209:224e7331a061 | 201 | Gyro.Termo = (unsigned int)(Spi.ADC1>>1); |
Kovalev_D | 209:224e7331a061 | 202 | Gyro.IN1_Accum += Spi.ADC2; |
Kovalev_D | 209:224e7331a061 | 203 | Gyro.IN2_Accum += Spi.ADC3; |
Kovalev_D | 209:224e7331a061 | 204 | // Gyro.DeltaT = (unsigned int)(((Spi.ADC4>>1) + Gyro.Tmp_OffsetT5) * Gyro.Tmp_scaleT5); |
Kovalev_D | 209:224e7331a061 | 205 | Gyro.DeltaT = (unsigned int)(Spi.ADC4>>1); |
Kovalev_D | 208:19150d2b528f | 206 | |
Kovalev_D | 172:ef7bf1663645 | 207 | TempA = (0xffff - Spi.ADC5); // перевернем знак и умножим на два (было 32000...0 стало 0 ...32000 /*сдвиг(<<1) стало 0 ...64000*/) |
Kovalev_D | 211:ac8251b067d2 | 208 | Gyro.TermLM = Spi.ADC1; |
Kovalev_D | 157:1069c80f4944 | 209 | Gyro.ADF_Accum += TempA; |
Kovalev_D | 157:1069c80f4944 | 210 | Gyro.ADS_Accum += TempA; |
Kovalev_D | 208:19150d2b528f | 211 | /// Gyro.ADS_AccumTermLM+=TempTermLM; |
Kovalev_D | 157:1069c80f4944 | 212 | Gyro.ADF_Count ++; |
Kovalev_D | 157:1069c80f4944 | 213 | Gyro.ADS_Count ++; |
Kovalev_D | 209:224e7331a061 | 214 | Gyro.ADM_Count ++; |
Kovalev_D | 209:224e7331a061 | 215 | /* sprintf((Time),"%d %d\r\n",((Gyro.In1>>1) - 0x4fff),(Spi.DAC_B-0x4fff)); |
Kovalev_D | 209:224e7331a061 | 216 | WriteCon(Time);*/ |
Kovalev_D | 209:224e7331a061 | 217 | if (Gyro.ADM_Count > 255) { |
Kovalev_D | 209:224e7331a061 | 218 | Gyro.In1 = Gyro.IN1_Accum>>8; |
Kovalev_D | 209:224e7331a061 | 219 | Gyro.In2 = Gyro.IN2_Accum>>8; |
Kovalev_D | 209:224e7331a061 | 220 | Gyro.IN1_Accum=0; |
Kovalev_D | 209:224e7331a061 | 221 | Gyro.IN2_Accum=0; |
Kovalev_D | 209:224e7331a061 | 222 | Gyro.ADM_Count=0; |
Kovalev_D | 147:1aed74f19a8f | 223 | |
Kovalev_D | 209:224e7331a061 | 224 | } |
Kovalev_D | 207:d1ce992f5d17 | 225 | if (Gyro.ADF_Count > 15) { // если прошло 16 тактов виброподвеса |
Kovalev_D | 172:ef7bf1663645 | 226 | Gyro.AD_Fast = Gyro.ADF_Accum << 11; //обновляем данные и приводим в один масштаб |
Kovalev_D | 157:1069c80f4944 | 227 | Gyro.ADF_Count = 0;// |
Kovalev_D | 157:1069c80f4944 | 228 | Gyro.ADF_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 229 | Gyro.ADF_NewData = 1; |
Kovalev_D | 157:1069c80f4944 | 230 | } |
Kovalev_D | 207:d1ce992f5d17 | 231 | if (Gyro.ADS_Count > 255) { // если прошло 256 тактов виброподвеса |
Kovalev_D | 172:ef7bf1663645 | 232 | Gyro.AD_Slow = Gyro.ADS_Accum << 7; //обновляем данные и приводим в один масштаб |
Kovalev_D | 211:ac8251b067d2 | 233 | // Gyro.TermLM = Gyro.ADS_AccumTermLM << 3; |
Kovalev_D | 157:1069c80f4944 | 234 | Gyro.ADS_Count = 0; |
Kovalev_D | 157:1069c80f4944 | 235 | Gyro.ADS_Accum = 0; |
Kovalev_D | 158:0c8342e1837a | 236 | Gyro.ADS_AccumTermLM=0; |
Kovalev_D | 207:d1ce992f5d17 | 237 | Gyro.ADS_NewData = 1; |
Kovalev_D | 209:224e7331a061 | 238 | } |
Kovalev_D | 147:1aed74f19a8f | 239 | } |
igor_v | 114:5cc38a53d8a7 | 240 | void SPI_Exchange(void) // новая функция чтения, в нецй не должно быть ничего лишнего |
Kovalev_D | 157:1069c80f4944 | 241 | { |
Kovalev_D | 157:1069c80f4944 | 242 | unsigned int DummySPI; |
Kovalev_D | 197:7a05523bf588 | 243 | //unsigned int ADC5Dif; |
Kovalev_D | 197:7a05523bf588 | 244 | ADC5New = LPC_SSP0->DR;// Чтение АЦП |
Kovalev_D | 207:d1ce992f5d17 | 245 | //Spi.ADC5_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 246 | Spi.ADC4_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 247 | Spi.ADC3_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 248 | Spi.ADC2_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 249 | Spi.ADC1_Accum += LPC_SSP0->DR; |
Kovalev_D | 207:d1ce992f5d17 | 250 | Spi.ADC5_Accum += ADC5New; |
Kovalev_D | 209:224e7331a061 | 251 | |
Kovalev_D | 207:d1ce992f5d17 | 252 | while (LPC_SSP0->SR & RX_SSP_notEMPT) |
Kovalev_D | 207:d1ce992f5d17 | 253 | { |
Kovalev_D | 170:d099c3025f87 | 254 | DummySPI = LPC_SSP0->DR; //если буфер SPI не пуст.//очистить буфер. |
Kovalev_D | 157:1069c80f4944 | 255 | } |
Kovalev_D | 112:4a96133a1311 | 256 | DAC_OutPut(); |
Kovalev_D | 157:1069c80f4944 | 257 | if (CountV31 == 0) { // просто фильтруем по 32 точкам. |
Kovalev_D | 197:7a05523bf588 | 258 | // выставояем бит, что есть новы данные |
Kovalev_D | 157:1069c80f4944 | 259 | Spi.ADC1 = Spi.ADC1_Accum >> 5; // подгоотавливаем данные (в той эе сетке) те ADC1 0..65535 |
Kovalev_D | 157:1069c80f4944 | 260 | Spi.ADC2 = Spi.ADC2_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 261 | Spi.ADC3 = Spi.ADC3_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 262 | Spi.ADC4 = Spi.ADC4_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 263 | Spi.ADC5 = Spi.ADC5_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 264 | Spi.ADC1_Accum = 0; // сбрасывкем аккамулятор |
Kovalev_D | 157:1069c80f4944 | 265 | Spi.ADC2_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 266 | Spi.ADC3_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 267 | Spi.ADC4_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 268 | Spi.ADC5_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 269 | Spi.ADC_NewData = 1; |
Kovalev_D | 209:224e7331a061 | 270 | |
Kovalev_D | 207:d1ce992f5d17 | 271 | } |
Kovalev_D | 197:7a05523bf588 | 272 | |
Kovalev_D | 214:4c70e452c491 | 273 | |
Kovalev_D | 214:4c70e452c491 | 274 | BuffADC_1Point[CountV255]=(0x7fff-ADC5New); |
Kovalev_D | 214:4c70e452c491 | 275 | |
Kovalev_D | 214:4c70e452c491 | 276 | ADC_64Point += BuffADC_1Point[CountV255 ]; |
Kovalev_D | 214:4c70e452c491 | 277 | ADC_64Point -= BuffADC_1Point[(CountV255 - 64) & 0xff]; // заполнение буфера накопленых приращений за 64 тактов |
Kovalev_D | 214:4c70e452c491 | 278 | BuffADC_64Point[CountV64] = ADC_64Point; |
Kovalev_D | 214:4c70e452c491 | 279 | |
Kovalev_D | 214:4c70e452c491 | 280 | |
Kovalev_D | 214:4c70e452c491 | 281 | ADC_32PointD -= BuffADC_1Point[(CountV255 - 32) & 0xff]; // заполнение буфера накопленых приращений за 32 тактов |
Kovalev_D | 214:4c70e452c491 | 282 | ADC_32PointD += BuffADC_1Point[CountV255]; |
Kovalev_D | 214:4c70e452c491 | 283 | BuffADC_32PointD[CountV64] = ADC_32PointD; |
Kovalev_D | 214:4c70e452c491 | 284 | |
Kovalev_D | 214:4c70e452c491 | 285 | Buff_Restored_Mod[CountV64] = BuffADC_32PointD[CountV64]*2 - BuffADC_64Point[CountV64]; |
Kovalev_D | 214:4c70e452c491 | 286 | |
Kovalev_D | 214:4c70e452c491 | 287 | |
Kovalev_D | 214:4c70e452c491 | 288 | |
Kovalev_D | 214:4c70e452c491 | 289 | // BuffADC_64Point[CountV64]=ADC5New; |
Kovalev_D | 197:7a05523bf588 | 290 | Buff_ADC_5[CountV255] = (0x7fff-ADC5New)<<2; |
Kovalev_D | 214:4c70e452c491 | 291 | |
Kovalev_D | 214:4c70e452c491 | 292 | |
Kovalev_D | 112:4a96133a1311 | 293 | } |
Kovalev_D | 113:8be429494918 | 294 | |
Kovalev_D | 190:289514f730ee | 295 | void ShowMod(void)//технологическая функция для просмотра в ориджине мод на всем диапазпне цап |
Kovalev_D | 158:0c8342e1837a | 296 | { |
Kovalev_D | 158:0c8342e1837a | 297 | |
Kovalev_D | 158:0c8342e1837a | 298 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 158:0c8342e1837a | 299 | //////////////////////////////////смотрим все моды///////////////////////////////////////////////// |
Kovalev_D | 158:0c8342e1837a | 300 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 197:7a05523bf588 | 301 | if(dispersion>5) |
Kovalev_D | 197:7a05523bf588 | 302 | { |
Kovalev_D | 197:7a05523bf588 | 303 | if( (Gyro.PLC_Lern<60000)&&(Gyro.PLC_Error2Mode >1))//пробигаем по нескольким значениям цап(60*0х3с=0хВВ8) для определения максимальной амплитуды. |
Kovalev_D | 158:0c8342e1837a | 304 | { |
Kovalev_D | 158:0c8342e1837a | 305 | Gyro.PLC_Error2Mode--; |
Kovalev_D | 158:0c8342e1837a | 306 | Gyro.PLC_Lern++; |
Kovalev_D | 197:7a05523bf588 | 307 | Spi.DAC_B += tempstrafe*side; |
Kovalev_D | 197:7a05523bf588 | 308 | if(side>0)side=(-1); |
Kovalev_D | 197:7a05523bf588 | 309 | else side = 1; |
Kovalev_D | 197:7a05523bf588 | 310 | tempstrafe-=40; |
Kovalev_D | 197:7a05523bf588 | 311 | dispersion=0; |
Kovalev_D | 168:f4a6abb18358 | 312 | } |
Kovalev_D | 197:7a05523bf588 | 313 | else {Gyro.LogPLC=0;} |
Kovalev_D | 197:7a05523bf588 | 314 | } |
Kovalev_D | 197:7a05523bf588 | 315 | else dispersion++; |
Kovalev_D | 197:7a05523bf588 | 316 | sprintf((Time),"%d %d %d %d \r\n", Gyro.CuruAngle, Spi.DAC_B, Gyro.AD_Slow, Gyro.Termo); |
Kovalev_D | 197:7a05523bf588 | 317 | Gyro.CuruAngle=0; |
Kovalev_D | 197:7a05523bf588 | 318 | WriteCon(Time); |
Kovalev_D | 158:0c8342e1837a | 319 | } |
Kovalev_D | 209:224e7331a061 | 320 | void ShowMod2(void)//технологическая функция для просмотра в ориджине мод на всем диапазпне цап |
Kovalev_D | 209:224e7331a061 | 321 | { |
Kovalev_D | 211:ac8251b067d2 | 322 | if(dispersion>3) |
Kovalev_D | 211:ac8251b067d2 | 323 | { |
Kovalev_D | 213:9953db9543d6 | 324 | unsigned int step = 50, ENDMOD=65400; |
Kovalev_D | 209:224e7331a061 | 325 | 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); |
Kovalev_D | 209:224e7331a061 | 326 | Gyro.CuruAngle=0; |
Kovalev_D | 209:224e7331a061 | 327 | WriteCon(Time); |
Kovalev_D | 213:9953db9543d6 | 328 | Spi.DAC_B+=step; |
Kovalev_D | 213:9953db9543d6 | 329 | if(Spi.DAC_B>ENDMOD) |
Kovalev_D | 211:ac8251b067d2 | 330 | { |
Kovalev_D | 214:4c70e452c491 | 331 | // Gyro.LogMod=0; |
Kovalev_D | 211:ac8251b067d2 | 332 | PlcON |
Kovalev_D | 213:9953db9543d6 | 333 | Spi.DAC_B = 48000; |
Kovalev_D | 211:ac8251b067d2 | 334 | } |
Kovalev_D | 211:ac8251b067d2 | 335 | dispersion=0; |
Kovalev_D | 209:224e7331a061 | 336 | } |
Kovalev_D | 211:ac8251b067d2 | 337 | else dispersion++; |
Kovalev_D | 191:40028201ddad | 338 | } |
Kovalev_D | 112:4a96133a1311 | 339 | void DAC_OutPut(void)//выдача в цапы |
igor_v | 0:8ad47e2b6f00 | 340 | { |
Kovalev_D | 208:19150d2b528f | 341 | if(Gyro.RgConA&0x10) Modulator(); |
Kovalev_D | 157:1069c80f4944 | 342 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 343 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 344 | LPC_SSP0->DR=0x5555; |
igor_v | 0:8ad47e2b6f00 | 345 | |
Kovalev_D | 209:224e7331a061 | 346 | if (CountV31 & 1) |
Kovalev_D | 209:224e7331a061 | 347 | { //если нечетный такт то |
Kovalev_D | 197:7a05523bf588 | 348 | LPC_SSP0->DR = WRITE_DAC0; //e.команда для ЦАП_0 передавать. |
igor_v | 31:c783288001b5 | 349 | LPC_SSP0->DR = (Spi.DAC_A); //e. передача 12 бит |
Kovalev_D | 209:224e7331a061 | 350 | } |
Kovalev_D | 209:224e7331a061 | 351 | else |
Kovalev_D | 209:224e7331a061 | 352 | { //если такт четный. |
Kovalev_D | 157:1069c80f4944 | 353 | LPC_SSP0->DR = WRITE_DAC1 ; //e.команда для ЦАП_1 передавать. |
Kovalev_D | 205:775d54fdf646 | 354 | LPC_SSP0->DR = (Spi.DAC_B); |
igor_v | 31:c783288001b5 | 355 | } |
Kovalev_D | 112:4a96133a1311 | 356 | } |
Kovalev_D | 112:4a96133a1311 | 357 | |
Kovalev_D | 112:4a96133a1311 | 358 | |
Kovalev_D | 113:8be429494918 | 359 | |
Kovalev_D | 113:8be429494918 | 360 | |
Kovalev_D | 113:8be429494918 | 361 | |
Kovalev_D | 113:8be429494918 | 362 |