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