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