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