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