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