![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
SPI.c@147:1aed74f19a8f, 2016-04-29 (annotated)
- Committer:
- Kovalev_D
- Date:
- Fri Apr 29 07:27:50 2016 +0000
- Revision:
- 147:1aed74f19a8f
- Parent:
- 146:2bea299a7c4f
- Child:
- 148:7ce8c1fd00f7
123
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 | 109:ee0cff33ad3b | 10 | |
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 | 144:083c667ba848 | 138 | int AD_MAX; |
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 | 144:083c667ba848 | 145 | AD_MAX=1941520832; |
Kovalev_D | 144:083c667ba848 | 146 | //15728640 |
Kovalev_D | 144:083c667ba848 | 147 | tempDelta=AD_MAX-Gyro.AD_Slow; |
Kovalev_D | 144:083c667ba848 | 148 | if(Gyro.RgConA&0x2) // если включон контур регулирования |
Kovalev_D | 144:083c667ba848 | 149 | { |
Kovalev_D | 144:083c667ba848 | 150 | |
Kovalev_D | 141:c6de20b9b483 | 151 | |
Kovalev_D | 144:083c667ba848 | 152 | if ( Gyro.PLC_Error2Mode > 0) {Gyro.PLC_Error2Mode --; Gyro.PLC_ADC_DOld = 0;} // если ошибка(нахожление в двух модовом) |
Kovalev_D | 144:083c667ba848 | 153 | else if ( Gyro.PLC_Delta > (3500 * 65536)) {Spi.DAC_B += 2500; Gyro.PLC_Error2Mode = 5; 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_DeltaADD > 0) {Gyro.PLC_ADC_DOld = 1;} |
Kovalev_D | 144:083c667ba848 | 156 | else if ( Gyro.PLC_DeltaADD < 0) {Gyro.PLC_ADC_DOld = -1;} |
Kovalev_D | 141:c6de20b9b483 | 157 | else |
Kovalev_D | 141:c6de20b9b483 | 158 | { |
Kovalev_D | 144:083c667ba848 | 159 | //Gyro.PLC_Delta=1114111;//если делта 0 то Spi.DAC_B += 4; |
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 | 141:c6de20b9b483 | 167 | |
Kovalev_D | 141:c6de20b9b483 | 168 | |
Kovalev_D | 144:083c667ba848 | 169 | if(((tempDelta>>18)>50)||((tempDelta>>18)<(-50))) |
Kovalev_D | 144:083c667ba848 | 170 | { |
Kovalev_D | 144:083c667ba848 | 171 | tempDac=(unsigned int)(tempDelta>>18); |
Kovalev_D | 144:083c667ba848 | 172 | if(tempDac>450) |
Kovalev_D | 144:083c667ba848 | 173 | {tempDac=400; |
Kovalev_D | 144:083c667ba848 | 174 | } |
Kovalev_D | 144:083c667ba848 | 175 | Spi.DAC_B += Gyro.PLC_ADC_DOld * tempDac /*Gyro.PLC_Delta>>18*/; |
Kovalev_D | 144:083c667ba848 | 176 | tempDac = Gyro.PLC_ADC_DOld * tempDac; |
Kovalev_D | 144:083c667ba848 | 177 | flagmod=3; |
Kovalev_D | 144:083c667ba848 | 178 | } |
Kovalev_D | 144:083c667ba848 | 179 | else if(((tempDelta>>18)>30)||((tempDelta>>18)<(-30))) |
Kovalev_D | 144:083c667ba848 | 180 | { |
Kovalev_D | 144:083c667ba848 | 181 | tempDac=(unsigned int)(tempDelta>>19); |
Kovalev_D | 144:083c667ba848 | 182 | Spi.DAC_B += Gyro.PLC_ADC_DOld * (tempDac+5); |
Kovalev_D | 144:083c667ba848 | 183 | tempDac = Gyro.PLC_ADC_DOld * (tempDac+5); |
Kovalev_D | 144:083c667ba848 | 184 | flagmod=2; |
Kovalev_D | 144:083c667ba848 | 185 | } |
Kovalev_D | 144:083c667ba848 | 186 | else |
Kovalev_D | 144:083c667ba848 | 187 | { |
Kovalev_D | 144:083c667ba848 | 188 | tempDac=(unsigned int)(tempDelta>>20); |
Kovalev_D | 144:083c667ba848 | 189 | Spi.DAC_B += Gyro.PLC_ADC_DOld *tempDac; |
Kovalev_D | 144:083c667ba848 | 190 | tempDac = Gyro.PLC_ADC_DOld * tempDac; |
Kovalev_D | 144:083c667ba848 | 191 | flagmod=1; |
Kovalev_D | 144:083c667ba848 | 192 | } |
Kovalev_D | 144:083c667ba848 | 193 | |
Kovalev_D | 144:083c667ba848 | 194 | |
Kovalev_D | 141:c6de20b9b483 | 195 | if ( Spi.DAC_B < 1000 ) {Spi.DAC_B = 32000; Gyro.PLC_Error2Mode = 5; Gyro.PLC_DeltaADD = 0;} |
Kovalev_D | 141:c6de20b9b483 | 196 | if ( Spi.DAC_B > 63000 ) {Spi.DAC_B = 32000; Gyro.PLC_Error2Mode = 5; Gyro.PLC_DeltaADD = 0;} |
Kovalev_D | 144:083c667ba848 | 197 | |
Kovalev_D | 144:083c667ba848 | 198 | k=1; |
Kovalev_D | 144:083c667ba848 | 199 | |
Kovalev_D | 141:c6de20b9b483 | 200 | if(Gyro.LogPLC==1) |
Kovalev_D | 141:c6de20b9b483 | 201 | { |
Kovalev_D | 144:083c667ba848 | 202 | 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 | 203 | WriteCon(Time); |
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 | 141:c6de20b9b483 | 209 | |
Kovalev_D | 141:c6de20b9b483 | 210 | |
Kovalev_D | 141:c6de20b9b483 | 211 | |
Kovalev_D | 141:c6de20b9b483 | 212 | /* |
Kovalev_D | 116:66f1f0ff2dab | 213 | void PlcRegul(void) //Программа расчет напряжения для модулятора |
Kovalev_D | 116:66f1f0ff2dab | 214 | { |
Kovalev_D | 116:66f1f0ff2dab | 215 | int PLC_In; |
Kovalev_D | 116:66f1f0ff2dab | 216 | |
igor_v | 127:6a7472d67804 | 217 | |
igor_v | 127:6a7472d67804 | 218 | PLC_In = Gyro.AD_Slow; //выбираем даные для фильтрации |
Kovalev_D | 116:66f1f0ff2dab | 219 | // PLC_In = Gyro.AD_Fast; |
Kovalev_D | 128:1e4675a36c93 | 220 | //или+,или-(знак) |
Kovalev_D | 128:1e4675a36c93 | 221 | Gyro.PLC_Delta = PLC_In - Gyro.PLC_Old; // узнаем приращение |
Kovalev_D | 128:1e4675a36c93 | 222 | // (знак) * (то на что инкрементировали цап) |
Kovalev_D | 128:1e4675a36c93 | 223 | Gyro.PLC_DeltaADD = Gyro.PLC_Delta * Gyro.PLC_ADC_DOld; //приращение с учетом знака (и количества) прошлого приращения |
Kovalev_D | 128:1e4675a36c93 | 224 | Gyro.PLC_Old = PLC_In; // запоминание значения |
igor_v | 127:6a7472d67804 | 225 | |
Kovalev_D | 128:1e4675a36c93 | 226 | if(Gyro.RgConA&0x2) // если включон контур регулирования |
igor_v | 127:6a7472d67804 | 227 | { |
Kovalev_D | 140:1fbf117fc120 | 228 | if (Gyro.PLC_Error2Mode > 0) {Gyro.PLC_Error2Mode --; Gyro.PLC_ADC_DOld = 0; } // если ошибка(нахожление в двух модовом) |
Kovalev_D | 128:1e4675a36c93 | 229 | else if ( Gyro.PLC_Delta > (3000 * 65536)) {Spi.DAC_B += 2500; Gyro.PLC_Error2Mode = 5; Gyro.PLC_ADC_DOld = 0;} // проверка на двух модовость |
Kovalev_D | 128:1e4675a36c93 | 230 | else if ( Gyro.PLC_Delta < (-3000 * 65536)) {Spi.DAC_B += 2500; Gyro.PLC_Error2Mode = 5; Gyro.PLC_ADC_DOld = 0;} |
Kovalev_D | 128:1e4675a36c93 | 231 | |
igor_v | 127:6a7472d67804 | 232 | else if (Gyro.PLC_DeltaADD > 0) |
igor_v | 127:6a7472d67804 | 233 | { |
Kovalev_D | 128:1e4675a36c93 | 234 | |
Kovalev_D | 128:1e4675a36c93 | 235 | // Gyro.PLC_ADC_DOld = (Gyro.PLC_DeltaADD /6553600 )+1; |
Kovalev_D | 128:1e4675a36c93 | 236 | Gyro.PLC_ADC_DOld = 1; |
igor_v | 127:6a7472d67804 | 237 | } |
igor_v | 127:6a7472d67804 | 238 | else if (Gyro.PLC_DeltaADD < 0) |
igor_v | 127:6a7472d67804 | 239 | { |
igor_v | 127:6a7472d67804 | 240 | |
Kovalev_D | 128:1e4675a36c93 | 241 | // Gyro.PLC_ADC_DOld = (Gyro.PLC_DeltaADD /6553600 )-1; |
Kovalev_D | 128:1e4675a36c93 | 242 | Gyro.PLC_ADC_DOld = -1; |
igor_v | 127:6a7472d67804 | 243 | } |
igor_v | 127:6a7472d67804 | 244 | else |
igor_v | 127:6a7472d67804 | 245 | { |
Kovalev_D | 128:1e4675a36c93 | 246 | Gyro.PLC_ADC_DOld = 1; |
igor_v | 127:6a7472d67804 | 247 | } |
igor_v | 127:6a7472d67804 | 248 | } |
igor_v | 127:6a7472d67804 | 249 | else |
igor_v | 127:6a7472d67804 | 250 | { |
Kovalev_D | 128:1e4675a36c93 | 251 | Gyro.PLC_Error2Mode = 1; Gyro.PLC_DeltaADD = 0; |
igor_v | 127:6a7472d67804 | 252 | } |
Kovalev_D | 128:1e4675a36c93 | 253 | |
Kovalev_D | 141:c6de20b9b483 | 254 | |
Kovalev_D | 141:c6de20b9b483 | 255 | Spi.DAC_B += Gyro.PLC_ADC_DOld * 16; |
Kovalev_D | 140:1fbf117fc120 | 256 | |
Kovalev_D | 140:1fbf117fc120 | 257 | |
Kovalev_D | 128:1e4675a36c93 | 258 | if ( Spi.DAC_B < 1000 ) {Spi.DAC_B = 32000; Gyro.PLC_Error2Mode = 5; Gyro.PLC_DeltaADD = 0;} |
Kovalev_D | 128:1e4675a36c93 | 259 | if ( Spi.DAC_B > 63000 ) {Spi.DAC_B = 32000; Gyro.PLC_Error2Mode = 5; Gyro.PLC_DeltaADD = 0;} |
Kovalev_D | 141:c6de20b9b483 | 260 | |
Kovalev_D | 141:c6de20b9b483 | 261 | if(Gyro.LogPLC==1) |
Kovalev_D | 141:c6de20b9b483 | 262 | { |
Kovalev_D | 141:c6de20b9b483 | 263 | |
Kovalev_D | 141:c6de20b9b483 | 264 | sprintf((Time),"%d %d %d\r\n", Spi.DAC_B, Gyro.StrayPLC_flag, temp9);//выдаем в терминал для постройки граффика регулировки периметра. |
Kovalev_D | 141:c6de20b9b483 | 265 | WriteCon(Time); |
Kovalev_D | 141:c6de20b9b483 | 266 | } |
igor_v | 127:6a7472d67804 | 267 | |
Kovalev_D | 128:1e4675a36c93 | 268 | } |
Kovalev_D | 116:66f1f0ff2dab | 269 | |
Kovalev_D | 116:66f1f0ff2dab | 270 | |
Kovalev_D | 141:c6de20b9b483 | 271 | */ |
Kovalev_D | 116:66f1f0ff2dab | 272 | |
Kovalev_D | 116:66f1f0ff2dab | 273 | void PlcRegul_old(void) // на всяни й случай |
Kovalev_D | 112:4a96133a1311 | 274 | { |
Kovalev_D | 112:4a96133a1311 | 275 | int Delta; |
Kovalev_D | 112:4a96133a1311 | 276 | |
Kovalev_D | 112:4a96133a1311 | 277 | ADD_AMP+=Spi.ADC5; |
Kovalev_D | 112:4a96133a1311 | 278 | Count_AMP++; |
Kovalev_D | 112:4a96133a1311 | 279 | if(Count_AMP>=(32*32+8)) |
Kovalev_D | 112:4a96133a1311 | 280 | { |
Kovalev_D | 112:4a96133a1311 | 281 | Delta = ADD_AMP - Cur_Amp; |
Kovalev_D | 112:4a96133a1311 | 282 | |
Kovalev_D | 112:4a96133a1311 | 283 | if(Gyro.RgConA&0x2) |
Kovalev_D | 112:4a96133a1311 | 284 | { |
Kovalev_D | 112:4a96133a1311 | 285 | if (Znak_Amp > 1) {Znak_Amp --;} |
Kovalev_D | 112:4a96133a1311 | 286 | else if ( Delta > 30000000 ) {AD_Regul += 5000000; Znak_Amp = 5;} |
Kovalev_D | 112:4a96133a1311 | 287 | else if ( Delta < (-3000000)) {AD_Regul += 5000000; Znak_Amp = 5;} |
Kovalev_D | 112:4a96133a1311 | 288 | else if ((Delta * Znak_Amp) > 0) |
Kovalev_D | 112:4a96133a1311 | 289 | { |
Kovalev_D | 112:4a96133a1311 | 290 | Znak_Amp = 1; |
Kovalev_D | 112:4a96133a1311 | 291 | AD_Regul -= (Delta * Znak_Amp * 10); |
Kovalev_D | 112:4a96133a1311 | 292 | } |
Kovalev_D | 112:4a96133a1311 | 293 | else |
Kovalev_D | 112:4a96133a1311 | 294 | { |
Kovalev_D | 112:4a96133a1311 | 295 | Znak_Amp = -1; |
Kovalev_D | 112:4a96133a1311 | 296 | AD_Regul -= (Delta * Znak_Amp * 10); |
Kovalev_D | 112:4a96133a1311 | 297 | } |
Kovalev_D | 112:4a96133a1311 | 298 | |
Kovalev_D | 112:4a96133a1311 | 299 | Spi.DAC_B = (AD_Regul + 0x1fffffff)/65536; |
Kovalev_D | 112:4a96133a1311 | 300 | } |
Kovalev_D | 112:4a96133a1311 | 301 | Cur_Amp=ADD_AMP; Count_AMP=0; ADD_AMP=0; |
Kovalev_D | 112:4a96133a1311 | 302 | } |
Kovalev_D | 112:4a96133a1311 | 303 | |
igor_v | 110:6406b7ac0442 | 304 | } |
igor_v | 110:6406b7ac0442 | 305 | |
igor_v | 110:6406b7ac0442 | 306 | |
Kovalev_D | 116:66f1f0ff2dab | 307 | |
Kovalev_D | 116:66f1f0ff2dab | 308 | |
Kovalev_D | 112:4a96133a1311 | 309 | void DAC_OutPut(void)//выдача в цапы |
igor_v | 0:8ad47e2b6f00 | 310 | { |
Kovalev_D | 112:4a96133a1311 | 311 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 312 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 313 | LPC_SSP0->DR=0x5555; |
igor_v | 0:8ad47e2b6f00 | 314 | |
igor_v | 110:6406b7ac0442 | 315 | if (CountV31 & 1) { //если нечетный такт то |
igor_v | 31:c783288001b5 | 316 | LPC_SSP0->DR = WRITE_DAC0; //e.команда для ЦАП_0 передавать. |
igor_v | 31:c783288001b5 | 317 | LPC_SSP0->DR = (Spi.DAC_A); //e. передача 12 бит |
Kovalev_D | 141:c6de20b9b483 | 318 | } |
Kovalev_D | 141:c6de20b9b483 | 319 | else { //если такт четный. |
Kovalev_D | 141:c6de20b9b483 | 320 | LPC_SSP0->DR = WRITE_DAC1 ; //e.команда для ЦАП_1 передавать. |
Kovalev_D | 141:c6de20b9b483 | 321 | |
Kovalev_D | 141:c6de20b9b483 | 322 | switch( Gyro.StrayPLC_flag) { |
Kovalev_D | 142:7a6f68601291 | 323 | |
Kovalev_D | 141:c6de20b9b483 | 324 | case 0://режим без воздействия |
Kovalev_D | 141:c6de20b9b483 | 325 | LPC_SSP0->DR = (Spi.DAC_B); |
Kovalev_D | 141:c6de20b9b483 | 326 | temp9=Spi.DAC_B; |
Kovalev_D | 141:c6de20b9b483 | 327 | break; |
Kovalev_D | 142:7a6f68601291 | 328 | |
Kovalev_D | 141:c6de20b9b483 | 329 | case 1://малое воздействие |
Kovalev_D | 142:7a6f68601291 | 330 | temp9=Spi.DAC_B + Gyro.StrayPLC_Pls; |
Kovalev_D | 141:c6de20b9b483 | 331 | LPC_SSP0->DR = temp9; |
Kovalev_D | 142:7a6f68601291 | 332 | break; |
Kovalev_D | 141:c6de20b9b483 | 333 | |
Kovalev_D | 142:7a6f68601291 | 334 | case 3://малое воздействие |
Kovalev_D | 142:7a6f68601291 | 335 | temp9=Spi.DAC_B + Gyro.StrayPLC_Mns; |
Kovalev_D | 142:7a6f68601291 | 336 | LPC_SSP0->DR = temp9; |
Kovalev_D | 141:c6de20b9b483 | 337 | break; |
Kovalev_D | 142:7a6f68601291 | 338 | |
Kovalev_D | 141:c6de20b9b483 | 339 | case 2://большое воздействие |
Kovalev_D | 141:c6de20b9b483 | 340 | temp9=Spi.DAC_B + Gyro.StrayPLC_2Mode; |
Kovalev_D | 141:c6de20b9b483 | 341 | LPC_SSP0->DR = temp9;//вгоняем в многомодовый режим |
Kovalev_D | 141:c6de20b9b483 | 342 | break; |
Kovalev_D | 142:7a6f68601291 | 343 | |
Kovalev_D | 141:c6de20b9b483 | 344 | } |
Kovalev_D | 141:c6de20b9b483 | 345 | // LPC_SSP0->DR = Spi.DAC_B; //e. передача 12 бит |
Kovalev_D | 141:c6de20b9b483 | 346 | |
igor_v | 31:c783288001b5 | 347 | } |
Kovalev_D | 112:4a96133a1311 | 348 | } |
Kovalev_D | 112:4a96133a1311 | 349 | |
Kovalev_D | 112:4a96133a1311 | 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 | 113:8be429494918 | 376 | |
Kovalev_D | 113:8be429494918 | 377 | |
Kovalev_D | 113:8be429494918 | 378 | |
Kovalev_D | 113:8be429494918 | 379 | /* |
Kovalev_D | 112:4a96133a1311 | 380 | void SPI_Exchange(void) |
Kovalev_D | 112:4a96133a1311 | 381 | { |
Kovalev_D | 112:4a96133a1311 | 382 | unsigned int DummySPI; |
Kovalev_D | 112:4a96133a1311 | 383 | |
Kovalev_D | 112:4a96133a1311 | 384 | |
Kovalev_D | 112:4a96133a1311 | 385 | Spi.ADC5 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 386 | Spi.ADC4 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 387 | Spi.ADC3 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 388 | Spi.ADC2 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 389 | Spi.ADC1 = LPC_SSP0->DR; |
Kovalev_D | 112:4a96133a1311 | 390 | |
Kovalev_D | 112:4a96133a1311 | 391 | Input.ArrayIn[2]= Spi.ADC5; |
Kovalev_D | 112:4a96133a1311 | 392 | |
Kovalev_D | 112:4a96133a1311 | 393 | DAC_OutPut(); |
igor_v | 0:8ad47e2b6f00 | 394 | |
Kovalev_D | 99:3d8f206ceac2 | 395 | // LPC_DAC->CR = (((SinPLC[CountV64]*35/5)+24300));// модулятор |
Kovalev_D | 112:4a96133a1311 | 396 | |
Kovalev_D | 89:a0d344db227e | 397 | while (LPC_SSP0->SR & RX_SSP_notEMPT) //если буфер SPI не пуст. |
Kovalev_D | 89:a0d344db227e | 398 | DummySPI = LPC_SSP0->DR; //очистить буфер. |
igor_v | 31:c783288001b5 | 399 | |
Kovalev_D | 112:4a96133a1311 | 400 | //заполнение буферов еденичных значений АЦП. |
Kovalev_D | 112:4a96133a1311 | 401 | Buff_ADC_1 [CountV31] = Spi.ADC1; |
Kovalev_D | 112:4a96133a1311 | 402 | Buff_ADC_2 [CountV31] = Spi.ADC2; |
Kovalev_D | 112:4a96133a1311 | 403 | Buff_ADC_3 [CountV31] = Spi.ADC3; |
Kovalev_D | 112:4a96133a1311 | 404 | Buff_ADC_4 [CountV31] = Spi.ADC4; |
Kovalev_D | 95:dd51e577e114 | 405 | Buff_ADC_5 [CountV255] = Spi.ADC5; // ампл ацп. |
igor_v | 110:6406b7ac0442 | 406 | |
Kovalev_D | 112:4a96133a1311 | 407 | |
igor_v | 110:6406b7ac0442 | 408 | Temp_AMP64P += Buff_ADC_5[CountV255]; |
Kovalev_D | 96:1c8536458119 | 409 | Temp_AMP64P -= Buff_ADC_5[(CountV255-64) & 0xff]; // заполнение буфера накопленых приращений за 8 тактов |
Kovalev_D | 96:1c8536458119 | 410 | Buff_AMP64P[CountV255] = (unsigned int) (Temp_AMP64P); |
Kovalev_D | 96:1c8536458119 | 411 | |
igor_v | 31:c783288001b5 | 412 | |
Kovalev_D | 47:d902ef6f7564 | 413 | Temp_ADC_2 += Buff_ADC_2[CountV31]; |
Kovalev_D | 47:d902ef6f7564 | 414 | Temp_ADC_2 -= Buff_ADC_2[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 415 | |
Kovalev_D | 47:d902ef6f7564 | 416 | Temp_ADC_3 += Buff_ADC_3[CountV31]; |
Kovalev_D | 95:dd51e577e114 | 417 | Temp_ADC_3 -= Buff_ADC_3[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 418 | |
Kovalev_D | 47:d902ef6f7564 | 419 | Temp_ADC_4 += Buff_ADC_4[CountV31]; |
Kovalev_D | 47:d902ef6f7564 | 420 | Temp_ADC_4 -= Buff_ADC_4[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 421 | |
igor_v | 31:c783288001b5 | 422 | Temp_ADC_5 += Buff_ADC_1[CountV255]; |
igor_v | 31:c783288001b5 | 423 | Temp_ADC_5 -= Buff_ADC_1[(CountV255-32) & 0xff]; |
Kovalev_D | 112:4a96133a1311 | 424 | Spi.PLC_NewData=1; |
Kovalev_D | 113:8be429494918 | 425 | }*/ |