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