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