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