![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LGstaandart by
SPI.c@228:a8195e1b1123, 2018-01-09 (annotated)
- Committer:
- Kovalev_D
- Date:
- Tue Jan 09 13:19:26 2018 +0000
- Revision:
- 228:a8195e1b1123
- Parent:
- 227:2774b56bfab0
- Child:
- 229:f359509f0c70
- Child:
- 230:8f7eeb47ca51
tryFiltr
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 0:8ad47e2b6f00 | 1 | #include "Global.h" |
Kovalev_D | 228:a8195e1b1123 | 2 | #define NCoef 2 |
Kovalev_D | 228:a8195e1b1123 | 3 | #define DCgain 8192 |
igor_v | 0:8ad47e2b6f00 | 4 | struct SPI Spi; |
Kovalev_D | 112:4a96133a1311 | 5 | //unsigned int Temp_AMP; |
Kovalev_D | 96:1c8536458119 | 6 | unsigned int Temp_AMP64P; |
Kovalev_D | 196:f76dbc081e63 | 7 | int ttt=1; |
Kovalev_D | 99:3d8f206ceac2 | 8 | unsigned int Count_AMP, ADD_AMP, Cur_Amp; |
Kovalev_D | 99:3d8f206ceac2 | 9 | int Znak_Amp; |
Kovalev_D | 109:ee0cff33ad3b | 10 | int AD_Regul = 0; |
Kovalev_D | 190:289514f730ee | 11 | int temp9,tempADC5; |
Kovalev_D | 148:7ce8c1fd00f7 | 12 | int AD_MAX=0; |
Kovalev_D | 220:04c54405b82d | 13 | unsigned int SPIlog; |
Kovalev_D | 196:f76dbc081e63 | 14 | int k=0,l=0,r=0,n=0;//счетчики для регулировки периметра |
Kovalev_D | 188:4c523cc373cc | 15 | int flagmod=0,Bdelta; |
Kovalev_D | 191:40028201ddad | 16 | int start=10; |
Kovalev_D | 197:7a05523bf588 | 17 | int dispersion=0,side=1,tempstrafe=15000; |
Kovalev_D | 214:4c70e452c491 | 18 | int ADC_5_T; |
Kovalev_D | 227:2774b56bfab0 | 19 | int PLC_ERR_DAC,PLC_ERR_DAC_F; |
Kovalev_D | 227:2774b56bfab0 | 20 | |
Kovalev_D | 227:2774b56bfab0 | 21 | |
Kovalev_D | 147:1aed74f19a8f | 22 | unsigned int TempA; |
Kovalev_D | 158:0c8342e1837a | 23 | unsigned int TempTermLM; |
Kovalev_D | 211:ac8251b067d2 | 24 | unsigned int conuntPLS; |
Kovalev_D | 197:7a05523bf588 | 25 | int ADC5Old,ADCDIF=0; |
Kovalev_D | 215:b58b887fd367 | 26 | /*int DACModReg;*/ |
Kovalev_D | 197:7a05523bf588 | 27 | int SinPls=0,SinMns=0; |
Kovalev_D | 214:4c70e452c491 | 28 | int TSinPls=0,TSinMns=0; |
Kovalev_D | 213:9953db9543d6 | 29 | int timer=750; |
Kovalev_D | 216:189b0ea1dc38 | 30 | int sum=0; |
Kovalev_D | 216:189b0ea1dc38 | 31 | unsigned int testcount=0,faza, fazaFlag=0; |
Kovalev_D | 197:7a05523bf588 | 32 | unsigned int ADC5New; |
Kovalev_D | 95:dd51e577e114 | 33 | unsigned int Buff_ADC_1 [32]; |
Kovalev_D | 95:dd51e577e114 | 34 | unsigned int Buff_ADC_2 [32]; |
Kovalev_D | 95:dd51e577e114 | 35 | unsigned int Buff_ADC_3 [32]; |
Kovalev_D | 95:dd51e577e114 | 36 | unsigned int Buff_ADC_4 [32]; |
Kovalev_D | 220:04c54405b82d | 37 | int Buff_OUT1 [64]; |
Kovalev_D | 220:04c54405b82d | 38 | int Buff_OUT [64]; |
Kovalev_D | 213:9953db9543d6 | 39 | int RegulADC,DeltaRegul,tempDeltaRegul; |
Kovalev_D | 227:2774b56bfab0 | 40 | int count10HFO=0, count10v=0, AmpWorms,MinWorms,MaxWorms,AMPSUM,AMPSUMP,AMPSUMM,AMPSUMPout,AMPSUMMout,AMPSUMout,SumDelta,PLC_EROR,PLC_Flag,HFO_Flag,HFOdelta,HFOregul,HFOSumDelta; |
Kovalev_D | 214:4c70e452c491 | 41 | |
Kovalev_D | 215:b58b887fd367 | 42 | |
Kovalev_D | 215:b58b887fd367 | 43 | //int BuffADC_32Point [64]; |
Kovalev_D | 214:4c70e452c491 | 44 | |
Kovalev_D | 215:b58b887fd367 | 45 | //unsigned int Buff_ADC_5 [255]; |
Kovalev_D | 197:7a05523bf588 | 46 | |
Kovalev_D | 215:b58b887fd367 | 47 | |
Kovalev_D | 197:7a05523bf588 | 48 | |
Kovalev_D | 197:7a05523bf588 | 49 | |
Kovalev_D | 215:b58b887fd367 | 50 | //unsigned int PulseADC_16Point; |
Kovalev_D | 215:b58b887fd367 | 51 | //unsigned int PulseADC_32Point; |
Kovalev_D | 215:b58b887fd367 | 52 | //unsigned int PulseADC_64Point; |
Kovalev_D | 215:b58b887fd367 | 53 | //unsigned int PulseADC_32PointD; |
Kovalev_D | 215:b58b887fd367 | 54 | |
Kovalev_D | 215:b58b887fd367 | 55 | |
Kovalev_D | 215:b58b887fd367 | 56 | //unsigned int Buff_AMP [256]; |
Kovalev_D | 215:b58b887fd367 | 57 | //unsigned int Buff_AMP64P [256]; |
Kovalev_D | 228:a8195e1b1123 | 58 | int HFO_Buff_in [10]; |
Kovalev_D | 228:a8195e1b1123 | 59 | int HFO_Buff_out [10]; |
Kovalev_D | 228:a8195e1b1123 | 60 | int HFOAmpSUM; |
Kovalev_D | 228:a8195e1b1123 | 61 | int HFOAmp; |
Kovalev_D | 228:a8195e1b1123 | 62 | int HFOAmpfilt; |
Kovalev_D | 228:a8195e1b1123 | 63 | int HFOAmpfiltC; |
Kovalev_D | 220:04c54405b82d | 64 | unsigned int TypeMod=0; |
Kovalev_D | 197:7a05523bf588 | 65 | 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 | 66 | 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 | 67 | unsigned int ModArrayTriangle [64]; |
Kovalev_D | 216:189b0ea1dc38 | 68 | unsigned int ModArraySaw [64]; |
Kovalev_D | 216:189b0ea1dc38 | 69 | unsigned int Mod=0; |
Kovalev_D | 216:189b0ea1dc38 | 70 | int znak; |
Kovalev_D | 227:2774b56bfab0 | 71 | unsigned int HFO_AVR; |
Kovalev_D | 197:7a05523bf588 | 72 | void InitMOD(void) |
Kovalev_D | 197:7a05523bf588 | 73 | { |
Kovalev_D | 220:04c54405b82d | 74 | for (int i = 0; i < 64; i++ ) |
Kovalev_D | 197:7a05523bf588 | 75 | { |
Kovalev_D | 220:04c54405b82d | 76 | if(i<32) { ModArrayTriangle[i]=Mod; Mod=100;} |
Kovalev_D | 220:04c54405b82d | 77 | else { ModArrayTriangle[i]=Mod; Mod=0;} |
Kovalev_D | 197:7a05523bf588 | 78 | } |
Kovalev_D | 197:7a05523bf588 | 79 | |
Kovalev_D | 207:d1ce992f5d17 | 80 | for (int i = 0; i < 16; i++ ) |
Kovalev_D | 197:7a05523bf588 | 81 | { |
Kovalev_D | 216:189b0ea1dc38 | 82 | ModArraySaw[i]=Mod; |
Kovalev_D | 216:189b0ea1dc38 | 83 | Mod+=1; |
Kovalev_D | 220:04c54405b82d | 84 | } |
Kovalev_D | 197:7a05523bf588 | 85 | } |
Kovalev_D | 197:7a05523bf588 | 86 | void Modulator(void) |
Kovalev_D | 197:7a05523bf588 | 87 | { |
Kovalev_D | 197:7a05523bf588 | 88 | switch(TypeMod) |
Kovalev_D | 197:7a05523bf588 | 89 | { |
Kovalev_D | 220:04c54405b82d | 90 | |
Kovalev_D | 220:04c54405b82d | 91 | // case 0: LPC_DAC->DACR = (ModArraySin [(CountV64+Gyro.PLC_Phase)&0x3f])*Gyro.ModAmp + Gyro.ShiftMod-32000; break; |
Kovalev_D | 220:04c54405b82d | 92 | case 0: LPC_DAC->DACR = (ModArraySin [(CountV64+Gyro.PLC_Phase)&0x3f])*Gyro.ModAmp + Gyro.ShiftMod-32000; break; |
Kovalev_D | 220:04c54405b82d | 93 | |
Kovalev_D | 216:189b0ea1dc38 | 94 | case 1: LPC_DAC->DACR = (ModArraySaw [CountV64]*Gyro.ModAmp); break; |
Kovalev_D | 216:189b0ea1dc38 | 95 | case 2: LPC_DAC->DACR = (ModArrayTriangle [(CountV64-2)&0x3f]*Gyro.ModAmp); break; |
Kovalev_D | 216:189b0ea1dc38 | 96 | case 3: LPC_DAC->DACR = (ModArrayTriangle [(CountV64-2)&0x3f]*Gyro.ModAmp); break; |
Kovalev_D | 220:04c54405b82d | 97 | |
Kovalev_D | 220:04c54405b82d | 98 | //case 4: LPC_DAC->DACR = ((ModArraySin32 [(CountV31)&0x1f]+150)*Gyro.ModAmp); break;ShiftMod |
Kovalev_D | 220:04c54405b82d | 99 | case 4: LPC_DAC->DACR = ((ModArraySin32 [(CountV31+8)&0x1f])*Gyro.ModAmp + Gyro.ShiftMod-32000); break; |
Kovalev_D | 218:b4067cac75c0 | 100 | case 5: break; |
Kovalev_D | 197:7a05523bf588 | 101 | } |
Kovalev_D | 197:7a05523bf588 | 102 | } |
Kovalev_D | 215:b58b887fd367 | 103 | |
Kovalev_D | 209:224e7331a061 | 104 | void PLCRegul250(void) |
Kovalev_D | 209:224e7331a061 | 105 | { |
Kovalev_D | 209:224e7331a061 | 106 | unsigned int temp; |
Kovalev_D | 209:224e7331a061 | 107 | static int CountFaza; |
Kovalev_D | 209:224e7331a061 | 108 | temp = MODCount; |
Kovalev_D | 215:b58b887fd367 | 109 | |
Kovalev_D | 216:189b0ea1dc38 | 110 | /*for (CountFaza = 0; CountFaza <16; CountFaza++) SinPls+= (Buff_Restored_Mod[ (CountFaza - Gyro.PLC_Phase) & 0x3f]); |
Kovalev_D | 215:b58b887fd367 | 111 | for (CountFaza = 16; CountFaza <32; CountFaza++) SinMns-= (Buff_Restored_Mod[ (CountFaza - Gyro.PLC_Phase) & 0x3f]); |
Kovalev_D | 215:b58b887fd367 | 112 | for (CountFaza = 32; CountFaza <48; CountFaza++) SinPls+= (Buff_Restored_Mod[ (CountFaza - Gyro.PLC_Phase) & 0x3f]); |
Kovalev_D | 215:b58b887fd367 | 113 | for (CountFaza = 48; CountFaza <64; CountFaza++) SinMns-= (Buff_Restored_Mod[ (CountFaza - Gyro.PLC_Phase) & 0x3f]);*/ |
Kovalev_D | 215:b58b887fd367 | 114 | |
Kovalev_D | 214:4c70e452c491 | 115 | /* for (CountFaza = 0; CountFaza <32; CountFaza++ ) SinPls+= BuffADC_64Point[ (CountFaza - Gyro.PLC_Phase) & 0x3f]; |
Kovalev_D | 214:4c70e452c491 | 116 | for (CountFaza = 32; CountFaza <64; CountFaza++) SinMns+= BuffADC_64Point[ (CountFaza - Gyro.PLC_Phase) & 0x3f];*/ |
Kovalev_D | 209:224e7331a061 | 117 | Gyro.PLC_Eror = SinMns-SinPls; |
Kovalev_D | 214:4c70e452c491 | 118 | /* sprintf((Time)," %d %d %d %d %d\r\n",Spi.ADC5, Spi.DAC_B, SinPls, SinMns, Gyro.PLC_Eror); |
Kovalev_D | 209:224e7331a061 | 119 | WriteCon(Time);*/ |
Kovalev_D | 209:224e7331a061 | 120 | if(Gyro.RgConA&0x8) |
Kovalev_D | 209:224e7331a061 | 121 | { |
Kovalev_D | 222:7de7b3bf3a1d | 122 | /* if(Gyro.PLC_Eror>0) {Spi.DAC_B+=1 * Gyro.PLC_Gain;} |
Kovalev_D | 222:7de7b3bf3a1d | 123 | else {Spi.DAC_B-=1 * Gyro.PLC_Gain;}*/ |
Kovalev_D | 209:224e7331a061 | 124 | } |
Kovalev_D | 215:b58b887fd367 | 125 | /* if(Gyro.PLC_Eror>0) {Gyro.PLC_Eror_count++;} |
Kovalev_D | 215:b58b887fd367 | 126 | else {Gyro.PLC_Eror_count--;}*/ |
Kovalev_D | 209:224e7331a061 | 127 | |
Kovalev_D | 209:224e7331a061 | 128 | if ( Spi.DAC_B < 10300 ) Spi.DAC_B = 32000; //проверка на переваливание за границу. |
Kovalev_D | 209:224e7331a061 | 129 | else if ( Spi.DAC_B > 57000 ) Spi.DAC_B = 32000; |
igor_v | 110:6406b7ac0442 | 130 | |
Kovalev_D | 209:224e7331a061 | 131 | SinPls=0; |
Kovalev_D | 209:224e7331a061 | 132 | SinMns=0; |
Kovalev_D | 209:224e7331a061 | 133 | } |
Kovalev_D | 226:4a4d5bd5fcd7 | 134 | |
Kovalev_D | 147:1aed74f19a8f | 135 | void ADS_Acum(void) |
Kovalev_D | 147:1aed74f19a8f | 136 | { |
Kovalev_D | 157:1069c80f4944 | 137 | Spi.ADC_NewData = 0; |
Kovalev_D | 209:224e7331a061 | 138 | // Gyro.Termo = (unsigned int)(((Spi.ADC1>>1) + Gyro.Tmp_OffsetT4) * Gyro.Tmp_scaleT4); |
Kovalev_D | 227:2774b56bfab0 | 139 | Gyro.Termo = (unsigned int)((((Spi.ADC1>>1)*100)*0.0122)-27300); |
Kovalev_D | 227:2774b56bfab0 | 140 | //Gyro.Termo = |
Kovalev_D | 209:224e7331a061 | 141 | Gyro.IN1_Accum += Spi.ADC2; |
Kovalev_D | 209:224e7331a061 | 142 | Gyro.IN2_Accum += Spi.ADC3; |
Kovalev_D | 209:224e7331a061 | 143 | // Gyro.DeltaT = (unsigned int)(((Spi.ADC4>>1) + Gyro.Tmp_OffsetT5) * Gyro.Tmp_scaleT5); |
Kovalev_D | 221:53b256368ca1 | 144 | switch(Gyro.LG_Type) |
Kovalev_D | 221:53b256368ca1 | 145 | { |
Kovalev_D | 227:2774b56bfab0 | 146 | case 1: Gyro.DeltaT = (unsigned int)((((Spi.ADC2>>1)*100)*0.0122)-27300); break; |
Kovalev_D | 221:53b256368ca1 | 147 | |
Kovalev_D | 221:53b256368ca1 | 148 | case 0: Gyro.DeltaT = (unsigned int)(Spi.ADC4>>1); break; |
Kovalev_D | 221:53b256368ca1 | 149 | } |
Kovalev_D | 221:53b256368ca1 | 150 | |
Kovalev_D | 208:19150d2b528f | 151 | |
Kovalev_D | 172:ef7bf1663645 | 152 | TempA = (0xffff - Spi.ADC5); // перевернем знак и умножим на два (было 32000...0 стало 0 ...32000 /*сдвиг(<<1) стало 0 ...64000*/) |
Kovalev_D | 211:ac8251b067d2 | 153 | Gyro.TermLM = Spi.ADC1; |
Kovalev_D | 157:1069c80f4944 | 154 | Gyro.ADF_Accum += TempA; |
Kovalev_D | 157:1069c80f4944 | 155 | Gyro.ADS_Accum += TempA; |
Kovalev_D | 208:19150d2b528f | 156 | /// Gyro.ADS_AccumTermLM+=TempTermLM; |
Kovalev_D | 157:1069c80f4944 | 157 | Gyro.ADF_Count ++; |
Kovalev_D | 157:1069c80f4944 | 158 | Gyro.ADS_Count ++; |
Kovalev_D | 209:224e7331a061 | 159 | Gyro.ADM_Count ++; |
Kovalev_D | 209:224e7331a061 | 160 | /* sprintf((Time),"%d %d\r\n",((Gyro.In1>>1) - 0x4fff),(Spi.DAC_B-0x4fff)); |
Kovalev_D | 209:224e7331a061 | 161 | WriteCon(Time);*/ |
Kovalev_D | 209:224e7331a061 | 162 | if (Gyro.ADM_Count > 255) { |
Kovalev_D | 209:224e7331a061 | 163 | Gyro.In1 = Gyro.IN1_Accum>>8; |
Kovalev_D | 209:224e7331a061 | 164 | Gyro.In2 = Gyro.IN2_Accum>>8; |
Kovalev_D | 209:224e7331a061 | 165 | Gyro.IN1_Accum=0; |
Kovalev_D | 209:224e7331a061 | 166 | Gyro.IN2_Accum=0; |
Kovalev_D | 209:224e7331a061 | 167 | Gyro.ADM_Count=0; |
Kovalev_D | 209:224e7331a061 | 168 | } |
Kovalev_D | 207:d1ce992f5d17 | 169 | if (Gyro.ADF_Count > 15) { // если прошло 16 тактов виброподвеса |
Kovalev_D | 172:ef7bf1663645 | 170 | Gyro.AD_Fast = Gyro.ADF_Accum << 11; //обновляем данные и приводим в один масштаб |
Kovalev_D | 157:1069c80f4944 | 171 | Gyro.ADF_Count = 0;// |
Kovalev_D | 157:1069c80f4944 | 172 | Gyro.ADF_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 173 | Gyro.ADF_NewData = 1; |
Kovalev_D | 157:1069c80f4944 | 174 | } |
Kovalev_D | 207:d1ce992f5d17 | 175 | if (Gyro.ADS_Count > 255) { // если прошло 256 тактов виброподвеса |
Kovalev_D | 172:ef7bf1663645 | 176 | Gyro.AD_Slow = Gyro.ADS_Accum << 7; //обновляем данные и приводим в один масштаб |
Kovalev_D | 211:ac8251b067d2 | 177 | // Gyro.TermLM = Gyro.ADS_AccumTermLM << 3; |
Kovalev_D | 157:1069c80f4944 | 178 | Gyro.ADS_Count = 0; |
Kovalev_D | 157:1069c80f4944 | 179 | Gyro.ADS_Accum = 0; |
Kovalev_D | 158:0c8342e1837a | 180 | Gyro.ADS_AccumTermLM=0; |
Kovalev_D | 207:d1ce992f5d17 | 181 | Gyro.ADS_NewData = 1; |
Kovalev_D | 209:224e7331a061 | 182 | } |
Kovalev_D | 147:1aed74f19a8f | 183 | } |
Kovalev_D | 226:4a4d5bd5fcd7 | 184 | |
Kovalev_D | 226:4a4d5bd5fcd7 | 185 | void HFOFilt(void) |
Kovalev_D | 220:04c54405b82d | 186 | { |
Kovalev_D | 227:2774b56bfab0 | 187 | |
Kovalev_D | 227:2774b56bfab0 | 188 | |
Kovalev_D | 227:2774b56bfab0 | 189 | /* HFO_AVR+=(BuffADC_10v[CountV64]>>4); |
Kovalev_D | 227:2774b56bfab0 | 190 | HFO_AVR-=(BuffADC_10v[CountV64 - 32]>>4); |
Kovalev_D | 227:2774b56bfab0 | 191 | */ |
Kovalev_D | 228:a8195e1b1123 | 192 | HFOdelta=(int)((Gyro.HFO_ref)-(BuffADC_128Point[CountV64]>>5)); |
Kovalev_D | 227:2774b56bfab0 | 193 | |
Kovalev_D | 226:4a4d5bd5fcd7 | 194 | HFOSumDelta+=HFOdelta; |
Kovalev_D | 228:a8195e1b1123 | 195 | |
Kovalev_D | 228:a8195e1b1123 | 196 | |
Kovalev_D | 228:a8195e1b1123 | 197 | |
Kovalev_D | 226:4a4d5bd5fcd7 | 198 | HFOregul=HFOSumDelta/(int)(Gyro.HFO_Gain); |
Kovalev_D | 227:2774b56bfab0 | 199 | |
Kovalev_D | 226:4a4d5bd5fcd7 | 200 | HFOSumDelta-=Gyro.HFO_Gain*HFOregul; |
Kovalev_D | 226:4a4d5bd5fcd7 | 201 | tempDeltaRegul += HFOregul; |
Kovalev_D | 226:4a4d5bd5fcd7 | 202 | AMPSUM=0; |
Kovalev_D | 226:4a4d5bd5fcd7 | 203 | HFO_Flag=1; |
Kovalev_D | 227:2774b56bfab0 | 204 | |
Kovalev_D | 226:4a4d5bd5fcd7 | 205 | } |
Kovalev_D | 226:4a4d5bd5fcd7 | 206 | |
Kovalev_D | 226:4a4d5bd5fcd7 | 207 | void PLCFilt(void) |
Kovalev_D | 226:4a4d5bd5fcd7 | 208 | { |
Kovalev_D | 226:4a4d5bd5fcd7 | 209 | static int SumBuff,Delta, OldDelta; |
Kovalev_D | 226:4a4d5bd5fcd7 | 210 | |
Kovalev_D | 225:f8fee6c586cc | 211 | if (count10v>=64*32) |
Kovalev_D | 220:04c54405b82d | 212 | { |
Kovalev_D | 227:2774b56bfab0 | 213 | C_PLC_F++; |
Kovalev_D | 227:2774b56bfab0 | 214 | C_PLC_F = C_PLC_F & 0xf; |
Kovalev_D | 220:04c54405b82d | 215 | count10v=0; |
Kovalev_D | 222:7de7b3bf3a1d | 216 | |
Kovalev_D | 220:04c54405b82d | 217 | for(int q=0; q<32; q++) |
Kovalev_D | 220:04c54405b82d | 218 | { |
Kovalev_D | 220:04c54405b82d | 219 | SumBuff += BuffADC_10v[q]; |
Kovalev_D | 220:04c54405b82d | 220 | SumBuff -= BuffADC_10v_OLD[q+32]; |
Kovalev_D | 220:04c54405b82d | 221 | BuffADC_10v_F [q] = SumBuff; |
Kovalev_D | 220:04c54405b82d | 222 | } |
Kovalev_D | 225:f8fee6c586cc | 223 | |
Kovalev_D | 220:04c54405b82d | 224 | for(int q=32; q<64; q++) |
Kovalev_D | 220:04c54405b82d | 225 | { |
Kovalev_D | 220:04c54405b82d | 226 | SumBuff += BuffADC_10v[q]; |
Kovalev_D | 220:04c54405b82d | 227 | SumBuff -= BuffADC_10v[q-32]; |
Kovalev_D | 220:04c54405b82d | 228 | BuffADC_10v_F [q] = SumBuff; |
Kovalev_D | 220:04c54405b82d | 229 | } |
Kovalev_D | 220:04c54405b82d | 230 | |
Kovalev_D | 225:f8fee6c586cc | 231 | for(int q=0; q<32; q++) {AMPSUMP += BuffADC_10v_F [q];} |
Kovalev_D | 225:f8fee6c586cc | 232 | for(int q=32; q<64; q++) {AMPSUMM += BuffADC_10v_F [q];} |
Kovalev_D | 225:f8fee6c586cc | 233 | |
Kovalev_D | 225:f8fee6c586cc | 234 | for(int q=0; q<64; q++) |
Kovalev_D | 220:04c54405b82d | 235 | { |
Kovalev_D | 227:2774b56bfab0 | 236 | AMPSUM+=BuffADC_10v[q]; |
Kovalev_D | 222:7de7b3bf3a1d | 237 | AMPSUMout+=BuffADC_10v_F[q]; |
Kovalev_D | 222:7de7b3bf3a1d | 238 | BuffADC_10v_OLD[q]= BuffADC_10v[q]; |
Kovalev_D | 225:f8fee6c586cc | 239 | BuffADC_10v[q] =0; |
Kovalev_D | 220:04c54405b82d | 240 | } |
Kovalev_D | 225:f8fee6c586cc | 241 | for(int q=0; q<64; q++) |
Kovalev_D | 222:7de7b3bf3a1d | 242 | { |
Kovalev_D | 222:7de7b3bf3a1d | 243 | Buff_OUT[q]=(BuffADC_10v_F[q]-(AMPSUM>>1))>>3; |
Kovalev_D | 222:7de7b3bf3a1d | 244 | } |
Kovalev_D | 222:7de7b3bf3a1d | 245 | |
Kovalev_D | 222:7de7b3bf3a1d | 246 | /*sprintf((Time),"%d \r\n", Spi.DAC_A); |
Kovalev_D | 222:7de7b3bf3a1d | 247 | WriteCon(Time);*/ |
Kovalev_D | 227:2774b56bfab0 | 248 | |
Kovalev_D | 227:2774b56bfab0 | 249 | AMPSUM=AMPSUM>>6; |
Kovalev_D | 227:2774b56bfab0 | 250 | AMPSUM=AMPSUM>>3; |
Kovalev_D | 227:2774b56bfab0 | 251 | AMPSUM=AMPSUM>>3; |
Kovalev_D | 227:2774b56bfab0 | 252 | |
Kovalev_D | 225:f8fee6c586cc | 253 | AMPSUMPout=AMPSUMP>>1; |
Kovalev_D | 225:f8fee6c586cc | 254 | AMPSUMMout=AMPSUMM>>1; |
Kovalev_D | 222:7de7b3bf3a1d | 255 | AMPSUMout=AMPSUM; |
Kovalev_D | 225:f8fee6c586cc | 256 | |
Kovalev_D | 220:04c54405b82d | 257 | Delta= (AMPSUMPout - AMPSUMMout); |
Kovalev_D | 225:f8fee6c586cc | 258 | |
Kovalev_D | 225:f8fee6c586cc | 259 | // if((Delta<(-5000000))||(Delta>5000000))Delta=0; |
Kovalev_D | 225:f8fee6c586cc | 260 | |
Kovalev_D | 220:04c54405b82d | 261 | SumDelta+=Delta; |
Kovalev_D | 225:f8fee6c586cc | 262 | |
Kovalev_D | 220:04c54405b82d | 263 | Gyro.PLC_Eror_count=SumDelta/Gyro.PLC_Gain; |
Kovalev_D | 220:04c54405b82d | 264 | SumDelta-=Gyro.PLC_Gain*Gyro.PLC_Eror_count; |
Kovalev_D | 225:f8fee6c586cc | 265 | |
Kovalev_D | 225:f8fee6c586cc | 266 | PLC_EROR+=Gyro.PLC_Eror_count; |
Kovalev_D | 226:4a4d5bd5fcd7 | 267 | |
Kovalev_D | 227:2774b56bfab0 | 268 | BuffPLC_FILT[C_PLC_F] = Gyro.PLC_Eror_count; |
Kovalev_D | 227:2774b56bfab0 | 269 | if(Time1Hz>10) |
Kovalev_D | 227:2774b56bfab0 | 270 | { |
Kovalev_D | 227:2774b56bfab0 | 271 | PLC_ERR_DAC_F += BuffPLC_FILT[C_PLC_F]; |
Kovalev_D | 227:2774b56bfab0 | 272 | PLC_ERR_DAC_F -= BuffPLC_FILT[(C_PLC_F-8)&0xf]; |
Kovalev_D | 227:2774b56bfab0 | 273 | } |
Kovalev_D | 227:2774b56bfab0 | 274 | PLC_ERR_DAC = PLC_ERR_DAC_F>>3; |
Kovalev_D | 220:04c54405b82d | 275 | PLC_Flag=1; |
Kovalev_D | 220:04c54405b82d | 276 | AMPSUMM=0; |
Kovalev_D | 220:04c54405b82d | 277 | AMPSUMP=0; |
Kovalev_D | 226:4a4d5bd5fcd7 | 278 | |
Kovalev_D | 226:4a4d5bd5fcd7 | 279 | // LoopOff |
Kovalev_D | 220:04c54405b82d | 280 | } |
Kovalev_D | 220:04c54405b82d | 281 | } |
Kovalev_D | 226:4a4d5bd5fcd7 | 282 | void ModFilt(void) |
Kovalev_D | 226:4a4d5bd5fcd7 | 283 | { |
Kovalev_D | 226:4a4d5bd5fcd7 | 284 | |
Kovalev_D | 226:4a4d5bd5fcd7 | 285 | |
Kovalev_D | 226:4a4d5bd5fcd7 | 286 | PLCFilt(); |
Kovalev_D | 226:4a4d5bd5fcd7 | 287 | if(PLC_Flag) |
Kovalev_D | 226:4a4d5bd5fcd7 | 288 | { |
Kovalev_D | 226:4a4d5bd5fcd7 | 289 | |
Kovalev_D | 226:4a4d5bd5fcd7 | 290 | HFOSumDelta=0; |
Kovalev_D | 226:4a4d5bd5fcd7 | 291 | } |
Kovalev_D | 226:4a4d5bd5fcd7 | 292 | else HFOFilt(); |
Kovalev_D | 226:4a4d5bd5fcd7 | 293 | |
Kovalev_D | 226:4a4d5bd5fcd7 | 294 | } |
Kovalev_D | 220:04c54405b82d | 295 | |
igor_v | 114:5cc38a53d8a7 | 296 | void SPI_Exchange(void) // новая функция чтения, в нецй не должно быть ничего лишнего |
Kovalev_D | 157:1069c80f4944 | 297 | { |
Kovalev_D | 220:04c54405b82d | 298 | |
Kovalev_D | 157:1069c80f4944 | 299 | unsigned int DummySPI; |
Kovalev_D | 220:04c54405b82d | 300 | |
Kovalev_D | 197:7a05523bf588 | 301 | //unsigned int ADC5Dif; |
Kovalev_D | 197:7a05523bf588 | 302 | ADC5New = LPC_SSP0->DR;// Чтение АЦП |
Kovalev_D | 228:a8195e1b1123 | 303 | HFOAmpSUM+=0xffff-ADC5New; |
Kovalev_D | 207:d1ce992f5d17 | 304 | //Spi.ADC5_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 305 | Spi.ADC4_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 306 | Spi.ADC3_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 307 | Spi.ADC2_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 308 | Spi.ADC1_Accum += LPC_SSP0->DR; |
Kovalev_D | 207:d1ce992f5d17 | 309 | Spi.ADC5_Accum += ADC5New; |
Kovalev_D | 209:224e7331a061 | 310 | |
Kovalev_D | 207:d1ce992f5d17 | 311 | while (LPC_SSP0->SR & RX_SSP_notEMPT) |
Kovalev_D | 207:d1ce992f5d17 | 312 | { |
Kovalev_D | 170:d099c3025f87 | 313 | DummySPI = LPC_SSP0->DR; //если буфер SPI не пуст.//очистить буфер. |
Kovalev_D | 157:1069c80f4944 | 314 | } |
Kovalev_D | 112:4a96133a1311 | 315 | DAC_OutPut(); |
Kovalev_D | 157:1069c80f4944 | 316 | if (CountV31 == 0) { // просто фильтруем по 32 точкам. |
Kovalev_D | 197:7a05523bf588 | 317 | // выставояем бит, что есть новы данные |
Kovalev_D | 157:1069c80f4944 | 318 | Spi.ADC1 = Spi.ADC1_Accum >> 5; // подгоотавливаем данные (в той эе сетке) те ADC1 0..65535 |
Kovalev_D | 157:1069c80f4944 | 319 | Spi.ADC2 = Spi.ADC2_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 320 | Spi.ADC3 = Spi.ADC3_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 321 | Spi.ADC4 = Spi.ADC4_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 322 | Spi.ADC5 = Spi.ADC5_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 323 | Spi.ADC1_Accum = 0; // сбрасывкем аккамулятор |
Kovalev_D | 157:1069c80f4944 | 324 | Spi.ADC2_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 325 | Spi.ADC3_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 326 | Spi.ADC4_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 327 | Spi.ADC5_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 328 | Spi.ADC_NewData = 1; |
Kovalev_D | 209:224e7331a061 | 329 | |
Kovalev_D | 207:d1ce992f5d17 | 330 | } |
Kovalev_D | 215:b58b887fd367 | 331 | if(Time1Hz>6) |
Kovalev_D | 215:b58b887fd367 | 332 | { |
Kovalev_D | 220:04c54405b82d | 333 | BuffADC_1Point[CountV255] = (0x7fff-ADC5New)&0x7fff; |
Kovalev_D | 218:b4067cac75c0 | 334 | BuffADC_1Point_64[CountV31]=(0x7fff-ADC5New)&0x7fff; |
Kovalev_D | 216:189b0ea1dc38 | 335 | |
Kovalev_D | 227:2774b56bfab0 | 336 | ADC_128Point += BuffADC_1Point[CountV255]; |
Kovalev_D | 228:a8195e1b1123 | 337 | ADC_128Point -= BuffADC_1Point[(CountV255 - 32) & 0xff]; // заполнение буфера накопленых приращений за 64 тактов |
Kovalev_D | 227:2774b56bfab0 | 338 | BuffADC_128Point[CountV64] = ADC_128Point; |
Kovalev_D | 228:a8195e1b1123 | 339 | |
Kovalev_D | 228:a8195e1b1123 | 340 | if(Time1Hz>8) |
Kovalev_D | 228:a8195e1b1123 | 341 | { |
Kovalev_D | 228:a8195e1b1123 | 342 | if(CountV31==31) |
Kovalev_D | 228:a8195e1b1123 | 343 | { |
Kovalev_D | 228:a8195e1b1123 | 344 | HFOAmp=HFOAmpSUM>>5; |
Kovalev_D | 228:a8195e1b1123 | 345 | HFOAmpSUM=0; |
Kovalev_D | 228:a8195e1b1123 | 346 | |
Kovalev_D | 228:a8195e1b1123 | 347 | HFOAmpfilt=BUTTER(25); |
Kovalev_D | 228:a8195e1b1123 | 348 | //HFOAmpfiltC = iirr(HFOAmp); |
Kovalev_D | 228:a8195e1b1123 | 349 | |
Kovalev_D | 228:a8195e1b1123 | 350 | sprintf((Time),"%d %d %d \r\n",0xffff-ADC5New, HFOAmp, HFOAmpfilt); |
Kovalev_D | 228:a8195e1b1123 | 351 | WriteCon(Time); |
Kovalev_D | 228:a8195e1b1123 | 352 | } |
Kovalev_D | 228:a8195e1b1123 | 353 | |
Kovalev_D | 228:a8195e1b1123 | 354 | } |
Kovalev_D | 220:04c54405b82d | 355 | |
Kovalev_D | 220:04c54405b82d | 356 | // Buff_Restored_Mod[CountV31] =(int)(BuffADC_1Point_64[CountV31] - ((BuffADC_128Point[CountV64])>>7)); |
Kovalev_D | 228:a8195e1b1123 | 357 | // Buff_Restored_Mod[CountV64] =(int)(BuffADC_32PointD[CountV64]*2 - BuffADC_64Point[CountV64]); |
Kovalev_D | 220:04c54405b82d | 358 | |
Kovalev_D | 220:04c54405b82d | 359 | |
Kovalev_D | 220:04c54405b82d | 360 | count10v++; |
Kovalev_D | 226:4a4d5bd5fcd7 | 361 | count10HFO++; |
Kovalev_D | 220:04c54405b82d | 362 | BuffADC_10v[CountV64] += BuffADC_1Point[CountV255]; |
Kovalev_D | 228:a8195e1b1123 | 363 | |
Kovalev_D | 226:4a4d5bd5fcd7 | 364 | // BuffADC_10HFO[CountV64] += BuffADC_1Point[CountV255]; |
Kovalev_D | 220:04c54405b82d | 365 | ModFilt(); |
Kovalev_D | 220:04c54405b82d | 366 | } |
Kovalev_D | 220:04c54405b82d | 367 | |
Kovalev_D | 220:04c54405b82d | 368 | } |
Kovalev_D | 220:04c54405b82d | 369 | |
Kovalev_D | 228:a8195e1b1123 | 370 | |
Kovalev_D | 228:a8195e1b1123 | 371 | |
Kovalev_D | 228:a8195e1b1123 | 372 | |
Kovalev_D | 228:a8195e1b1123 | 373 | int BUTTER(int NewSample) { |
Kovalev_D | 228:a8195e1b1123 | 374 | static unsigned int SHIFT=1; |
Kovalev_D | 228:a8195e1b1123 | 375 | int ACoef[NCoef+1] = { |
Kovalev_D | 228:a8195e1b1123 | 376 | 8195, |
Kovalev_D | 228:a8195e1b1123 | 377 | 16390, |
Kovalev_D | 228:a8195e1b1123 | 378 | 8195 |
Kovalev_D | 228:a8195e1b1123 | 379 | }; |
Kovalev_D | 228:a8195e1b1123 | 380 | |
Kovalev_D | 228:a8195e1b1123 | 381 | int BCoef[NCoef+1] = { |
Kovalev_D | 228:a8195e1b1123 | 382 | 16384, |
Kovalev_D | 228:a8195e1b1123 | 383 | -32404, |
Kovalev_D | 228:a8195e1b1123 | 384 | 16024 |
Kovalev_D | 228:a8195e1b1123 | 385 | }; |
Kovalev_D | 228:a8195e1b1123 | 386 | |
Kovalev_D | 228:a8195e1b1123 | 387 | static int y1[NCoef+1]; //output samples |
Kovalev_D | 228:a8195e1b1123 | 388 | //Warning!!!!!! This variable should be signed (input sample width + Coefs width + 2 )-bit width to avoid saturation. |
Kovalev_D | 228:a8195e1b1123 | 389 | |
Kovalev_D | 228:a8195e1b1123 | 390 | static int x1[NCoef+1]; //input samples |
Kovalev_D | 228:a8195e1b1123 | 391 | int n; |
Kovalev_D | 228:a8195e1b1123 | 392 | |
Kovalev_D | 228:a8195e1b1123 | 393 | //shift the old samples |
Kovalev_D | 228:a8195e1b1123 | 394 | for(n=NCoef; n>0; n--) { |
Kovalev_D | 228:a8195e1b1123 | 395 | x1[n] = x1[n-1]; |
Kovalev_D | 228:a8195e1b1123 | 396 | y1[n] = y1[n-1]; |
Kovalev_D | 228:a8195e1b1123 | 397 | } |
Kovalev_D | 228:a8195e1b1123 | 398 | |
Kovalev_D | 228:a8195e1b1123 | 399 | //Calculate the new output |
Kovalev_D | 228:a8195e1b1123 | 400 | x1[0] = NewSample; |
Kovalev_D | 228:a8195e1b1123 | 401 | y1[0] = ACoef[0]>>SHIFT * x1[0]; |
Kovalev_D | 228:a8195e1b1123 | 402 | for(n=1; n<=NCoef; n++) |
Kovalev_D | 228:a8195e1b1123 | 403 | y1[0] += ACoef[n]>>SHIFT * x1[n] - BCoef[n]>>SHIFT * y1[n]; |
Kovalev_D | 228:a8195e1b1123 | 404 | |
Kovalev_D | 228:a8195e1b1123 | 405 | y1[0] =(int)(y1[0]/ BCoef[0]>>SHIFT); |
Kovalev_D | 228:a8195e1b1123 | 406 | |
Kovalev_D | 228:a8195e1b1123 | 407 | // return (int)(y1[0] / DCgain>>SHIFT); |
Kovalev_D | 228:a8195e1b1123 | 408 | return (int)(y1[0]); |
Kovalev_D | 228:a8195e1b1123 | 409 | } |
Kovalev_D | 228:a8195e1b1123 | 410 | |
Kovalev_D | 228:a8195e1b1123 | 411 | |
Kovalev_D | 228:a8195e1b1123 | 412 | |
Kovalev_D | 228:a8195e1b1123 | 413 | |
Kovalev_D | 228:a8195e1b1123 | 414 | |
Kovalev_D | 228:a8195e1b1123 | 415 | |
Kovalev_D | 228:a8195e1b1123 | 416 | |
Kovalev_D | 228:a8195e1b1123 | 417 | |
Kovalev_D | 220:04c54405b82d | 418 | void HFORegul(void) |
Kovalev_D | 220:04c54405b82d | 419 | { |
Kovalev_D | 220:04c54405b82d | 420 | static unsigned int countHFO; |
Kovalev_D | 220:04c54405b82d | 421 | |
Kovalev_D | 220:04c54405b82d | 422 | countHFO=0; |
Kovalev_D | 220:04c54405b82d | 423 | |
Kovalev_D | 220:04c54405b82d | 424 | if(Gyro.RgConA&0x2) |
Kovalev_D | 220:04c54405b82d | 425 | { |
Kovalev_D | 220:04c54405b82d | 426 | if(HFO_Flag) |
Kovalev_D | 220:04c54405b82d | 427 | { |
Kovalev_D | 220:04c54405b82d | 428 | Spi.DAC_A -= HFOregul; |
Kovalev_D | 220:04c54405b82d | 429 | HFO_Flag=0; |
Kovalev_D | 220:04c54405b82d | 430 | DeltaRegul=0; |
Kovalev_D | 220:04c54405b82d | 431 | } |
Kovalev_D | 220:04c54405b82d | 432 | } |
Kovalev_D | 220:04c54405b82d | 433 | |
Kovalev_D | 220:04c54405b82d | 434 | else DeltaRegul=0; |
Kovalev_D | 220:04c54405b82d | 435 | |
Kovalev_D | 220:04c54405b82d | 436 | if(Spi.DAC_A>Gyro.HFO_Min-1) Spi.DAC_A=Gyro.HFO_Min-2; |
Kovalev_D | 220:04c54405b82d | 437 | else if(Spi.DAC_A<Gyro.HFO_Max+1) Spi.DAC_A=Gyro.HFO_Max+2; |
Kovalev_D | 220:04c54405b82d | 438 | |
Kovalev_D | 220:04c54405b82d | 439 | } |
Kovalev_D | 220:04c54405b82d | 440 | |
Kovalev_D | 214:4c70e452c491 | 441 | |
Kovalev_D | 220:04c54405b82d | 442 | void PLCRegul(void) |
Kovalev_D | 215:b58b887fd367 | 443 | |
Kovalev_D | 220:04c54405b82d | 444 | { |
Kovalev_D | 220:04c54405b82d | 445 | static unsigned int Flag_64=0, count; |
Kovalev_D | 220:04c54405b82d | 446 | static int CountFaza,Sin; |
Kovalev_D | 216:189b0ea1dc38 | 447 | |
Kovalev_D | 216:189b0ea1dc38 | 448 | |
Kovalev_D | 220:04c54405b82d | 449 | if(Gyro.RgConA&0x8) |
Kovalev_D | 220:04c54405b82d | 450 | { |
Kovalev_D | 220:04c54405b82d | 451 | if(PLC_Flag) |
Kovalev_D | 220:04c54405b82d | 452 | { |
Kovalev_D | 226:4a4d5bd5fcd7 | 453 | if (Gyro.PLCDelay) |
Kovalev_D | 225:f8fee6c586cc | 454 | { |
Kovalev_D | 225:f8fee6c586cc | 455 | |
Kovalev_D | 225:f8fee6c586cc | 456 | } |
Kovalev_D | 227:2774b56bfab0 | 457 | else |
Kovalev_D | 227:2774b56bfab0 | 458 | { |
Kovalev_D | 227:2774b56bfab0 | 459 | /* if(Gyro.PLC_Eror_count>600) Gyro.PLC_Eror_count=0; |
Kovalev_D | 227:2774b56bfab0 | 460 | else if(Gyro.PLC_Eror_count<(-600)) Gyro.PLC_Eror_count=0;*/ |
Kovalev_D | 227:2774b56bfab0 | 461 | |
Kovalev_D | 227:2774b56bfab0 | 462 | Spi.DAC_B+=PLC_ERR_DAC; |
Kovalev_D | 227:2774b56bfab0 | 463 | |
Kovalev_D | 227:2774b56bfab0 | 464 | } |
Kovalev_D | 220:04c54405b82d | 465 | } |
Kovalev_D | 227:2774b56bfab0 | 466 | if(Spi.DAC_B > Gyro.HighTreshold ) |
Kovalev_D | 227:2774b56bfab0 | 467 | { |
Kovalev_D | 222:7de7b3bf3a1d | 468 | Spi.DAC_B = (Gyro.ResetLevelCool); |
Kovalev_D | 225:f8fee6c586cc | 469 | Gyro.PLCDelay = GyroP.Str.PLCDelay; |
Kovalev_D | 227:2774b56bfab0 | 470 | } |
Kovalev_D | 227:2774b56bfab0 | 471 | else if(Spi.DAC_B < Gyro.DownTreshold ) |
Kovalev_D | 227:2774b56bfab0 | 472 | { |
Kovalev_D | 222:7de7b3bf3a1d | 473 | Spi.DAC_B = (Gyro.ResetLevelHeat); |
Kovalev_D | 225:f8fee6c586cc | 474 | Gyro.PLCDelay = GyroP.Str.PLCDelay; |
Kovalev_D | 227:2774b56bfab0 | 475 | } |
Kovalev_D | 227:2774b56bfab0 | 476 | } |
Kovalev_D | 227:2774b56bfab0 | 477 | |
Kovalev_D | 227:2774b56bfab0 | 478 | |
Kovalev_D | 227:2774b56bfab0 | 479 | |
Kovalev_D | 227:2774b56bfab0 | 480 | |
Kovalev_D | 226:4a4d5bd5fcd7 | 481 | if(PLC_Flag) |
Kovalev_D | 226:4a4d5bd5fcd7 | 482 | { |
Kovalev_D | 227:2774b56bfab0 | 483 | /*sprintf((Time),"%d %d %d\r\n", PLC_ERR_DAC, Spi.DAC_B, Spi.DAC_A); |
Kovalev_D | 227:2774b56bfab0 | 484 | WriteCon(Time);*/ |
Kovalev_D | 227:2774b56bfab0 | 485 | PLC_ERR_DAC=0; |
Kovalev_D | 226:4a4d5bd5fcd7 | 486 | PLC_Flag=0; |
Kovalev_D | 226:4a4d5bd5fcd7 | 487 | } |
Kovalev_D | 220:04c54405b82d | 488 | } |
Kovalev_D | 216:189b0ea1dc38 | 489 | |
Kovalev_D | 220:04c54405b82d | 490 | |
Kovalev_D | 220:04c54405b82d | 491 | |
Kovalev_D | 113:8be429494918 | 492 | |
Kovalev_D | 190:289514f730ee | 493 | void ShowMod(void)//технологическая функция для просмотра в ориджине мод на всем диапазпне цап |
Kovalev_D | 158:0c8342e1837a | 494 | { |
Kovalev_D | 158:0c8342e1837a | 495 | |
Kovalev_D | 158:0c8342e1837a | 496 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 158:0c8342e1837a | 497 | //////////////////////////////////смотрим все моды///////////////////////////////////////////////// |
Kovalev_D | 158:0c8342e1837a | 498 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 197:7a05523bf588 | 499 | if(dispersion>5) |
Kovalev_D | 197:7a05523bf588 | 500 | { |
Kovalev_D | 197:7a05523bf588 | 501 | if( (Gyro.PLC_Lern<60000)&&(Gyro.PLC_Error2Mode >1))//пробигаем по нескольким значениям цап(60*0х3с=0хВВ8) для определения максимальной амплитуды. |
Kovalev_D | 158:0c8342e1837a | 502 | { |
Kovalev_D | 158:0c8342e1837a | 503 | Gyro.PLC_Error2Mode--; |
Kovalev_D | 158:0c8342e1837a | 504 | Gyro.PLC_Lern++; |
Kovalev_D | 197:7a05523bf588 | 505 | Spi.DAC_B += tempstrafe*side; |
Kovalev_D | 197:7a05523bf588 | 506 | if(side>0)side=(-1); |
Kovalev_D | 197:7a05523bf588 | 507 | else side = 1; |
Kovalev_D | 197:7a05523bf588 | 508 | tempstrafe-=40; |
Kovalev_D | 197:7a05523bf588 | 509 | dispersion=0; |
Kovalev_D | 168:f4a6abb18358 | 510 | } |
Kovalev_D | 197:7a05523bf588 | 511 | else {Gyro.LogPLC=0;} |
Kovalev_D | 197:7a05523bf588 | 512 | } |
Kovalev_D | 197:7a05523bf588 | 513 | else dispersion++; |
Kovalev_D | 222:7de7b3bf3a1d | 514 | /*sprintf((Time),"%d %d %d %d \r\n", Gyro.CuruAngle, Spi.DAC_B, Gyro.AD_Slow, Gyro.Termo); |
Kovalev_D | 222:7de7b3bf3a1d | 515 | Gyro.CuruAngle=0;*/ |
Kovalev_D | 197:7a05523bf588 | 516 | WriteCon(Time); |
Kovalev_D | 158:0c8342e1837a | 517 | } |
Kovalev_D | 209:224e7331a061 | 518 | void ShowMod2(void)//технологическая функция для просмотра в ориджине мод на всем диапазпне цап |
Kovalev_D | 209:224e7331a061 | 519 | { |
Kovalev_D | 211:ac8251b067d2 | 520 | if(dispersion>3) |
Kovalev_D | 211:ac8251b067d2 | 521 | { |
Kovalev_D | 213:9953db9543d6 | 522 | unsigned int step = 50, ENDMOD=65400; |
Kovalev_D | 222:7de7b3bf3a1d | 523 | /*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 | 524 | Gyro.CuruAngle=0; |
Kovalev_D | 222:7de7b3bf3a1d | 525 | WriteCon(Time);*/ |
Kovalev_D | 213:9953db9543d6 | 526 | Spi.DAC_B+=step; |
Kovalev_D | 213:9953db9543d6 | 527 | if(Spi.DAC_B>ENDMOD) |
Kovalev_D | 211:ac8251b067d2 | 528 | { |
Kovalev_D | 214:4c70e452c491 | 529 | // Gyro.LogMod=0; |
Kovalev_D | 211:ac8251b067d2 | 530 | PlcON |
Kovalev_D | 213:9953db9543d6 | 531 | Spi.DAC_B = 48000; |
Kovalev_D | 211:ac8251b067d2 | 532 | } |
Kovalev_D | 211:ac8251b067d2 | 533 | dispersion=0; |
Kovalev_D | 209:224e7331a061 | 534 | } |
Kovalev_D | 211:ac8251b067d2 | 535 | else dispersion++; |
Kovalev_D | 191:40028201ddad | 536 | } |
Kovalev_D | 112:4a96133a1311 | 537 | void DAC_OutPut(void)//выдача в цапы |
igor_v | 0:8ad47e2b6f00 | 538 | { |
Kovalev_D | 220:04c54405b82d | 539 | /*if(Gyro.RgConA&0x10)*/ Modulator(); |
Kovalev_D | 157:1069c80f4944 | 540 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 541 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 542 | LPC_SSP0->DR=0x5555; |
igor_v | 0:8ad47e2b6f00 | 543 | |
Kovalev_D | 209:224e7331a061 | 544 | if (CountV31 & 1) |
Kovalev_D | 209:224e7331a061 | 545 | { //если нечетный такт то |
Kovalev_D | 218:b4067cac75c0 | 546 | LPC_SSP0->DR = WRITE_DAC0; //e.команда для ЦАП_0 передавать. |
Kovalev_D | 220:04c54405b82d | 547 | LPC_SSP0->DR = (Spi.DAC_A); //e. передача 12 бит |
Kovalev_D | 209:224e7331a061 | 548 | } |
Kovalev_D | 209:224e7331a061 | 549 | else |
Kovalev_D | 209:224e7331a061 | 550 | { //если такт четный. |
Kovalev_D | 157:1069c80f4944 | 551 | LPC_SSP0->DR = WRITE_DAC1 ; //e.команда для ЦАП_1 передавать. |
Kovalev_D | 220:04c54405b82d | 552 | LPC_SSP0->DR = (Spi.DAC_B) ; |
igor_v | 31:c783288001b5 | 553 | } |
Kovalev_D | 112:4a96133a1311 | 554 | } |
Kovalev_D | 112:4a96133a1311 | 555 | |
Kovalev_D | 112:4a96133a1311 | 556 | |
Kovalev_D | 113:8be429494918 | 557 | |
Kovalev_D | 113:8be429494918 | 558 | |
Kovalev_D | 113:8be429494918 | 559 | |
Kovalev_D | 113:8be429494918 | 560 |