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