![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
SPI.c@208:19150d2b528f, 2017-02-07 (annotated)
- Committer:
- Kovalev_D
- Date:
- Tue Feb 07 10:11:35 2017 +0000
- Revision:
- 208:19150d2b528f
- Parent:
- 207:d1ce992f5d17
- Child:
- 209:224e7331a061
465
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 | 147:1aed74f19a8f | 19 | unsigned int TempA; |
Kovalev_D | 158:0c8342e1837a | 20 | unsigned int TempTermLM; |
igor_v | 31:c783288001b5 | 21 | |
Kovalev_D | 197:7a05523bf588 | 22 | int ADC5Old,ADCDIF=0; |
Kovalev_D | 197:7a05523bf588 | 23 | int DACModReg; |
Kovalev_D | 197:7a05523bf588 | 24 | int SinPls=0,SinMns=0; |
Kovalev_D | 197:7a05523bf588 | 25 | unsigned int ADC5New; |
Kovalev_D | 95:dd51e577e114 | 26 | unsigned int Buff_ADC_1 [32]; |
Kovalev_D | 95:dd51e577e114 | 27 | unsigned int Buff_ADC_2 [32]; |
Kovalev_D | 95:dd51e577e114 | 28 | unsigned int Buff_ADC_3 [32]; |
Kovalev_D | 95:dd51e577e114 | 29 | unsigned int Buff_ADC_4 [32]; |
igor_v | 51:81f47b817071 | 30 | |
Kovalev_D | 197:7a05523bf588 | 31 | |
Kovalev_D | 197:7a05523bf588 | 32 | unsigned int Buff_ADC_5 [512]; |
Kovalev_D | 197:7a05523bf588 | 33 | unsigned int BuffADC_16Point [64]; |
Kovalev_D | 197:7a05523bf588 | 34 | unsigned int BuffADC_32Point [64]; |
Kovalev_D | 197:7a05523bf588 | 35 | unsigned int BuffADC_64Point [64]; |
Kovalev_D | 197:7a05523bf588 | 36 | unsigned int BuffADC_32PointD [64]; |
Kovalev_D | 197:7a05523bf588 | 37 | unsigned int Buff_Restored_Mod [64]; |
Kovalev_D | 197:7a05523bf588 | 38 | |
Kovalev_D | 197:7a05523bf588 | 39 | unsigned int PulseADC_16Point; |
Kovalev_D | 197:7a05523bf588 | 40 | unsigned int PulseADC_32Point; |
Kovalev_D | 197:7a05523bf588 | 41 | unsigned int PulseADC_64Point; |
Kovalev_D | 197:7a05523bf588 | 42 | unsigned int PulseADC_32PointD; |
Kovalev_D | 197:7a05523bf588 | 43 | |
Kovalev_D | 197:7a05523bf588 | 44 | |
igor_v | 31:c783288001b5 | 45 | unsigned int Buff_AMP [256]; |
Kovalev_D | 96:1c8536458119 | 46 | unsigned int Buff_AMP64P [256]; |
Kovalev_D | 197:7a05523bf588 | 47 | unsigned int TypeMod=0; |
Kovalev_D | 197:7a05523bf588 | 48 | 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 | 49 | unsigned int ModArrayTriangle [64]; |
Kovalev_D | 197:7a05523bf588 | 50 | unsigned int ModArraySaw [64]; |
Kovalev_D | 197:7a05523bf588 | 51 | unsigned int Mod=0; |
Kovalev_D | 197:7a05523bf588 | 52 | |
Kovalev_D | 197:7a05523bf588 | 53 | void InitMOD(void) |
Kovalev_D | 197:7a05523bf588 | 54 | { |
Kovalev_D | 207:d1ce992f5d17 | 55 | for (int i = 0; i < 32; i++ ) |
Kovalev_D | 197:7a05523bf588 | 56 | { |
Kovalev_D | 207:d1ce992f5d17 | 57 | if(i<16) { ModArrayTriangle[i]=Mod; Mod+=1;} |
Kovalev_D | 207:d1ce992f5d17 | 58 | else { ModArrayTriangle[i]=Mod; Mod-=1;} |
Kovalev_D | 197:7a05523bf588 | 59 | } |
Kovalev_D | 197:7a05523bf588 | 60 | |
Kovalev_D | 207:d1ce992f5d17 | 61 | for (int i = 0; i < 16; i++ ) |
Kovalev_D | 197:7a05523bf588 | 62 | { |
Kovalev_D | 197:7a05523bf588 | 63 | ModArraySaw[i]=Mod; |
Kovalev_D | 207:d1ce992f5d17 | 64 | Mod+=1; |
Kovalev_D | 197:7a05523bf588 | 65 | } |
Kovalev_D | 197:7a05523bf588 | 66 | } |
Kovalev_D | 197:7a05523bf588 | 67 | void Modulator(void) |
Kovalev_D | 197:7a05523bf588 | 68 | { |
Kovalev_D | 197:7a05523bf588 | 69 | switch(TypeMod) |
Kovalev_D | 197:7a05523bf588 | 70 | { |
Kovalev_D | 197:7a05523bf588 | 71 | case 0: LPC_DAC->DACR = (ModArraySin [CountV64]*Gyro.ModAmp); break; |
Kovalev_D | 197:7a05523bf588 | 72 | case 1: LPC_DAC->DACR = (ModArraySaw [CountV64]*Gyro.ModAmp); break; |
Kovalev_D | 197:7a05523bf588 | 73 | case 2: LPC_DAC->DACR = (ModArrayTriangle [CountV64]*Gyro.ModAmp); break; |
Kovalev_D | 197:7a05523bf588 | 74 | } |
Kovalev_D | 197:7a05523bf588 | 75 | } |
Kovalev_D | 197:7a05523bf588 | 76 | void PLCRegul(void) |
Kovalev_D | 208:19150d2b528f | 77 | { |
Kovalev_D | 208:19150d2b528f | 78 | unsigned int temp; |
Kovalev_D | 208:19150d2b528f | 79 | static int CountFaza; |
Kovalev_D | 208:19150d2b528f | 80 | if(Gyro.RgConA&0x8) |
Kovalev_D | 208:19150d2b528f | 81 | { |
Kovalev_D | 208:19150d2b528f | 82 | for (CountFaza = 0; CountFaza <32; CountFaza++ ) |
Kovalev_D | 197:7a05523bf588 | 83 | { |
Kovalev_D | 208:19150d2b528f | 84 | SinPls+= BuffADC_64Point[ (CountFaza + Gyro.PLC_Phase) & 0x3f]; |
Kovalev_D | 208:19150d2b528f | 85 | } |
Kovalev_D | 208:19150d2b528f | 86 | for (CountFaza = 32; CountFaza <64; CountFaza++) |
Kovalev_D | 197:7a05523bf588 | 87 | { |
Kovalev_D | 208:19150d2b528f | 88 | SinMns+= BuffADC_64Point[(CountFaza + Gyro.PLC_Phase) & 0x3f]; |
Kovalev_D | 208:19150d2b528f | 89 | } |
Kovalev_D | 208:19150d2b528f | 90 | ADCDIF = SinMns-SinPls; |
Kovalev_D | 208:19150d2b528f | 91 | /*sprintf((Time),"%d\r\n",Gyro.PLC_Phase); |
Kovalev_D | 208:19150d2b528f | 92 | WriteCon(Time);*/ |
Kovalev_D | 208:19150d2b528f | 93 | if(ADCDIF>0) Spi.DAC_B+=1 * Gyro.PLC_Gain; |
Kovalev_D | 208:19150d2b528f | 94 | else Spi.DAC_B-=1 * Gyro.PLC_Gain; |
Kovalev_D | 208:19150d2b528f | 95 | |
Kovalev_D | 208:19150d2b528f | 96 | if ( Spi.DAC_B < 15300 ) Spi.DAC_B = 32000; //проверка на переваливание за границу. |
Kovalev_D | 208:19150d2b528f | 97 | else if ( Spi.DAC_B > 53000 ) Spi.DAC_B = 32000; |
Kovalev_D | 208:19150d2b528f | 98 | |
Kovalev_D | 197:7a05523bf588 | 99 | SinPls=0; |
Kovalev_D | 197:7a05523bf588 | 100 | SinMns=0; |
Kovalev_D | 208:19150d2b528f | 101 | } |
Kovalev_D | 197:7a05523bf588 | 102 | } |
Kovalev_D | 197:7a05523bf588 | 103 | |
Kovalev_D | 208:19150d2b528f | 104 | |
igor_v | 110:6406b7ac0442 | 105 | |
Kovalev_D | 208:19150d2b528f | 106 | |
Kovalev_D | 208:19150d2b528f | 107 | |
Kovalev_D | 208:19150d2b528f | 108 | |
Kovalev_D | 208:19150d2b528f | 109 | |
Kovalev_D | 208:19150d2b528f | 110 | // Spi.DAC_B-=ADCDIF>>6; |
Kovalev_D | 208:19150d2b528f | 111 | |
Kovalev_D | 147:1aed74f19a8f | 112 | void ADS_Acum(void) |
Kovalev_D | 147:1aed74f19a8f | 113 | { |
Kovalev_D | 157:1069c80f4944 | 114 | Spi.ADC_NewData = 0; |
Kovalev_D | 208:19150d2b528f | 115 | Gyro.Termo = (unsigned int)(((Spi.ADC1>>1) + Gyro.Tmp_OffsetT4) * Gyro.Tmp_scaleT4); |
Kovalev_D | 208:19150d2b528f | 116 | Gyro.In1 = Spi.ADC2; |
Kovalev_D | 208:19150d2b528f | 117 | Gyro.In2 = Spi.ADC3; |
Kovalev_D | 208:19150d2b528f | 118 | Gyro.DeltaT = (unsigned int)(((Spi.ADC4>>1) + Gyro.Tmp_OffsetT5) * Gyro.Tmp_scaleT5); |
Kovalev_D | 208:19150d2b528f | 119 | |
Kovalev_D | 208:19150d2b528f | 120 | |
Kovalev_D | 172:ef7bf1663645 | 121 | TempA = (0xffff - Spi.ADC5); // перевернем знак и умножим на два (было 32000...0 стало 0 ...32000 /*сдвиг(<<1) стало 0 ...64000*/) |
Kovalev_D | 170:d099c3025f87 | 122 | TempTermLM = Spi.ADC1; |
Kovalev_D | 170:d099c3025f87 | 123 | |
Kovalev_D | 157:1069c80f4944 | 124 | Gyro.ADF_Accum += TempA; |
Kovalev_D | 157:1069c80f4944 | 125 | Gyro.ADS_Accum += TempA; |
Kovalev_D | 208:19150d2b528f | 126 | /// Gyro.ADS_AccumTermLM+=TempTermLM; |
Kovalev_D | 157:1069c80f4944 | 127 | Gyro.ADF_Count ++; |
Kovalev_D | 157:1069c80f4944 | 128 | Gyro.ADS_Count ++; |
Kovalev_D | 147:1aed74f19a8f | 129 | |
Kovalev_D | 207:d1ce992f5d17 | 130 | if (Gyro.ADF_Count > 15) { // если прошло 16 тактов виброподвеса |
Kovalev_D | 172:ef7bf1663645 | 131 | Gyro.AD_Fast = Gyro.ADF_Accum << 11; //обновляем данные и приводим в один масштаб |
Kovalev_D | 157:1069c80f4944 | 132 | Gyro.ADF_Count = 0;// |
Kovalev_D | 157:1069c80f4944 | 133 | Gyro.ADF_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 134 | Gyro.ADF_NewData = 1; |
Kovalev_D | 157:1069c80f4944 | 135 | } |
Kovalev_D | 207:d1ce992f5d17 | 136 | if (Gyro.ADS_Count > 255) { // если прошло 256 тактов виброподвеса |
Kovalev_D | 172:ef7bf1663645 | 137 | Gyro.AD_Slow = Gyro.ADS_Accum << 7; //обновляем данные и приводим в один масштаб |
Kovalev_D | 158:0c8342e1837a | 138 | Gyro.TermLM = Gyro.ADS_AccumTermLM << 3; |
Kovalev_D | 157:1069c80f4944 | 139 | Gyro.ADS_Count = 0; |
Kovalev_D | 157:1069c80f4944 | 140 | Gyro.ADS_Accum = 0; |
Kovalev_D | 158:0c8342e1837a | 141 | Gyro.ADS_AccumTermLM=0; |
Kovalev_D | 207:d1ce992f5d17 | 142 | Gyro.ADS_NewData = 1; |
Kovalev_D | 208:19150d2b528f | 143 | /* sprintf((Time),"%d\r\n",Spi.ADC5); |
Kovalev_D | 208:19150d2b528f | 144 | WriteCon(Time);*/ |
Kovalev_D | 207:d1ce992f5d17 | 145 | //srand(Gyro.AD_Slow); |
Kovalev_D | 157:1069c80f4944 | 146 | } |
Kovalev_D | 147:1aed74f19a8f | 147 | } |
igor_v | 114:5cc38a53d8a7 | 148 | void SPI_Exchange(void) // новая функция чтения, в нецй не должно быть ничего лишнего |
Kovalev_D | 157:1069c80f4944 | 149 | { |
Kovalev_D | 157:1069c80f4944 | 150 | unsigned int DummySPI; |
Kovalev_D | 197:7a05523bf588 | 151 | //unsigned int ADC5Dif; |
Kovalev_D | 197:7a05523bf588 | 152 | ADC5New = LPC_SSP0->DR;// Чтение АЦП |
Kovalev_D | 207:d1ce992f5d17 | 153 | //Spi.ADC5_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 154 | Spi.ADC4_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 155 | Spi.ADC3_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 156 | Spi.ADC2_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 157 | Spi.ADC1_Accum += LPC_SSP0->DR; |
Kovalev_D | 207:d1ce992f5d17 | 158 | Spi.ADC5_Accum += ADC5New; |
Kovalev_D | 197:7a05523bf588 | 159 | // ADC5Dif = (ADC5New) - (ADC5Old); |
Kovalev_D | 197:7a05523bf588 | 160 | // ADC5Old=ADC5New; |
Kovalev_D | 207:d1ce992f5d17 | 161 | /* |
Kovalev_D | 197:7a05523bf588 | 162 | sprintf((Time)," %d\r\n", (Buff_Restored_Mod[CountV64])); |
Kovalev_D | 197:7a05523bf588 | 163 | WriteCon(Time); |
Kovalev_D | 197:7a05523bf588 | 164 | */ |
Kovalev_D | 207:d1ce992f5d17 | 165 | while (LPC_SSP0->SR & RX_SSP_notEMPT) |
Kovalev_D | 207:d1ce992f5d17 | 166 | { |
Kovalev_D | 170:d099c3025f87 | 167 | DummySPI = LPC_SSP0->DR; //если буфер SPI не пуст.//очистить буфер. |
Kovalev_D | 157:1069c80f4944 | 168 | } |
Kovalev_D | 112:4a96133a1311 | 169 | DAC_OutPut(); |
Kovalev_D | 157:1069c80f4944 | 170 | if (CountV31 == 0) { // просто фильтруем по 32 точкам. |
Kovalev_D | 197:7a05523bf588 | 171 | // выставояем бит, что есть новы данные |
Kovalev_D | 157:1069c80f4944 | 172 | Spi.ADC1 = Spi.ADC1_Accum >> 5; // подгоотавливаем данные (в той эе сетке) те ADC1 0..65535 |
Kovalev_D | 157:1069c80f4944 | 173 | Spi.ADC2 = Spi.ADC2_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 174 | Spi.ADC3 = Spi.ADC3_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 175 | Spi.ADC4 = Spi.ADC4_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 176 | Spi.ADC5 = Spi.ADC5_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 177 | Spi.ADC1_Accum = 0; // сбрасывкем аккамулятор |
Kovalev_D | 157:1069c80f4944 | 178 | Spi.ADC2_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 179 | Spi.ADC3_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 180 | Spi.ADC4_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 181 | Spi.ADC5_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 182 | Spi.ADC_NewData = 1; |
Kovalev_D | 207:d1ce992f5d17 | 183 | } |
Kovalev_D | 197:7a05523bf588 | 184 | |
Kovalev_D | 197:7a05523bf588 | 185 | BuffADC_64Point[CountV64]=ADC5New; |
Kovalev_D | 197:7a05523bf588 | 186 | Buff_ADC_5[CountV255] = (0x7fff-ADC5New)<<2; |
Kovalev_D | 208:19150d2b528f | 187 | |
Kovalev_D | 197:7a05523bf588 | 188 | |
Kovalev_D | 197:7a05523bf588 | 189 | /* |
Kovalev_D | 197:7a05523bf588 | 190 | PulseADC_16Point += Buff_ADC_5[CountV255]; |
Kovalev_D | 197:7a05523bf588 | 191 | PulseADC_16Point -= Buff_ADC_5[(CountV255-16)& 0xff]; // заполнение буфера накопленых приращений за 16 тактов |
Kovalev_D | 197:7a05523bf588 | 192 | BuffADC_16Point[CountV64] = (Pulse_16Point); |
Kovalev_D | 197:7a05523bf588 | 193 | |
Kovalev_D | 197:7a05523bf588 | 194 | PulseADC_32Point += Buff_ADC_5[CountV255]; |
Kovalev_D | 197:7a05523bf588 | 195 | PulseADC_32Point -= Buff_ADC_5[(CountV255-32)& 0xff ]; // заполнение буфера накопленых приращений за 32 тактов |
Kovalev_D | 197:7a05523bf588 | 196 | BuffADC_32Point[CountV64] = (PulseADC_32Point ); |
Kovalev_D | 197:7a05523bf588 | 197 | |
Kovalev_D | 197:7a05523bf588 | 198 | PulseADC_32PointD += Buff_ADC_5[CountV255]; |
Kovalev_D | 197:7a05523bf588 | 199 | PulseADC_32PointD -= Buff_ADC_5[(CountV255-32)& 0xff]; // заполнение буфера накопленых приращений за 32 тактов Двойныз |
Kovalev_D | 197:7a05523bf588 | 200 | PulseADC_32PointD += Buff_ADC_5[(CountV255-48)& 0xff]; // |
Kovalev_D | 197:7a05523bf588 | 201 | PulseADC_32PointD -= Buff_ADC_5[(CountV255-64)& 0xff]; // |
Kovalev_D | 197:7a05523bf588 | 202 | BuffADC_32PointD[CountV64] = PulseADC_32PointD ; |
Kovalev_D | 197:7a05523bf588 | 203 | */ |
Kovalev_D | 197:7a05523bf588 | 204 | /* PulseADC_64Point += (Buff_ADC_5[CountV255]); |
Kovalev_D | 197:7a05523bf588 | 205 | PulseADC_64Point -= Buff_ADC_5[(CountV255-64) & 0xff]; // заполнение буфера накопленых приращений за два 64 тактов |
Kovalev_D | 197:7a05523bf588 | 206 | BuffADC_64Point[CountV64] = (PulseADC_64Point);*/ |
Kovalev_D | 197:7a05523bf588 | 207 | //ADCDIF += BuffADC_64Point[CountV64]; |
Kovalev_D | 197:7a05523bf588 | 208 | /// Buff_Restored_Mod[CountV64] = BuffADC_32PointD[CountV64] - BuffADC_64Point[CountV64]; |
Kovalev_D | 197:7a05523bf588 | 209 | |
Kovalev_D | 197:7a05523bf588 | 210 | /* if(ADC5Old>3) |
Kovalev_D | 197:7a05523bf588 | 211 | { |
Kovalev_D | 197:7a05523bf588 | 212 | sprintf((Time),"%d %d \r\n", BuffADC_64Point[CountV64], Buff_Restored_Mod[CountV64]); |
Kovalev_D | 197:7a05523bf588 | 213 | WriteCon(Time); |
Kovalev_D | 197:7a05523bf588 | 214 | ADC5Old=0; |
Kovalev_D | 197:7a05523bf588 | 215 | } |
Kovalev_D | 197:7a05523bf588 | 216 | else ADC5Old++; |
Kovalev_D | 197:7a05523bf588 | 217 | */ |
Kovalev_D | 197:7a05523bf588 | 218 | // BackLightOFF |
Kovalev_D | 197:7a05523bf588 | 219 | |
Kovalev_D | 197:7a05523bf588 | 220 | // ADCDIF += BuffADC_64Point[CountV64]/*>>5*/; |
Kovalev_D | 197:7a05523bf588 | 221 | /* sprintf((Time),"%d %d\r\n", ADC5New, PulseADC_64Point); |
Kovalev_D | 197:7a05523bf588 | 222 | WriteCon(Time);*/ |
Kovalev_D | 128:1e4675a36c93 | 223 | |
Kovalev_D | 113:8be429494918 | 224 | |
Kovalev_D | 112:4a96133a1311 | 225 | } |
Kovalev_D | 113:8be429494918 | 226 | |
Kovalev_D | 190:289514f730ee | 227 | void ShowMod(void)//технологическая функция для просмотра в ориджине мод на всем диапазпне цап |
Kovalev_D | 158:0c8342e1837a | 228 | { |
Kovalev_D | 158:0c8342e1837a | 229 | |
Kovalev_D | 158:0c8342e1837a | 230 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 158:0c8342e1837a | 231 | //////////////////////////////////смотрим все моды///////////////////////////////////////////////// |
Kovalev_D | 158:0c8342e1837a | 232 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 197:7a05523bf588 | 233 | if(dispersion>5) |
Kovalev_D | 197:7a05523bf588 | 234 | { |
Kovalev_D | 197:7a05523bf588 | 235 | if( (Gyro.PLC_Lern<60000)&&(Gyro.PLC_Error2Mode >1))//пробигаем по нескольким значениям цап(60*0х3с=0хВВ8) для определения максимальной амплитуды. |
Kovalev_D | 158:0c8342e1837a | 236 | { |
Kovalev_D | 158:0c8342e1837a | 237 | Gyro.PLC_Error2Mode--; |
Kovalev_D | 158:0c8342e1837a | 238 | Gyro.PLC_Lern++; |
Kovalev_D | 197:7a05523bf588 | 239 | Spi.DAC_B += tempstrafe*side; |
Kovalev_D | 197:7a05523bf588 | 240 | if(side>0)side=(-1); |
Kovalev_D | 197:7a05523bf588 | 241 | else side = 1; |
Kovalev_D | 197:7a05523bf588 | 242 | tempstrafe-=40; |
Kovalev_D | 197:7a05523bf588 | 243 | dispersion=0; |
Kovalev_D | 168:f4a6abb18358 | 244 | } |
Kovalev_D | 197:7a05523bf588 | 245 | else {Gyro.LogPLC=0;} |
Kovalev_D | 197:7a05523bf588 | 246 | } |
Kovalev_D | 197:7a05523bf588 | 247 | else dispersion++; |
Kovalev_D | 197:7a05523bf588 | 248 | sprintf((Time),"%d %d %d %d \r\n", Gyro.CuruAngle, Spi.DAC_B, Gyro.AD_Slow, Gyro.Termo); |
Kovalev_D | 197:7a05523bf588 | 249 | Gyro.CuruAngle=0; |
Kovalev_D | 197:7a05523bf588 | 250 | WriteCon(Time); |
Kovalev_D | 158:0c8342e1837a | 251 | } |
Kovalev_D | 144:083c667ba848 | 252 | |
Kovalev_D | 144:083c667ba848 | 253 | |
Kovalev_D | 144:083c667ba848 | 254 | |
Kovalev_D | 205:775d54fdf646 | 255 | /* |
Kovalev_D | 144:083c667ba848 | 256 | |
Kovalev_D | 195:bcc769f5292b | 257 | void PlcRegul(void) |
Kovalev_D | 195:bcc769f5292b | 258 | //Программа расчет напряжения для модулятора(//выполняется 1.25 микросек.) |
Kovalev_D | 195:bcc769f5292b | 259 | { |
Kovalev_D | 195:bcc769f5292b | 260 | |
Kovalev_D | 195:bcc769f5292b | 261 | int templm=0; |
Kovalev_D | 157:1069c80f4944 | 262 | int PLC_In; |
Kovalev_D | 157:1069c80f4944 | 263 | int tempDac; |
Kovalev_D | 197:7a05523bf588 | 264 | if(start<=5) |
Kovalev_D | 195:bcc769f5292b | 265 | { |
Kovalev_D | 196:f76dbc081e63 | 266 | if(ttt) |
Kovalev_D | 196:f76dbc081e63 | 267 | {// +25 С° |
Kovalev_D | 196:f76dbc081e63 | 268 | templm = (Gyro.TermoNKU-Gyro.Termo); //дельта |
Kovalev_D | 195:bcc769f5292b | 269 | if(templm>0) Gyro.Ktermo=1; |
Kovalev_D | 195:bcc769f5292b | 270 | else Gyro.Ktermo=0; |
Kovalev_D | 195:bcc769f5292b | 271 | Spi.DAC_B+=templm; |
Kovalev_D | 196:f76dbc081e63 | 272 | ttt=0; |
Kovalev_D | 195:bcc769f5292b | 273 | } |
Kovalev_D | 195:bcc769f5292b | 274 | } |
Kovalev_D | 196:f76dbc081e63 | 275 | |
Kovalev_D | 196:f76dbc081e63 | 276 | if(!(Gyro.PinReg & PinRegBitL) && (start>0)) start--; |
Kovalev_D | 196:f76dbc081e63 | 277 | |
Kovalev_D | 196:f76dbc081e63 | 278 | else if((start==0)) |
Kovalev_D | 193:a0fe8bfc97e4 | 279 | { |
Kovalev_D | 197:7a05523bf588 | 280 | |
Kovalev_D | 193:a0fe8bfc97e4 | 281 | PLC_In = Gyro.AD_Slow; //выбираем даные для фильтрации |
Kovalev_D | 191:40028201ddad | 282 | Gyro.PLC_Delta = PLC_In - Gyro.PLC_Old; //узнаем приращение |
Kovalev_D | 191:40028201ddad | 283 | Gyro.PLC_DeltaADD = Gyro.PLC_Delta * Gyro.PLC_ADC_DOld; //приращение с учетом знака (и количества) прошлого приращения |
Kovalev_D | 191:40028201ddad | 284 | Gyro.PLC_Old = PLC_In; //запоминание значения |
Kovalev_D | 205:775d54fdf646 | 285 | if(Gyro.flagGph_W) |
Kovalev_D | 193:a0fe8bfc97e4 | 286 | { |
Kovalev_D | 193:a0fe8bfc97e4 | 287 | AD_MAX=0; |
Kovalev_D | 193:a0fe8bfc97e4 | 288 | Gyro.flagGph_W--; |
Kovalev_D | 193:a0fe8bfc97e4 | 289 | Gyro.PLC_Error2Mode=3; |
Kovalev_D | 205:775d54fdf646 | 290 | } //если изменился коэфициент усиления ФД //3600 (размер моды порядка 3000) |
Kovalev_D | 193:a0fe8bfc97e4 | 291 | if((Gyro.PLC_Lern < 150) && (Gyro.PLC_Error2Mode != 0)) |
Kovalev_D | 193:a0fe8bfc97e4 | 292 | { //пробигаем по нескольким значениям цап(60*0х3с=0хВВ8) для определения максимальной амплитуды. |
Kovalev_D | 195:bcc769f5292b | 293 | |
Kovalev_D | 195:bcc769f5292b | 294 | if(Gyro.Ktermo)Spi.DAC_B += 0x3c; //добовляем в значение цапа 60 |
Kovalev_D | 195:bcc769f5292b | 295 | else Spi.DAC_B -= 0x3c; |
Kovalev_D | 193:a0fe8bfc97e4 | 296 | if(AD_MAX < PLC_In){AD_MAX = PLC_In;} //если максимальная амплитуда меньше текущей записываем новую максимальную амплитуду. |
Kovalev_D | 197:7a05523bf588 | 297 | else if ((AD_MAX>PLC_In)&&(AD_MAX>1550800000)) r++; //если текущая амплитуда меньше максимально найденной то инкрементируем счетчик. |
Kovalev_D | 193:a0fe8bfc97e4 | 298 | if (r>10) |
Kovalev_D | 193:a0fe8bfc97e4 | 299 | { |
Kovalev_D | 197:7a05523bf588 | 300 | Gyro.PLC_Lern=151; |
Kovalev_D | 193:a0fe8bfc97e4 | 301 | Gyro.PLC_Error2Mode=3; |
Kovalev_D | 191:40028201ddad | 302 | } //если текущая амплитуда меньше максимально найденной в течении 5 тактов то выходим из поиска |
Kovalev_D | 197:7a05523bf588 | 303 | Gyro.CuruAngle = 0; //не считаем угол пока ищем максивальную амплитуду. |
Kovalev_D | 197:7a05523bf588 | 304 | } //работает только первые ~30-40 секунд (37 сек). |
Kovalev_D | 193:a0fe8bfc97e4 | 305 | if (Gyro.PLC_Lern<160) Gyro.PLC_Lern++; |
Kovalev_D | 193:a0fe8bfc97e4 | 306 | |
Kovalev_D | 191:40028201ddad | 307 | if(AD_MAX < PLC_In) {AD_MAX = PLC_In; l=0;} //обновление максимального значения амплитуды обнуление счетчика малого понижения амплитуды. |
Kovalev_D | 191:40028201ddad | 308 | else l++; //инкрементируем счетчик малого понижения желаемой амплитуды (максимальной замеченной) |
Kovalev_D | 197:7a05523bf588 | 309 | if((l > 300)&&(Gyro.PLC_Error2Mode == 0)) {AD_MAX -= 2107200;k=15;l=0;} //если счетчик малого понижения амплитуды больше 100(аммплитуда не обновлялась 100 раз). m |
Kovalev_D | 197:7a05523bf588 | 310 | if ((k == 15)&&(Gyro.PLC_Lern > 150)) Spi.DAC_B += 75; //после уменьшения максимальной амплитуды двигаем шевелем цап |
Kovalev_D | 197:7a05523bf588 | 311 | else if((k == 1)&&(Gyro.PLC_Lern > 150)) {Spi.DAC_B -= 75; k=0;l=0;} //для быстрог поиска новог максимума. |
Kovalev_D | 195:bcc769f5292b | 312 | if(k>0)k--; |
Kovalev_D | 160:6170df6f5a5c | 313 | |
Kovalev_D | 191:40028201ddad | 314 | Gyro.PlC_MaxD=(unsigned int)(AD_MAX-PLC_In); //ищем разницу между желаемой и действительной амплитудами. |
Kovalev_D | 160:6170df6f5a5c | 315 | |
Kovalev_D | 205:775d54fdf646 | 316 | if(Gyro.ModJump==1) { ///прыжок с моды на моду. (-->) |
Kovalev_D | 197:7a05523bf588 | 317 | Gyro.OldCuruAngle = Gyro.CuruAngle; |
Kovalev_D | 197:7a05523bf588 | 318 | Gyro.ModJump=0; |
Kovalev_D | 197:7a05523bf588 | 319 | Spi.DAC_B += 4300; |
Kovalev_D | 197:7a05523bf588 | 320 | Gyro.PLC_Error2Mode=1; |
Kovalev_D | 197:7a05523bf588 | 321 | Gyro.StopCuruAngle=2; |
Kovalev_D | 197:7a05523bf588 | 322 | } |
Kovalev_D | 197:7a05523bf588 | 323 | |
Kovalev_D | 197:7a05523bf588 | 324 | if(Gyro.ModJump==2) { ///прыжок с моды на моду. (<--) |
Kovalev_D | 197:7a05523bf588 | 325 | Gyro.OldCuruAngle = Gyro.CuruAngle; |
Kovalev_D | 197:7a05523bf588 | 326 | Gyro.ModJump=0; |
Kovalev_D | 197:7a05523bf588 | 327 | Spi.DAC_B -= 5250; |
Kovalev_D | 197:7a05523bf588 | 328 | Gyro.PLC_Error2Mode=1; |
Kovalev_D | 197:7a05523bf588 | 329 | Gyro.StopCuruAngle=2; |
Kovalev_D | 197:7a05523bf588 | 330 | } |
Kovalev_D | 197:7a05523bf588 | 331 | |
Kovalev_D | 191:40028201ddad | 332 | if(Gyro.RgConA&0x8) { // если контур регулирования замкнут |
Kovalev_D | 191:40028201ddad | 333 | if ( Gyro.PLC_Error2Mode > 0) { Gyro.PLC_Error2Mode --; Gyro.PLC_ADC_DOld = 0;} // если ошибка(нахожление в двух модовом) |
Kovalev_D | 191:40028201ddad | 334 | else if ( Gyro.PLC_DeltaADD > 0) { Gyro.PLC_ADC_DOld = 1;} |
Kovalev_D | 191:40028201ddad | 335 | else if ( Gyro.PLC_DeltaADD < 0) { Gyro.PLC_ADC_DOld = -1;} |
Kovalev_D | 191:40028201ddad | 336 | else { Gyro.PLC_ADC_DOld = 1;} |
Kovalev_D | 157:1069c80f4944 | 337 | } |
Kovalev_D | 191:40028201ddad | 338 | else {Gyro.PLC_Error2Mode = 1; Gyro.PLC_DeltaADD = 0;} |
Kovalev_D | 191:40028201ddad | 339 | |
Kovalev_D | 191:40028201ddad | 340 | ///прыжок с моды на моду. |
Kovalev_D | 171:d227a6045305 | 341 | |
Kovalev_D | 197:7a05523bf588 | 342 | |
Kovalev_D | 197:7a05523bf588 | 343 | |
Kovalev_D | 197:7a05523bf588 | 344 | |
Kovalev_D | 190:289514f730ee | 345 | |
Kovalev_D | 191:40028201ddad | 346 | tempADC5=0x7fff-Spi.ADC5; |
Kovalev_D | 191:40028201ddad | 347 | // контур замкнут включен лазер |
Kovalev_D | 193:a0fe8bfc97e4 | 348 | if((Gyro.RgConA&0x8) && (tempADC5>1000)) |
Kovalev_D | 197:7a05523bf588 | 349 | { |
Kovalev_D | 197:7a05523bf588 | 350 | if(Gyro.PlC_MaxD>(50<<17)) { // 3 режим регулирования |
Kovalev_D | 172:ef7bf1663645 | 351 | tempDac=(unsigned int)(Gyro.PlC_MaxD>>19); |
Kovalev_D | 197:7a05523bf588 | 352 | if(tempDac>600) tempDac=600; //ограничение на регулирование если очень большая разница амплитуд |
Kovalev_D | 197:7a05523bf588 | 353 | Spi.DAC_B += Gyro.PLC_ADC_DOld * tempDac; //новое значение в цап (±1 * значение регулировки) |
Kovalev_D | 197:7a05523bf588 | 354 | tempDac = Gyro.PLC_ADC_DOld * tempDac; //используется только для выдачи |
Kovalev_D | 171:d227a6045305 | 355 | flagmod=3; |
Kovalev_D | 171:d227a6045305 | 356 | } |
Kovalev_D | 197:7a05523bf588 | 357 | else if(Gyro.PlC_MaxD>(12<<17)) { // 2 режим регулирования |
Kovalev_D | 172:ef7bf1663645 | 358 | tempDac=(unsigned int)(Gyro.PlC_MaxD>>19); |
Kovalev_D | 171:d227a6045305 | 359 | Spi.DAC_B += Gyro.PLC_ADC_DOld * (tempDac); |
Kovalev_D | 197:7a05523bf588 | 360 | tempDac = Gyro.PLC_ADC_DOld * (tempDac); //используется только для выдачи |
Kovalev_D | 171:d227a6045305 | 361 | flagmod=2; |
Kovalev_D | 171:d227a6045305 | 362 | } |
Kovalev_D | 205:775d54fdf646 | 363 | else if(Gyro.PlC_MaxD<(2<<17)) { //режим если дельта равна 0; |
Kovalev_D | 197:7a05523bf588 | 364 | tempDac=2; |
Kovalev_D | 171:d227a6045305 | 365 | Spi.DAC_B += Gyro.PLC_ADC_DOld * tempDac; |
Kovalev_D | 171:d227a6045305 | 366 | flagmod=0; |
Kovalev_D | 205:775d54fdf646 | 367 | } |
Kovalev_D | 171:d227a6045305 | 368 | else { |
Kovalev_D | 197:7a05523bf588 | 369 | tempDac=2; // 1 режим регулирования |
Kovalev_D | 171:d227a6045305 | 370 | Spi.DAC_B += Gyro.PLC_ADC_DOld *tempDac; |
Kovalev_D | 171:d227a6045305 | 371 | tempDac = Gyro.PLC_ADC_DOld * tempDac; |
Kovalev_D | 171:d227a6045305 | 372 | flagmod=1; |
Kovalev_D | 191:40028201ddad | 373 | } |
Kovalev_D | 197:7a05523bf588 | 374 | } |
Kovalev_D | 196:f76dbc081e63 | 375 | |
Kovalev_D | 195:bcc769f5292b | 376 | |
Kovalev_D | 197:7a05523bf588 | 377 | if ( Spi.DAC_B < 15300 ) {Spi.DAC_B = 32000; Gyro.PLC_Error2Mode = 5; Gyro.PLC_DeltaADD = 0;} //проверка на переваливание за границу. |
Kovalev_D | 195:bcc769f5292b | 378 | else if ( Spi.DAC_B > 53000) {Spi.DAC_B = 32000; Gyro.PLC_Error2Mode = 5; Gyro.PLC_DeltaADD = 0;} |
Kovalev_D | 195:bcc769f5292b | 379 | |
Kovalev_D | 191:40028201ddad | 380 | } |
Kovalev_D | 197:7a05523bf588 | 381 | if(Gyro.StopCuruAngle) {Gyro.CuruAngle = Gyro.OldCuruAngle; Gyro.StopCuruAngle--;} |
Kovalev_D | 157:1069c80f4944 | 382 | /////////////////////// |
Kovalev_D | 157:1069c80f4944 | 383 | //////////лог////////// |
Kovalev_D | 157:1069c80f4944 | 384 | /////////////////////// |
Kovalev_D | 157:1069c80f4944 | 385 | if(Gyro.LogPLC==1) { |
Kovalev_D | 205:775d54fdf646 | 386 | |
Kovalev_D | 197:7a05523bf588 | 387 | sprintf((Time),"%d %d %d %d %d %d %d %d %d \r\n",Gyro.CuruAngle, Gyro.Frq, Gyro.MaxAmp, Spi.DAC_B, tempDac, flagmod, AD_MAX, PLC_In, Gyro.Termo);//выдаем в терминал для постройки граффика регулировки периметра. |
Kovalev_D | 196:f76dbc081e63 | 388 | Gyro.CuruAngle=0; |
Kovalev_D | 196:f76dbc081e63 | 389 | Gyro.tempdelta=0; |
Kovalev_D | 196:f76dbc081e63 | 390 | Gyro.tempdelta2=0; |
Kovalev_D | 141:c6de20b9b483 | 391 | WriteCon(Time); |
Kovalev_D | 205:775d54fdf646 | 392 | |
Kovalev_D | 157:1069c80f4944 | 393 | } |
Kovalev_D | 157:1069c80f4944 | 394 | } |
Kovalev_D | 141:c6de20b9b483 | 395 | |
Kovalev_D | 141:c6de20b9b483 | 396 | |
Kovalev_D | 141:c6de20b9b483 | 397 | |
Kovalev_D | 205:775d54fdf646 | 398 | */ |
Kovalev_D | 141:c6de20b9b483 | 399 | /* |
Kovalev_D | 157:1069c80f4944 | 400 | |
Kovalev_D | 116:66f1f0ff2dab | 401 | void PlcRegul(void) //Программа расчет напряжения для модулятора |
Kovalev_D | 116:66f1f0ff2dab | 402 | { |
Kovalev_D | 116:66f1f0ff2dab | 403 | int PLC_In; |
Kovalev_D | 116:66f1f0ff2dab | 404 | |
igor_v | 127:6a7472d67804 | 405 | |
igor_v | 127:6a7472d67804 | 406 | PLC_In = Gyro.AD_Slow; //выбираем даные для фильтрации |
Kovalev_D | 116:66f1f0ff2dab | 407 | // PLC_In = Gyro.AD_Fast; |
Kovalev_D | 128:1e4675a36c93 | 408 | //или+,или-(знак) |
Kovalev_D | 128:1e4675a36c93 | 409 | Gyro.PLC_Delta = PLC_In - Gyro.PLC_Old; // узнаем приращение |
Kovalev_D | 128:1e4675a36c93 | 410 | // (знак) * (то на что инкрементировали цап) |
Kovalev_D | 128:1e4675a36c93 | 411 | Gyro.PLC_DeltaADD = Gyro.PLC_Delta * Gyro.PLC_ADC_DOld; //приращение с учетом знака (и количества) прошлого приращения |
Kovalev_D | 128:1e4675a36c93 | 412 | Gyro.PLC_Old = PLC_In; // запоминание значения |
igor_v | 127:6a7472d67804 | 413 | |
Kovalev_D | 128:1e4675a36c93 | 414 | if(Gyro.RgConA&0x2) // если включон контур регулирования |
Kovalev_D | 157:1069c80f4944 | 415 | { |
Kovalev_D | 140:1fbf117fc120 | 416 | if (Gyro.PLC_Error2Mode > 0) {Gyro.PLC_Error2Mode --; Gyro.PLC_ADC_DOld = 0; } // если ошибка(нахожление в двух модовом) |
Kovalev_D | 128:1e4675a36c93 | 417 | else if ( Gyro.PLC_Delta > (3000 * 65536)) {Spi.DAC_B += 2500; Gyro.PLC_Error2Mode = 5; Gyro.PLC_ADC_DOld = 0;} // проверка на двух модовость |
Kovalev_D | 128:1e4675a36c93 | 418 | else if ( Gyro.PLC_Delta < (-3000 * 65536)) {Spi.DAC_B += 2500; Gyro.PLC_Error2Mode = 5; Gyro.PLC_ADC_DOld = 0;} |
Kovalev_D | 157:1069c80f4944 | 419 | |
Kovalev_D | 157:1069c80f4944 | 420 | else if (Gyro.PLC_DeltaADD > 0) |
igor_v | 127:6a7472d67804 | 421 | { |
Kovalev_D | 157:1069c80f4944 | 422 | |
Kovalev_D | 159:38f39c0c143f | 423 | // Gyro.PLC_ADC_DOld = (Gyro.PLC_DeltaADD /6553600 )+1; |
Kovalev_D | 128:1e4675a36c93 | 424 | Gyro.PLC_ADC_DOld = 1; |
igor_v | 127:6a7472d67804 | 425 | } |
Kovalev_D | 157:1069c80f4944 | 426 | else if (Gyro.PLC_DeltaADD < 0) |
igor_v | 127:6a7472d67804 | 427 | { |
igor_v | 127:6a7472d67804 | 428 | |
Kovalev_D | 128:1e4675a36c93 | 429 | // Gyro.PLC_ADC_DOld = (Gyro.PLC_DeltaADD /6553600 )-1; |
Kovalev_D | 128:1e4675a36c93 | 430 | Gyro.PLC_ADC_DOld = -1; |
igor_v | 127:6a7472d67804 | 431 | } |
igor_v | 127:6a7472d67804 | 432 | else |
igor_v | 127:6a7472d67804 | 433 | { |
Kovalev_D | 128:1e4675a36c93 | 434 | Gyro.PLC_ADC_DOld = 1; |
igor_v | 127:6a7472d67804 | 435 | } |
igor_v | 127:6a7472d67804 | 436 | } |
Kovalev_D | 157:1069c80f4944 | 437 | else |
igor_v | 127:6a7472d67804 | 438 | { |
Kovalev_D | 128:1e4675a36c93 | 439 | Gyro.PLC_Error2Mode = 1; Gyro.PLC_DeltaADD = 0; |
igor_v | 127:6a7472d67804 | 440 | } |
Kovalev_D | 157:1069c80f4944 | 441 | |
Kovalev_D | 157:1069c80f4944 | 442 | |
Kovalev_D | 141:c6de20b9b483 | 443 | Spi.DAC_B += Gyro.PLC_ADC_DOld * 16; |
Kovalev_D | 157:1069c80f4944 | 444 | |
Kovalev_D | 157:1069c80f4944 | 445 | |
Kovalev_D | 128:1e4675a36c93 | 446 | if ( Spi.DAC_B < 1000 ) {Spi.DAC_B = 32000; Gyro.PLC_Error2Mode = 5; Gyro.PLC_DeltaADD = 0;} |
Kovalev_D | 128:1e4675a36c93 | 447 | if ( Spi.DAC_B > 63000 ) {Spi.DAC_B = 32000; Gyro.PLC_Error2Mode = 5; Gyro.PLC_DeltaADD = 0;} |
Kovalev_D | 157:1069c80f4944 | 448 | |
Kovalev_D | 141:c6de20b9b483 | 449 | if(Gyro.LogPLC==1) |
Kovalev_D | 141:c6de20b9b483 | 450 | { |
Kovalev_D | 157:1069c80f4944 | 451 | sprintf((Time),"%d %d %d %d %d %d\r\n", Spi.DAC_B, temp9,flagmod, AD_MAX, Gyro.AD_Slow, k);//выдаем в терминал для постройки граффика регулировки периметра. |
Kovalev_D | 157:1069c80f4944 | 452 | WriteCon(Time); |
Kovalev_D | 141:c6de20b9b483 | 453 | } |
Kovalev_D | 157:1069c80f4944 | 454 | |
Kovalev_D | 128:1e4675a36c93 | 455 | } |
Kovalev_D | 116:66f1f0ff2dab | 456 | |
Kovalev_D | 116:66f1f0ff2dab | 457 | |
Kovalev_D | 191:40028201ddad | 458 | *//* |
Kovalev_D | 157:1069c80f4944 | 459 | void PlcRegul_old(void) // на всякий случай |
Kovalev_D | 112:4a96133a1311 | 460 | { |
Kovalev_D | 157:1069c80f4944 | 461 | int Delta; |
Kovalev_D | 157:1069c80f4944 | 462 | |
Kovalev_D | 157:1069c80f4944 | 463 | ADD_AMP+=Spi.ADC5; |
Kovalev_D | 157:1069c80f4944 | 464 | Count_AMP++; |
Kovalev_D | 157:1069c80f4944 | 465 | if(Count_AMP>=(32*32+8)) { |
Kovalev_D | 157:1069c80f4944 | 466 | Delta = ADD_AMP - Cur_Amp; |
Kovalev_D | 157:1069c80f4944 | 467 | |
Kovalev_D | 157:1069c80f4944 | 468 | if(Gyro.RgConA&0x2) { |
Kovalev_D | 157:1069c80f4944 | 469 | if (Znak_Amp > 1) { |
Kovalev_D | 157:1069c80f4944 | 470 | Znak_Amp --; |
Kovalev_D | 157:1069c80f4944 | 471 | } else if ( Delta > 30000000 ) { |
Kovalev_D | 157:1069c80f4944 | 472 | AD_Regul += 5000000; |
Kovalev_D | 157:1069c80f4944 | 473 | Znak_Amp = 5; |
Kovalev_D | 157:1069c80f4944 | 474 | } else if ( Delta < (-3000000)) { |
Kovalev_D | 157:1069c80f4944 | 475 | AD_Regul += 5000000; |
Kovalev_D | 157:1069c80f4944 | 476 | Znak_Amp = 5; |
Kovalev_D | 157:1069c80f4944 | 477 | } else if ((Delta * Znak_Amp) > 0) { |
Kovalev_D | 157:1069c80f4944 | 478 | Znak_Amp = 1; |
Kovalev_D | 157:1069c80f4944 | 479 | AD_Regul -= (Delta * Znak_Amp * 10); |
Kovalev_D | 157:1069c80f4944 | 480 | } else { |
Kovalev_D | 157:1069c80f4944 | 481 | Znak_Amp = -1; |
Kovalev_D | 157:1069c80f4944 | 482 | AD_Regul -= (Delta * Znak_Amp * 10); |
Kovalev_D | 157:1069c80f4944 | 483 | } |
Kovalev_D | 157:1069c80f4944 | 484 | |
Kovalev_D | 157:1069c80f4944 | 485 | Spi.DAC_B = (AD_Regul + 0x1fffffff)/65536; |
Kovalev_D | 157:1069c80f4944 | 486 | } |
Kovalev_D | 157:1069c80f4944 | 487 | Cur_Amp=ADD_AMP; |
Kovalev_D | 157:1069c80f4944 | 488 | Count_AMP=0; |
Kovalev_D | 157:1069c80f4944 | 489 | ADD_AMP=0; |
Kovalev_D | 157:1069c80f4944 | 490 | } |
Kovalev_D | 157:1069c80f4944 | 491 | |
igor_v | 110:6406b7ac0442 | 492 | } |
igor_v | 110:6406b7ac0442 | 493 | |
igor_v | 110:6406b7ac0442 | 494 | |
Kovalev_D | 191:40028201ddad | 495 | */ |
Kovalev_D | 116:66f1f0ff2dab | 496 | |
Kovalev_D | 112:4a96133a1311 | 497 | void DAC_OutPut(void)//выдача в цапы |
igor_v | 0:8ad47e2b6f00 | 498 | { |
Kovalev_D | 208:19150d2b528f | 499 | if(Gyro.RgConA&0x10) Modulator(); |
Kovalev_D | 157:1069c80f4944 | 500 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 501 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 502 | LPC_SSP0->DR=0x5555; |
igor_v | 0:8ad47e2b6f00 | 503 | |
igor_v | 110:6406b7ac0442 | 504 | if (CountV31 & 1) { //если нечетный такт то |
Kovalev_D | 197:7a05523bf588 | 505 | LPC_SSP0->DR = WRITE_DAC0; //e.команда для ЦАП_0 передавать. |
igor_v | 31:c783288001b5 | 506 | LPC_SSP0->DR = (Spi.DAC_A); //e. передача 12 бит |
Kovalev_D | 157:1069c80f4944 | 507 | } else { //если такт четный. |
Kovalev_D | 157:1069c80f4944 | 508 | LPC_SSP0->DR = WRITE_DAC1 ; //e.команда для ЦАП_1 передавать. |
Kovalev_D | 205:775d54fdf646 | 509 | LPC_SSP0->DR = (Spi.DAC_B); |
Kovalev_D | 208:19150d2b528f | 510 | // t//emp9 = Spi.DAC_B;//для вывода. |
Kovalev_D | 205:775d54fdf646 | 511 | /* |
Kovalev_D | 205:775d54fdf646 | 512 | switch( Gyro.StrayPLC_flag) { |
Kovalev_D | 157:1069c80f4944 | 513 | |
Kovalev_D | 157:1069c80f4944 | 514 | case 0://режим без воздействия |
Kovalev_D | 157:1069c80f4944 | 515 | LPC_SSP0->DR = (Spi.DAC_B); |
Kovalev_D | 157:1069c80f4944 | 516 | temp9=Spi.DAC_B; |
Kovalev_D | 157:1069c80f4944 | 517 | break; |
Kovalev_D | 205:775d54fdf646 | 518 | case 1://малое воздействие + |
Kovalev_D | 157:1069c80f4944 | 519 | temp9=Spi.DAC_B + Gyro.StrayPLC_Pls; |
Kovalev_D | 157:1069c80f4944 | 520 | LPC_SSP0->DR = temp9; |
Kovalev_D | 157:1069c80f4944 | 521 | break; |
Kovalev_D | 157:1069c80f4944 | 522 | |
Kovalev_D | 157:1069c80f4944 | 523 | case 3://малое воздействие - |
Kovalev_D | 157:1069c80f4944 | 524 | temp9=Spi.DAC_B + Gyro.StrayPLC_Mns; |
Kovalev_D | 157:1069c80f4944 | 525 | LPC_SSP0->DR = temp9; |
Kovalev_D | 157:1069c80f4944 | 526 | break; |
Kovalev_D | 157:1069c80f4944 | 527 | |
Kovalev_D | 157:1069c80f4944 | 528 | case 2://большое воздействие + |
Kovalev_D | 157:1069c80f4944 | 529 | temp9=Spi.DAC_B + Gyro.StrayPLC_2Mode; |
Kovalev_D | 157:1069c80f4944 | 530 | LPC_SSP0->DR = temp9;//вгоняем в многомодовый режим |
Kovalev_D | 157:1069c80f4944 | 531 | break; |
Kovalev_D | 205:775d54fdf646 | 532 | |
Kovalev_D | 205:775d54fdf646 | 533 | }*/ |
Kovalev_D | 157:1069c80f4944 | 534 | // LPC_SSP0->DR = Spi.DAC_B; //e. передача 12 бит |
Kovalev_D | 157:1069c80f4944 | 535 | |
igor_v | 31:c783288001b5 | 536 | } |
Kovalev_D | 112:4a96133a1311 | 537 | } |
Kovalev_D | 112:4a96133a1311 | 538 | |
Kovalev_D | 112:4a96133a1311 | 539 | |
Kovalev_D | 113:8be429494918 | 540 | |
Kovalev_D | 113:8be429494918 | 541 | |
Kovalev_D | 113:8be429494918 | 542 | |
Kovalev_D | 113:8be429494918 | 543 | |
Kovalev_D | 113:8be429494918 | 544 | |
Kovalev_D | 113:8be429494918 | 545 | |
Kovalev_D | 113:8be429494918 | 546 | |
Kovalev_D | 113:8be429494918 | 547 | |
Kovalev_D | 113:8be429494918 | 548 | |
Kovalev_D | 113:8be429494918 | 549 | |
Kovalev_D | 113:8be429494918 | 550 | |
Kovalev_D | 113:8be429494918 | 551 | |
Kovalev_D | 113:8be429494918 | 552 | |
Kovalev_D | 113:8be429494918 | 553 | |
Kovalev_D | 113:8be429494918 | 554 | |
Kovalev_D | 113:8be429494918 | 555 | |
Kovalev_D | 113:8be429494918 | 556 | |
Kovalev_D | 113:8be429494918 | 557 | |
Kovalev_D | 113:8be429494918 | 558 | |
Kovalev_D | 113:8be429494918 | 559 | |
Kovalev_D | 113:8be429494918 | 560 | |
Kovalev_D | 113:8be429494918 | 561 | |
Kovalev_D | 113:8be429494918 | 562 | |
Kovalev_D | 113:8be429494918 | 563 | |
Kovalev_D | 113:8be429494918 | 564 | |
Kovalev_D | 113:8be429494918 | 565 | |
Kovalev_D | 113:8be429494918 | 566 | |
Kovalev_D | 113:8be429494918 | 567 | |
Kovalev_D | 113:8be429494918 | 568 | /* |
Kovalev_D | 112:4a96133a1311 | 569 | void SPI_Exchange(void) |
Kovalev_D | 112:4a96133a1311 | 570 | { |
Kovalev_D | 112:4a96133a1311 | 571 | unsigned int DummySPI; |
Kovalev_D | 157:1069c80f4944 | 572 | |
Kovalev_D | 112:4a96133a1311 | 573 | |
Kovalev_D | 112:4a96133a1311 | 574 | Spi.ADC5 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 575 | Spi.ADC4 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 576 | Spi.ADC3 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 577 | Spi.ADC2 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 578 | Spi.ADC1 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 579 | |
Kovalev_D | 112:4a96133a1311 | 580 | Input.ArrayIn[2]= Spi.ADC5; |
Kovalev_D | 157:1069c80f4944 | 581 | |
Kovalev_D | 112:4a96133a1311 | 582 | DAC_OutPut(); |
igor_v | 0:8ad47e2b6f00 | 583 | |
Kovalev_D | 99:3d8f206ceac2 | 584 | // LPC_DAC->CR = (((SinPLC[CountV64]*35/5)+24300));// модулятор |
Kovalev_D | 112:4a96133a1311 | 585 | |
Kovalev_D | 89:a0d344db227e | 586 | while (LPC_SSP0->SR & RX_SSP_notEMPT) //если буфер SPI не пуст. |
Kovalev_D | 89:a0d344db227e | 587 | DummySPI = LPC_SSP0->DR; //очистить буфер. |
igor_v | 31:c783288001b5 | 588 | |
Kovalev_D | 112:4a96133a1311 | 589 | //заполнение буферов еденичных значений АЦП. |
Kovalev_D | 157:1069c80f4944 | 590 | Buff_ADC_1 [CountV31] = Spi.ADC1; |
Kovalev_D | 112:4a96133a1311 | 591 | Buff_ADC_2 [CountV31] = Spi.ADC2; |
Kovalev_D | 112:4a96133a1311 | 592 | Buff_ADC_3 [CountV31] = Spi.ADC3; |
Kovalev_D | 112:4a96133a1311 | 593 | Buff_ADC_4 [CountV31] = Spi.ADC4; |
Kovalev_D | 95:dd51e577e114 | 594 | Buff_ADC_5 [CountV255] = Spi.ADC5; // ампл ацп. |
igor_v | 110:6406b7ac0442 | 595 | |
Kovalev_D | 157:1069c80f4944 | 596 | |
igor_v | 110:6406b7ac0442 | 597 | Temp_AMP64P += Buff_ADC_5[CountV255]; |
Kovalev_D | 96:1c8536458119 | 598 | Temp_AMP64P -= Buff_ADC_5[(CountV255-64) & 0xff]; // заполнение буфера накопленых приращений за 8 тактов |
Kovalev_D | 96:1c8536458119 | 599 | Buff_AMP64P[CountV255] = (unsigned int) (Temp_AMP64P); |
Kovalev_D | 96:1c8536458119 | 600 | |
igor_v | 31:c783288001b5 | 601 | |
Kovalev_D | 47:d902ef6f7564 | 602 | Temp_ADC_2 += Buff_ADC_2[CountV31]; |
Kovalev_D | 47:d902ef6f7564 | 603 | Temp_ADC_2 -= Buff_ADC_2[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 604 | |
Kovalev_D | 47:d902ef6f7564 | 605 | Temp_ADC_3 += Buff_ADC_3[CountV31]; |
Kovalev_D | 95:dd51e577e114 | 606 | Temp_ADC_3 -= Buff_ADC_3[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 607 | |
Kovalev_D | 47:d902ef6f7564 | 608 | Temp_ADC_4 += Buff_ADC_4[CountV31]; |
Kovalev_D | 47:d902ef6f7564 | 609 | Temp_ADC_4 -= Buff_ADC_4[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 610 | |
igor_v | 31:c783288001b5 | 611 | Temp_ADC_5 += Buff_ADC_1[CountV255]; |
igor_v | 31:c783288001b5 | 612 | Temp_ADC_5 -= Buff_ADC_1[(CountV255-32) & 0xff]; |
Kovalev_D | 112:4a96133a1311 | 613 | Spi.PLC_NewData=1; |
Kovalev_D | 113:8be429494918 | 614 | }*/ |