![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
SPI.c@159:38f39c0c143f, 2016-05-13 (annotated)
- Committer:
- Kovalev_D
- Date:
- Fri May 13 11:01:16 2016 +0000
- Revision:
- 159:38f39c0c143f
- Parent:
- 158:0c8342e1837a
- Child:
- 160:6170df6f5a5c
plc
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; |
igor_v | 31:c783288001b5 | 5 | |
Kovalev_D | 153:7086895c6ee3 | 6 | int ttt = 0; |
Kovalev_D | 99:3d8f206ceac2 | 7 | unsigned int Count_AMP, ADD_AMP, Cur_Amp; |
Kovalev_D | 99:3d8f206ceac2 | 8 | int Znak_Amp; |
Kovalev_D | 109:ee0cff33ad3b | 9 | int AD_Regul = 0; |
Kovalev_D | 141:c6de20b9b483 | 10 | int temp9; |
Kovalev_D | 148:7ce8c1fd00f7 | 11 | int AD_MAX=0; |
Kovalev_D | 150:29c9f7671bac | 12 | int k=0,l=0; |
Kovalev_D | 152:cff1321ab25e | 13 | int flagmod=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 | 95:dd51e577e114 | 21 | unsigned int Buff_ADC_1 [32]; |
Kovalev_D | 95:dd51e577e114 | 22 | unsigned int Buff_ADC_2 [32]; |
Kovalev_D | 95:dd51e577e114 | 23 | unsigned int Buff_ADC_3 [32]; |
Kovalev_D | 95:dd51e577e114 | 24 | unsigned int Buff_ADC_4 [32]; |
igor_v | 51:81f47b817071 | 25 | |
igor_v | 31:c783288001b5 | 26 | unsigned int Buff_ADC_5 [256]; |
igor_v | 31:c783288001b5 | 27 | unsigned int Buff_AMP [256]; |
Kovalev_D | 96:1c8536458119 | 28 | unsigned int Buff_AMP64P [256]; |
igor_v | 31:c783288001b5 | 29 | unsigned int SinPLC[64]= {1023, 1016, 1006, 993, 976, 954, 904, 874, 841, 806, 768, 728, |
igor_v | 31:c783288001b5 | 30 | 687, 645, 601, 557, 500, 379, 337, 296, 256, 219, 183, 150, |
igor_v | 31:c783288001b5 | 31 | 120, 93, 69, 48, 31, 18, 8, 0, 8, 18, 31, 48, |
igor_v | 31:c783288001b5 | 32 | 69, 93, 120, 150, 183, 219, 256, 296, 337, 379, 468, 512, 557, |
igor_v | 31:c783288001b5 | 33 | 601, 645, 687, 728, 768, 806, 841, 874, 904, 954, 976, 993, 1006, |
igor_v | 31:c783288001b5 | 34 | 1016, 1023 |
igor_v | 31:c783288001b5 | 35 | }; |
Kovalev_D | 86:398da56ef751 | 36 | |
igor_v | 110:6406b7ac0442 | 37 | |
igor_v | 110:6406b7ac0442 | 38 | |
Kovalev_D | 147:1aed74f19a8f | 39 | void ADS_Acum(void) |
Kovalev_D | 147:1aed74f19a8f | 40 | { |
Kovalev_D | 157:1069c80f4944 | 41 | // можно апихнкть в функцию |
Kovalev_D | 157:1069c80f4944 | 42 | Spi.ADC_NewData = 0; |
Kovalev_D | 157:1069c80f4944 | 43 | Gyro.Termo = Spi.ADC1; |
Kovalev_D | 157:1069c80f4944 | 44 | Gyro.In1 = Spi.ADC2; |
Kovalev_D | 157:1069c80f4944 | 45 | Gyro.In2 = Spi.ADC3; |
Kovalev_D | 157:1069c80f4944 | 46 | Gyro.DeltaT = Spi.ADC4; |
Kovalev_D | 157:1069c80f4944 | 47 | TempA = (0x7fff - Spi.ADC5) << 1; // перевернем знак и умножим на два (было 32000...0 стало 0 ...64000) |
Kovalev_D | 158:0c8342e1837a | 48 | TempTermLM = /*(0x7fff -*/ Spi.ADC1/*) << 1*/; |
Kovalev_D | 157:1069c80f4944 | 49 | Gyro.ADF_Accum += TempA; |
Kovalev_D | 157:1069c80f4944 | 50 | Gyro.ADS_Accum += TempA; |
Kovalev_D | 158:0c8342e1837a | 51 | Gyro.ADS_AccumTermLM+=TempTermLM; |
Kovalev_D | 157:1069c80f4944 | 52 | Gyro.ADF_Count ++; |
Kovalev_D | 157:1069c80f4944 | 53 | Gyro.ADS_Count ++; |
Kovalev_D | 147:1aed74f19a8f | 54 | |
Kovalev_D | 157:1069c80f4944 | 55 | if (Gyro.ADF_Count > 15) { // если прошло 16 тактов виброподвеса |
Kovalev_D | 157:1069c80f4944 | 56 | Gyro.AD_Fast = Gyro.ADF_Accum << 12; //обновляем данные и приводим в один масштаб |
Kovalev_D | 157:1069c80f4944 | 57 | Gyro.ADF_Count = 0;// |
Kovalev_D | 157:1069c80f4944 | 58 | Gyro.ADF_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 59 | Gyro.ADF_NewData = 1; |
Kovalev_D | 157:1069c80f4944 | 60 | } |
Kovalev_D | 157:1069c80f4944 | 61 | if (Gyro.ADS_Count > 255) { // если прошло 256 тактов виброподвеса |
Kovalev_D | 157:1069c80f4944 | 62 | Gyro.AD_Slow = Gyro.ADS_Accum << 8; //обновляем данные и приводим в один масштаб |
Kovalev_D | 158:0c8342e1837a | 63 | Gyro.TermLM = Gyro.ADS_AccumTermLM << 3; |
Kovalev_D | 157:1069c80f4944 | 64 | Gyro.ADS_Count = 0; |
Kovalev_D | 157:1069c80f4944 | 65 | Gyro.ADS_Accum = 0; |
Kovalev_D | 158:0c8342e1837a | 66 | Gyro.ADS_AccumTermLM=0; |
Kovalev_D | 157:1069c80f4944 | 67 | Gyro.ADS_NewData = 1; |
Kovalev_D | 158:0c8342e1837a | 68 | |
Kovalev_D | 157:1069c80f4944 | 69 | } |
Kovalev_D | 147:1aed74f19a8f | 70 | } |
igor_v | 110:6406b7ac0442 | 71 | |
igor_v | 114:5cc38a53d8a7 | 72 | void SPI_Exchange(void) // новая функция чтения, в нецй не должно быть ничего лишнего |
Kovalev_D | 157:1069c80f4944 | 73 | { |
Kovalev_D | 157:1069c80f4944 | 74 | unsigned int DummySPI; |
Kovalev_D | 157:1069c80f4944 | 75 | Spi.ADC5_Accum += LPC_SSP0->DR; // Чтение АЦП |
igor_v | 110:6406b7ac0442 | 76 | Spi.ADC4_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 77 | Spi.ADC3_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 78 | Spi.ADC2_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 79 | Spi.ADC1_Accum += LPC_SSP0->DR; |
Kovalev_D | 157:1069c80f4944 | 80 | while (LPC_SSP0->SR & RX_SSP_notEMPT) { |
Kovalev_D | 157:1069c80f4944 | 81 | DummySPI = LPC_SSP0->DR; //если буфер SPI не пуст.//очистить буфер. |
Kovalev_D | 157:1069c80f4944 | 82 | } |
Kovalev_D | 157:1069c80f4944 | 83 | |
Kovalev_D | 157:1069c80f4944 | 84 | |
Kovalev_D | 112:4a96133a1311 | 85 | DAC_OutPut(); |
Kovalev_D | 157:1069c80f4944 | 86 | |
Kovalev_D | 157:1069c80f4944 | 87 | if (CountV31 == 0) { // просто фильтруем по 32 точкам. |
Kovalev_D | 157:1069c80f4944 | 88 | // выставояем бит, что есть новы данные |
Kovalev_D | 157:1069c80f4944 | 89 | Spi.ADC1 = Spi.ADC1_Accum >> 5; // подгоотавливаем данные (в той эе сетке) те ADC1 0..65535 |
Kovalev_D | 157:1069c80f4944 | 90 | Spi.ADC2 = Spi.ADC2_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 91 | Spi.ADC3 = Spi.ADC3_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 92 | Spi.ADC4 = Spi.ADC4_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 93 | Spi.ADC5 = Spi.ADC5_Accum >> 5; |
Kovalev_D | 157:1069c80f4944 | 94 | Spi.ADC1_Accum = 0; // сбрасывкем аккамулятор |
Kovalev_D | 157:1069c80f4944 | 95 | Spi.ADC2_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 96 | Spi.ADC3_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 97 | Spi.ADC4_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 98 | Spi.ADC5_Accum = 0; |
Kovalev_D | 157:1069c80f4944 | 99 | Spi.ADC_NewData = 1; |
Kovalev_D | 157:1069c80f4944 | 100 | } |
Kovalev_D | 128:1e4675a36c93 | 101 | |
Kovalev_D | 113:8be429494918 | 102 | |
Kovalev_D | 112:4a96133a1311 | 103 | } |
Kovalev_D | 113:8be429494918 | 104 | |
Kovalev_D | 141:c6de20b9b483 | 105 | |
Kovalev_D | 141:c6de20b9b483 | 106 | |
Kovalev_D | 159:38f39c0c143f | 107 | void ShowMod(void)//технологическая функция для просмотра мод на всем диапазпне цап |
Kovalev_D | 158:0c8342e1837a | 108 | { |
Kovalev_D | 158:0c8342e1837a | 109 | |
Kovalev_D | 158:0c8342e1837a | 110 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 158:0c8342e1837a | 111 | //////////////////////////////////смотрим все моды///////////////////////////////////////////////// |
Kovalev_D | 158:0c8342e1837a | 112 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 158:0c8342e1837a | 113 | if( (Gyro.PLC_Lern<1092)&&(Gyro.PLC_Error2Mode != 0))//пробигаем по нескольким значениям цап(60*0х3с=0хВВ8) для определения максимальной амплитуды. |
Kovalev_D | 158:0c8342e1837a | 114 | { |
Kovalev_D | 158:0c8342e1837a | 115 | Gyro.PLC_Error2Mode--; |
Kovalev_D | 158:0c8342e1837a | 116 | Gyro.PLC_Lern++; |
Kovalev_D | 158:0c8342e1837a | 117 | Spi.DAC_B += 0x3c; |
Kovalev_D | 158:0c8342e1837a | 118 | if(AD_MAX < Gyro.AD_Slow) AD_MAX = Gyro.AD_Slow; |
Kovalev_D | 158:0c8342e1837a | 119 | sprintf((Time),"%d %d %d %d \r\n",Gyro.TermLM,Spi.DAC_B, Gyro.AD_Slow, AD_MAX); |
Kovalev_D | 158:0c8342e1837a | 120 | WriteCon(Time); |
Kovalev_D | 158:0c8342e1837a | 121 | } |
Kovalev_D | 158:0c8342e1837a | 122 | } |
Kovalev_D | 144:083c667ba848 | 123 | |
Kovalev_D | 144:083c667ba848 | 124 | |
Kovalev_D | 144:083c667ba848 | 125 | |
Kovalev_D | 144:083c667ba848 | 126 | |
Kovalev_D | 144:083c667ba848 | 127 | |
Kovalev_D | 159:38f39c0c143f | 128 | void PlcRegul(void) //Программа расчет напряжения для модулятора(//выполняется 1.25 микросек.) |
Kovalev_D | 144:083c667ba848 | 129 | { |
Kovalev_D | 155:94e7ac5fea58 | 130 | |
Kovalev_D | 157:1069c80f4944 | 131 | int PLC_In; |
Kovalev_D | 157:1069c80f4944 | 132 | int tempDac; |
Kovalev_D | 153:7086895c6ee3 | 133 | |
Kovalev_D | 151:d565ce4d58c8 | 134 | |
Kovalev_D | 157:1069c80f4944 | 135 | // PLC_In = Gyro.AD_Fast; |
Kovalev_D | 157:1069c80f4944 | 136 | //или+,или-(знак) |
Kovalev_D | 153:7086895c6ee3 | 137 | |
Kovalev_D | 158:0c8342e1837a | 138 | // Gyro.AD_Slow=Gyro.AD_Slow<<3; |
Kovalev_D | 158:0c8342e1837a | 139 | |
Kovalev_D | 157:1069c80f4944 | 140 | PLC_In = Gyro.AD_Slow; //выбираем даные для фильтрации |
Kovalev_D | 157:1069c80f4944 | 141 | Gyro.PLC_Delta = PLC_In - Gyro.PLC_Old; // узнаем приращение |
Kovalev_D | 157:1069c80f4944 | 142 | Gyro.PLC_DeltaADD = Gyro.PLC_Delta * Gyro.PLC_ADC_DOld; //приращение с учетом знака (и количества) прошлого приращения |
Kovalev_D | 157:1069c80f4944 | 143 | Gyro.PLC_Old = PLC_In; // запоминание значения |
Kovalev_D | 157:1069c80f4944 | 144 | |
Kovalev_D | 158:0c8342e1837a | 145 | |
Kovalev_D | 158:0c8342e1837a | 146 | |
Kovalev_D | 158:0c8342e1837a | 147 | |
Kovalev_D | 158:0c8342e1837a | 148 | |
Kovalev_D | 158:0c8342e1837a | 149 | |
Kovalev_D | 158:0c8342e1837a | 150 | // 3600 (размер моды порядка 3000) |
Kovalev_D | 157:1069c80f4944 | 151 | if((Gyro.PLC_Lern < 60) && (Gyro.PLC_Error2Mode != 0)) { //пробигаем по нескольким значениям цап(60*0х3с=0хВВ8) для определения максимальной амплитуды. |
Kovalev_D | 157:1069c80f4944 | 152 | Gyro.PLC_Lern++; //инкрементируем счетчик поиска максимальной амплитуды |
Kovalev_D | 157:1069c80f4944 | 153 | if(AD_MAX < Gyro.AD_Slow) AD_MAX = Gyro.AD_Slow; //если максимальная амплитуда меньше текущей записываем новую максимальную амплитуду. * |
Kovalev_D | 157:1069c80f4944 | 154 | Spi.DAC_B += 0x3c; //добовляем в значение цапа 60 |
Kovalev_D | 159:38f39c0c143f | 155 | Gyro.CuruAngle = 0; |
Kovalev_D | 157:1069c80f4944 | 156 | } //работает только первые ~30-40 секунд (37 сек). |
Kovalev_D | 153:7086895c6ee3 | 157 | |
Kovalev_D | 153:7086895c6ee3 | 158 | |
Kovalev_D | 153:7086895c6ee3 | 159 | |
Kovalev_D | 157:1069c80f4944 | 160 | if(AD_MAX < Gyro.AD_Slow) { AD_MAX = Gyro.AD_Slow; l=0; }//обновление максимального значения амплитуды обнуление счетчика малого понижения амплитуды. * |
Kovalev_D | 159:38f39c0c143f | 161 | else if((l == 100)&&(Gyro.PLC_Error2Mode == 0)) { AD_MAX -= 5107200;k=1;l=0;} //если счетчик малого понижения амплитуды больше 100(аммплитуда не обновлялась 100 раз). |
Kovalev_D | 159:38f39c0c143f | 162 | else l++; |
Kovalev_D | 159:38f39c0c143f | 163 | |
Kovalev_D | 159:38f39c0c143f | 164 | if((k == 1)&&(Gyro.PLC_Error2Mode == 0)) {Spi.DAC_B += 200; k=2;} |
Kovalev_D | 159:38f39c0c143f | 165 | //if((k == 2)&&(Gyro.PLC_Error2Mode == 0)) {Spi.DAC_B -= 200; k=0;l=0;} |
Kovalev_D | 159:38f39c0c143f | 166 | //инкрементируем счетчик малого понижения желаемой амплитуды (максимальной замеченной) |
Kovalev_D | 158:0c8342e1837a | 167 | Gyro.PlC_MaxD=(unsigned int)(AD_MAX-Gyro.AD_Slow); //ищем разницу между желаемой и действительной амплитудами. |
Kovalev_D | 158:0c8342e1837a | 168 | |
Kovalev_D | 157:1069c80f4944 | 169 | //ели небыло обновления максимальной амплитуды инкрементируем счетчика малого понижения амплитуды. |
Kovalev_D | 159:38f39c0c143f | 170 | |
Kovalev_D | 159:38f39c0c143f | 171 | |
Kovalev_D | 157:1069c80f4944 | 172 | |
Kovalev_D | 157:1069c80f4944 | 173 | if(Gyro.RgConA&0x2) { // если контур регулирования замкнут |
Kovalev_D | 157:1069c80f4944 | 174 | /* else if ( Gyro.PLC_Delta > (3500 * 65536)) {Spi.DAC_B += 2500; Gyro.PLC_Error2Mode = 5; Gyro.PLC_ADC_DOld = 0;} // проверка на двух модовость |
Kovalev_D | 157:1069c80f4944 | 175 | else if ( Gyro.PLC_Delta < (-3500 * 65536)) {Spi.DAC_B += 2500; Gyro.PLC_Error2Mode = 5; Gyro.PLC_ADC_DOld = 0;} // проверка на двух модовость*/ |
Kovalev_D | 157:1069c80f4944 | 176 | if ( Gyro.PLC_Error2Mode > 0) { Gyro.PLC_Error2Mode --; Gyro.PLC_ADC_DOld = 0;} // если ошибка(нахожление в двух модовом) |
Kovalev_D | 157:1069c80f4944 | 177 | else if ( Gyro.PLC_DeltaADD > 0) { Gyro.PLC_ADC_DOld = 1;} |
Kovalev_D | 157:1069c80f4944 | 178 | else if ( Gyro.PLC_DeltaADD < 0) { Gyro.PLC_ADC_DOld = -1;} |
Kovalev_D | 157:1069c80f4944 | 179 | else { Gyro.PLC_ADC_DOld = 1;} |
Kovalev_D | 157:1069c80f4944 | 180 | } |
Kovalev_D | 157:1069c80f4944 | 181 | else {Gyro.PLC_Error2Mode = 1; Gyro.PLC_DeltaADD = 0;} |
Kovalev_D | 157:1069c80f4944 | 182 | |
Kovalev_D | 157:1069c80f4944 | 183 | if(Gyro.PlC_MaxD>(50<<18)) { // 3 режим регулирования |
Kovalev_D | 157:1069c80f4944 | 184 | tempDac=(unsigned int)(Gyro.PlC_MaxD>>18); |
Kovalev_D | 159:38f39c0c143f | 185 | if(tempDac>600) tempDac=600; //ограничение на регулирование если очень большая разница амплитуд |
Kovalev_D | 157:1069c80f4944 | 186 | Spi.DAC_B += Gyro.PLC_ADC_DOld * tempDac; //новое значение в цап (±1 * значение регулировки) |
Kovalev_D | 157:1069c80f4944 | 187 | tempDac = Gyro.PLC_ADC_DOld * tempDac; //используется только для выдачи |
Kovalev_D | 157:1069c80f4944 | 188 | flagmod=3; |
Kovalev_D | 157:1069c80f4944 | 189 | } |
Kovalev_D | 157:1069c80f4944 | 190 | else if(Gyro.PlC_MaxD>(12<<18)) { // 2 режим регулирования |
Kovalev_D | 157:1069c80f4944 | 191 | tempDac=(unsigned int)(Gyro.PlC_MaxD>>18); |
Kovalev_D | 157:1069c80f4944 | 192 | Spi.DAC_B += Gyro.PLC_ADC_DOld * (tempDac); |
Kovalev_D | 157:1069c80f4944 | 193 | tempDac = Gyro.PLC_ADC_DOld * (tempDac); //используется только для выдачи |
Kovalev_D | 157:1069c80f4944 | 194 | flagmod=2; |
Kovalev_D | 157:1069c80f4944 | 195 | } |
Kovalev_D | 157:1069c80f4944 | 196 | else if(Gyro.PlC_MaxD<(2<<18)) { //режим если дельта равна 0; |
Kovalev_D | 157:1069c80f4944 | 197 | tempDac=2; |
Kovalev_D | 157:1069c80f4944 | 198 | Spi.DAC_B += Gyro.PLC_ADC_DOld * tempDac; |
Kovalev_D | 157:1069c80f4944 | 199 | flagmod=1; |
Kovalev_D | 157:1069c80f4944 | 200 | } |
Kovalev_D | 157:1069c80f4944 | 201 | else { |
Kovalev_D | 157:1069c80f4944 | 202 | tempDac=(unsigned int)(Gyro.PlC_MaxD>>19); // 1 режим регулирования |
Kovalev_D | 157:1069c80f4944 | 203 | Spi.DAC_B += Gyro.PLC_ADC_DOld *tempDac; |
Kovalev_D | 157:1069c80f4944 | 204 | tempDac = Gyro.PLC_ADC_DOld * tempDac; |
Kovalev_D | 157:1069c80f4944 | 205 | flagmod=1; |
Kovalev_D | 157:1069c80f4944 | 206 | } |
Kovalev_D | 159:38f39c0c143f | 207 | |
Kovalev_D | 159:38f39c0c143f | 208 | /* |
Kovalev_D | 157:1069c80f4944 | 209 | if(flagmod==3) {k++; //если максимальный режим регулирования //инкрементируем счетчик большого понижения амплитуды |
Kovalev_D | 159:38f39c0c143f | 210 | if(k>100){k=0;AD_MAX -= 6107200;} //если счетчик бльше 50 //обнуляем счетчик //уменьшаем максимальную амплитуду. |
Kovalev_D | 157:1069c80f4944 | 211 | } |
Kovalev_D | 157:1069c80f4944 | 212 | else k=0; //если это не серия максимальных регулировок обнуляем счетчик. |
Kovalev_D | 157:1069c80f4944 | 213 | |
Kovalev_D | 159:38f39c0c143f | 214 | */ |
Kovalev_D | 157:1069c80f4944 | 215 | |
Kovalev_D | 159:38f39c0c143f | 216 | if ( Spi.DAC_B < 1000 ) {Spi.DAC_B = 32000; Gyro.PLC_Error2Mode = 5; Gyro.PLC_DeltaADD = 0;} //проверка на переваливание за границу. |
Kovalev_D | 157:1069c80f4944 | 217 | else if ( Spi.DAC_B > 63000 ) {Spi.DAC_B = 32000; Gyro.PLC_Error2Mode = 5; Gyro.PLC_DeltaADD = 0;} |
Kovalev_D | 157:1069c80f4944 | 218 | |
Kovalev_D | 153:7086895c6ee3 | 219 | |
Kovalev_D | 157:1069c80f4944 | 220 | |
Kovalev_D | 157:1069c80f4944 | 221 | /////////////////////// |
Kovalev_D | 157:1069c80f4944 | 222 | //////////лог////////// |
Kovalev_D | 157:1069c80f4944 | 223 | /////////////////////// |
Kovalev_D | 157:1069c80f4944 | 224 | if(Gyro.LogPLC==1) { |
Kovalev_D | 157:1069c80f4944 | 225 | //sprintf((Time),"%d %d %d %d\r\n",Gyro.PLC_Lern, Spi.DAC_B, Gyro.AD_Slow, Gyro.AD_Slow>>18 );//выдаем в терминал для постройки граффика регулировки периметра. |
Kovalev_D | 151:d565ce4d58c8 | 226 | //WriteCon(Time); |
Kovalev_D | 159:38f39c0c143f | 227 | sprintf((Time),"%d %d %d %d %d %d %d %d %d %d\r\n", Spi.DAC_B, temp9, l, tempDac, flagmod, AD_MAX, Gyro.AD_Slow, k, Gyro.CuruAngle, Gyro.TermLM);//выдаем в терминал для постройки граффика регулировки периметра. |
Kovalev_D | 141:c6de20b9b483 | 228 | WriteCon(Time); |
Kovalev_D | 159:38f39c0c143f | 229 | // Gyro.CuruAngle = 0; |
Kovalev_D | 157:1069c80f4944 | 230 | } |
Kovalev_D | 157:1069c80f4944 | 231 | } |
Kovalev_D | 141:c6de20b9b483 | 232 | |
Kovalev_D | 141:c6de20b9b483 | 233 | |
Kovalev_D | 141:c6de20b9b483 | 234 | |
Kovalev_D | 141:c6de20b9b483 | 235 | |
Kovalev_D | 141:c6de20b9b483 | 236 | /* |
Kovalev_D | 157:1069c80f4944 | 237 | |
Kovalev_D | 116:66f1f0ff2dab | 238 | void PlcRegul(void) //Программа расчет напряжения для модулятора |
Kovalev_D | 116:66f1f0ff2dab | 239 | { |
Kovalev_D | 116:66f1f0ff2dab | 240 | int PLC_In; |
Kovalev_D | 116:66f1f0ff2dab | 241 | |
igor_v | 127:6a7472d67804 | 242 | |
igor_v | 127:6a7472d67804 | 243 | PLC_In = Gyro.AD_Slow; //выбираем даные для фильтрации |
Kovalev_D | 116:66f1f0ff2dab | 244 | // PLC_In = Gyro.AD_Fast; |
Kovalev_D | 128:1e4675a36c93 | 245 | //или+,или-(знак) |
Kovalev_D | 128:1e4675a36c93 | 246 | Gyro.PLC_Delta = PLC_In - Gyro.PLC_Old; // узнаем приращение |
Kovalev_D | 128:1e4675a36c93 | 247 | // (знак) * (то на что инкрементировали цап) |
Kovalev_D | 128:1e4675a36c93 | 248 | Gyro.PLC_DeltaADD = Gyro.PLC_Delta * Gyro.PLC_ADC_DOld; //приращение с учетом знака (и количества) прошлого приращения |
Kovalev_D | 128:1e4675a36c93 | 249 | Gyro.PLC_Old = PLC_In; // запоминание значения |
igor_v | 127:6a7472d67804 | 250 | |
Kovalev_D | 128:1e4675a36c93 | 251 | if(Gyro.RgConA&0x2) // если включон контур регулирования |
Kovalev_D | 157:1069c80f4944 | 252 | { |
Kovalev_D | 140:1fbf117fc120 | 253 | if (Gyro.PLC_Error2Mode > 0) {Gyro.PLC_Error2Mode --; Gyro.PLC_ADC_DOld = 0; } // если ошибка(нахожление в двух модовом) |
Kovalev_D | 128:1e4675a36c93 | 254 | else if ( Gyro.PLC_Delta > (3000 * 65536)) {Spi.DAC_B += 2500; Gyro.PLC_Error2Mode = 5; Gyro.PLC_ADC_DOld = 0;} // проверка на двух модовость |
Kovalev_D | 128:1e4675a36c93 | 255 | else if ( Gyro.PLC_Delta < (-3000 * 65536)) {Spi.DAC_B += 2500; Gyro.PLC_Error2Mode = 5; Gyro.PLC_ADC_DOld = 0;} |
Kovalev_D | 157:1069c80f4944 | 256 | |
Kovalev_D | 157:1069c80f4944 | 257 | else if (Gyro.PLC_DeltaADD > 0) |
igor_v | 127:6a7472d67804 | 258 | { |
Kovalev_D | 157:1069c80f4944 | 259 | |
Kovalev_D | 159:38f39c0c143f | 260 | // Gyro.PLC_ADC_DOld = (Gyro.PLC_DeltaADD /6553600 )+1; |
Kovalev_D | 128:1e4675a36c93 | 261 | Gyro.PLC_ADC_DOld = 1; |
igor_v | 127:6a7472d67804 | 262 | } |
Kovalev_D | 157:1069c80f4944 | 263 | else if (Gyro.PLC_DeltaADD < 0) |
igor_v | 127:6a7472d67804 | 264 | { |
igor_v | 127:6a7472d67804 | 265 | |
Kovalev_D | 128:1e4675a36c93 | 266 | // Gyro.PLC_ADC_DOld = (Gyro.PLC_DeltaADD /6553600 )-1; |
Kovalev_D | 128:1e4675a36c93 | 267 | Gyro.PLC_ADC_DOld = -1; |
igor_v | 127:6a7472d67804 | 268 | } |
igor_v | 127:6a7472d67804 | 269 | else |
igor_v | 127:6a7472d67804 | 270 | { |
Kovalev_D | 128:1e4675a36c93 | 271 | Gyro.PLC_ADC_DOld = 1; |
igor_v | 127:6a7472d67804 | 272 | } |
igor_v | 127:6a7472d67804 | 273 | } |
Kovalev_D | 157:1069c80f4944 | 274 | else |
igor_v | 127:6a7472d67804 | 275 | { |
Kovalev_D | 128:1e4675a36c93 | 276 | Gyro.PLC_Error2Mode = 1; Gyro.PLC_DeltaADD = 0; |
igor_v | 127:6a7472d67804 | 277 | } |
Kovalev_D | 157:1069c80f4944 | 278 | |
Kovalev_D | 157:1069c80f4944 | 279 | |
Kovalev_D | 141:c6de20b9b483 | 280 | Spi.DAC_B += Gyro.PLC_ADC_DOld * 16; |
Kovalev_D | 157:1069c80f4944 | 281 | |
Kovalev_D | 157:1069c80f4944 | 282 | |
Kovalev_D | 128:1e4675a36c93 | 283 | if ( Spi.DAC_B < 1000 ) {Spi.DAC_B = 32000; Gyro.PLC_Error2Mode = 5; Gyro.PLC_DeltaADD = 0;} |
Kovalev_D | 128:1e4675a36c93 | 284 | if ( Spi.DAC_B > 63000 ) {Spi.DAC_B = 32000; Gyro.PLC_Error2Mode = 5; Gyro.PLC_DeltaADD = 0;} |
Kovalev_D | 157:1069c80f4944 | 285 | |
Kovalev_D | 141:c6de20b9b483 | 286 | if(Gyro.LogPLC==1) |
Kovalev_D | 141:c6de20b9b483 | 287 | { |
Kovalev_D | 157:1069c80f4944 | 288 | 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 | 289 | WriteCon(Time); |
Kovalev_D | 141:c6de20b9b483 | 290 | } |
Kovalev_D | 157:1069c80f4944 | 291 | |
Kovalev_D | 128:1e4675a36c93 | 292 | } |
Kovalev_D | 116:66f1f0ff2dab | 293 | |
Kovalev_D | 116:66f1f0ff2dab | 294 | |
Kovalev_D | 141:c6de20b9b483 | 295 | */ |
Kovalev_D | 157:1069c80f4944 | 296 | void PlcRegul_old(void) // на всякий случай |
Kovalev_D | 112:4a96133a1311 | 297 | { |
Kovalev_D | 157:1069c80f4944 | 298 | int Delta; |
Kovalev_D | 157:1069c80f4944 | 299 | |
Kovalev_D | 157:1069c80f4944 | 300 | ADD_AMP+=Spi.ADC5; |
Kovalev_D | 157:1069c80f4944 | 301 | Count_AMP++; |
Kovalev_D | 157:1069c80f4944 | 302 | if(Count_AMP>=(32*32+8)) { |
Kovalev_D | 157:1069c80f4944 | 303 | Delta = ADD_AMP - Cur_Amp; |
Kovalev_D | 157:1069c80f4944 | 304 | |
Kovalev_D | 157:1069c80f4944 | 305 | if(Gyro.RgConA&0x2) { |
Kovalev_D | 157:1069c80f4944 | 306 | if (Znak_Amp > 1) { |
Kovalev_D | 157:1069c80f4944 | 307 | Znak_Amp --; |
Kovalev_D | 157:1069c80f4944 | 308 | } else if ( Delta > 30000000 ) { |
Kovalev_D | 157:1069c80f4944 | 309 | AD_Regul += 5000000; |
Kovalev_D | 157:1069c80f4944 | 310 | Znak_Amp = 5; |
Kovalev_D | 157:1069c80f4944 | 311 | } else if ( Delta < (-3000000)) { |
Kovalev_D | 157:1069c80f4944 | 312 | AD_Regul += 5000000; |
Kovalev_D | 157:1069c80f4944 | 313 | Znak_Amp = 5; |
Kovalev_D | 157:1069c80f4944 | 314 | } else if ((Delta * Znak_Amp) > 0) { |
Kovalev_D | 157:1069c80f4944 | 315 | Znak_Amp = 1; |
Kovalev_D | 157:1069c80f4944 | 316 | AD_Regul -= (Delta * Znak_Amp * 10); |
Kovalev_D | 157:1069c80f4944 | 317 | } else { |
Kovalev_D | 157:1069c80f4944 | 318 | Znak_Amp = -1; |
Kovalev_D | 157:1069c80f4944 | 319 | AD_Regul -= (Delta * Znak_Amp * 10); |
Kovalev_D | 157:1069c80f4944 | 320 | } |
Kovalev_D | 157:1069c80f4944 | 321 | |
Kovalev_D | 157:1069c80f4944 | 322 | Spi.DAC_B = (AD_Regul + 0x1fffffff)/65536; |
Kovalev_D | 157:1069c80f4944 | 323 | } |
Kovalev_D | 157:1069c80f4944 | 324 | Cur_Amp=ADD_AMP; |
Kovalev_D | 157:1069c80f4944 | 325 | Count_AMP=0; |
Kovalev_D | 157:1069c80f4944 | 326 | ADD_AMP=0; |
Kovalev_D | 157:1069c80f4944 | 327 | } |
Kovalev_D | 157:1069c80f4944 | 328 | |
igor_v | 110:6406b7ac0442 | 329 | } |
igor_v | 110:6406b7ac0442 | 330 | |
igor_v | 110:6406b7ac0442 | 331 | |
Kovalev_D | 116:66f1f0ff2dab | 332 | |
Kovalev_D | 116:66f1f0ff2dab | 333 | |
Kovalev_D | 112:4a96133a1311 | 334 | void DAC_OutPut(void)//выдача в цапы |
igor_v | 0:8ad47e2b6f00 | 335 | { |
Kovalev_D | 157:1069c80f4944 | 336 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 337 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 338 | LPC_SSP0->DR=0x5555; |
igor_v | 0:8ad47e2b6f00 | 339 | |
igor_v | 110:6406b7ac0442 | 340 | if (CountV31 & 1) { //если нечетный такт то |
igor_v | 31:c783288001b5 | 341 | LPC_SSP0->DR = WRITE_DAC0; //e.команда для ЦАП_0 передавать. |
igor_v | 31:c783288001b5 | 342 | LPC_SSP0->DR = (Spi.DAC_A); //e. передача 12 бит |
Kovalev_D | 157:1069c80f4944 | 343 | } else { //если такт четный. |
Kovalev_D | 157:1069c80f4944 | 344 | LPC_SSP0->DR = WRITE_DAC1 ; //e.команда для ЦАП_1 передавать. |
Kovalev_D | 157:1069c80f4944 | 345 | |
Kovalev_D | 157:1069c80f4944 | 346 | switch( Gyro.StrayPLC_flag) { |
Kovalev_D | 157:1069c80f4944 | 347 | |
Kovalev_D | 157:1069c80f4944 | 348 | case 0://режим без воздействия |
Kovalev_D | 157:1069c80f4944 | 349 | LPC_SSP0->DR = (Spi.DAC_B); |
Kovalev_D | 157:1069c80f4944 | 350 | temp9=Spi.DAC_B; |
Kovalev_D | 157:1069c80f4944 | 351 | break; |
Kovalev_D | 157:1069c80f4944 | 352 | |
Kovalev_D | 157:1069c80f4944 | 353 | case 1://малое воздействие + |
Kovalev_D | 157:1069c80f4944 | 354 | temp9=Spi.DAC_B + Gyro.StrayPLC_Pls; |
Kovalev_D | 157:1069c80f4944 | 355 | LPC_SSP0->DR = temp9; |
Kovalev_D | 157:1069c80f4944 | 356 | break; |
Kovalev_D | 157:1069c80f4944 | 357 | |
Kovalev_D | 157:1069c80f4944 | 358 | case 3://малое воздействие - |
Kovalev_D | 157:1069c80f4944 | 359 | temp9=Spi.DAC_B + Gyro.StrayPLC_Mns; |
Kovalev_D | 157:1069c80f4944 | 360 | LPC_SSP0->DR = temp9; |
Kovalev_D | 157:1069c80f4944 | 361 | break; |
Kovalev_D | 157:1069c80f4944 | 362 | |
Kovalev_D | 157:1069c80f4944 | 363 | case 2://большое воздействие + |
Kovalev_D | 157:1069c80f4944 | 364 | temp9=Spi.DAC_B + Gyro.StrayPLC_2Mode; |
Kovalev_D | 157:1069c80f4944 | 365 | LPC_SSP0->DR = temp9;//вгоняем в многомодовый режим |
Kovalev_D | 157:1069c80f4944 | 366 | break; |
Kovalev_D | 157:1069c80f4944 | 367 | |
Kovalev_D | 157:1069c80f4944 | 368 | } |
Kovalev_D | 157:1069c80f4944 | 369 | // LPC_SSP0->DR = Spi.DAC_B; //e. передача 12 бит |
Kovalev_D | 157:1069c80f4944 | 370 | |
igor_v | 31:c783288001b5 | 371 | } |
Kovalev_D | 112:4a96133a1311 | 372 | } |
Kovalev_D | 112:4a96133a1311 | 373 | |
Kovalev_D | 112:4a96133a1311 | 374 | |
Kovalev_D | 113:8be429494918 | 375 | |
Kovalev_D | 113:8be429494918 | 376 | |
Kovalev_D | 113:8be429494918 | 377 | |
Kovalev_D | 113:8be429494918 | 378 | |
Kovalev_D | 113:8be429494918 | 379 | |
Kovalev_D | 113:8be429494918 | 380 | |
Kovalev_D | 113:8be429494918 | 381 | |
Kovalev_D | 113:8be429494918 | 382 | |
Kovalev_D | 113:8be429494918 | 383 | |
Kovalev_D | 113:8be429494918 | 384 | |
Kovalev_D | 113:8be429494918 | 385 | |
Kovalev_D | 113:8be429494918 | 386 | |
Kovalev_D | 113:8be429494918 | 387 | |
Kovalev_D | 113:8be429494918 | 388 | |
Kovalev_D | 113:8be429494918 | 389 | |
Kovalev_D | 113:8be429494918 | 390 | |
Kovalev_D | 113:8be429494918 | 391 | |
Kovalev_D | 113:8be429494918 | 392 | |
Kovalev_D | 113:8be429494918 | 393 | |
Kovalev_D | 113:8be429494918 | 394 | |
Kovalev_D | 113:8be429494918 | 395 | |
Kovalev_D | 113:8be429494918 | 396 | |
Kovalev_D | 113:8be429494918 | 397 | |
Kovalev_D | 113:8be429494918 | 398 | |
Kovalev_D | 113:8be429494918 | 399 | |
Kovalev_D | 113:8be429494918 | 400 | |
Kovalev_D | 113:8be429494918 | 401 | |
Kovalev_D | 113:8be429494918 | 402 | |
Kovalev_D | 113:8be429494918 | 403 | /* |
Kovalev_D | 112:4a96133a1311 | 404 | void SPI_Exchange(void) |
Kovalev_D | 112:4a96133a1311 | 405 | { |
Kovalev_D | 112:4a96133a1311 | 406 | unsigned int DummySPI; |
Kovalev_D | 157:1069c80f4944 | 407 | |
Kovalev_D | 112:4a96133a1311 | 408 | |
Kovalev_D | 112:4a96133a1311 | 409 | Spi.ADC5 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 410 | Spi.ADC4 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 411 | Spi.ADC3 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 412 | Spi.ADC2 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 413 | Spi.ADC1 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 414 | |
Kovalev_D | 112:4a96133a1311 | 415 | Input.ArrayIn[2]= Spi.ADC5; |
Kovalev_D | 157:1069c80f4944 | 416 | |
Kovalev_D | 112:4a96133a1311 | 417 | DAC_OutPut(); |
igor_v | 0:8ad47e2b6f00 | 418 | |
Kovalev_D | 99:3d8f206ceac2 | 419 | // LPC_DAC->CR = (((SinPLC[CountV64]*35/5)+24300));// модулятор |
Kovalev_D | 112:4a96133a1311 | 420 | |
Kovalev_D | 89:a0d344db227e | 421 | while (LPC_SSP0->SR & RX_SSP_notEMPT) //если буфер SPI не пуст. |
Kovalev_D | 89:a0d344db227e | 422 | DummySPI = LPC_SSP0->DR; //очистить буфер. |
igor_v | 31:c783288001b5 | 423 | |
Kovalev_D | 112:4a96133a1311 | 424 | //заполнение буферов еденичных значений АЦП. |
Kovalev_D | 157:1069c80f4944 | 425 | Buff_ADC_1 [CountV31] = Spi.ADC1; |
Kovalev_D | 112:4a96133a1311 | 426 | Buff_ADC_2 [CountV31] = Spi.ADC2; |
Kovalev_D | 112:4a96133a1311 | 427 | Buff_ADC_3 [CountV31] = Spi.ADC3; |
Kovalev_D | 112:4a96133a1311 | 428 | Buff_ADC_4 [CountV31] = Spi.ADC4; |
Kovalev_D | 95:dd51e577e114 | 429 | Buff_ADC_5 [CountV255] = Spi.ADC5; // ампл ацп. |
igor_v | 110:6406b7ac0442 | 430 | |
Kovalev_D | 157:1069c80f4944 | 431 | |
igor_v | 110:6406b7ac0442 | 432 | Temp_AMP64P += Buff_ADC_5[CountV255]; |
Kovalev_D | 96:1c8536458119 | 433 | Temp_AMP64P -= Buff_ADC_5[(CountV255-64) & 0xff]; // заполнение буфера накопленых приращений за 8 тактов |
Kovalev_D | 96:1c8536458119 | 434 | Buff_AMP64P[CountV255] = (unsigned int) (Temp_AMP64P); |
Kovalev_D | 96:1c8536458119 | 435 | |
igor_v | 31:c783288001b5 | 436 | |
Kovalev_D | 47:d902ef6f7564 | 437 | Temp_ADC_2 += Buff_ADC_2[CountV31]; |
Kovalev_D | 47:d902ef6f7564 | 438 | Temp_ADC_2 -= Buff_ADC_2[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 439 | |
Kovalev_D | 47:d902ef6f7564 | 440 | Temp_ADC_3 += Buff_ADC_3[CountV31]; |
Kovalev_D | 95:dd51e577e114 | 441 | Temp_ADC_3 -= Buff_ADC_3[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 442 | |
Kovalev_D | 47:d902ef6f7564 | 443 | Temp_ADC_4 += Buff_ADC_4[CountV31]; |
Kovalev_D | 47:d902ef6f7564 | 444 | Temp_ADC_4 -= Buff_ADC_4[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 445 | |
igor_v | 31:c783288001b5 | 446 | Temp_ADC_5 += Buff_ADC_1[CountV255]; |
igor_v | 31:c783288001b5 | 447 | Temp_ADC_5 -= Buff_ADC_1[(CountV255-32) & 0xff]; |
Kovalev_D | 112:4a96133a1311 | 448 | Spi.PLC_NewData=1; |
Kovalev_D | 113:8be429494918 | 449 | }*/ |