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