123
Fork of LG by
PLC_reg.c@112:4a96133a1311, 2016-04-04 (annotated)
- Committer:
- Kovalev_D
- Date:
- Mon Apr 04 11:09:56 2016 +0000
- Revision:
- 112:4a96133a1311
- Parent:
- 21:bc8c1cec3da6
- Child:
- 129:406995a91322
IRQ
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 0:8ad47e2b6f00 | 1 | /****************************************Copyright (c)**************************************************** |
igor_v | 0:8ad47e2b6f00 | 2 | **--------------File Info--------------------------------------------------------------------------------- |
igor_v | 0:8ad47e2b6f00 | 3 | ** File name: PLC_reg.c |
igor_v | 0:8ad47e2b6f00 | 4 | ** Last modified Date: 2011-09-26 |
igor_v | 0:8ad47e2b6f00 | 5 | ** Last Version: V1.00 |
igor_v | 0:8ad47e2b6f00 | 6 | ** Descriptions: Routines for system of perimeter regulating unit |
igor_v | 0:8ad47e2b6f00 | 7 | ** |
igor_v | 0:8ad47e2b6f00 | 8 | **-------------------------------------------------------------------------------------------------------- |
igor_v | 0:8ad47e2b6f00 | 9 | ** Created by: Electrooptica Incorp. |
igor_v | 0:8ad47e2b6f00 | 10 | ** Created date: 2011-09-26 |
igor_v | 0:8ad47e2b6f00 | 11 | ** Version: V1.00 |
igor_v | 21:bc8c1cec3da6 | 12 | ** Descriptions: |
igor_v | 0:8ad47e2b6f00 | 13 | ** |
igor_v | 21:bc8c1cec3da6 | 14 | **-------------------------------------------------------------------------------------------------------- |
igor_v | 0:8ad47e2b6f00 | 15 | *********************************************************************************************************/ |
igor_v | 1:f2adcae3d304 | 16 | #include "Global.h" |
igor_v | 1:f2adcae3d304 | 17 | |
igor_v | 0:8ad47e2b6f00 | 18 | |
igor_v | 21:bc8c1cec3da6 | 19 | #define CONFIG_HFO_REG //r. изменяем коэффициент передачи контура ГВЧ от номинального на время обнуления |
igor_v | 0:8ad47e2b6f00 | 20 | #define WP_TRANSITION_ENA // |
igor_v | 21:bc8c1cec3da6 | 21 | |
igor_v | 21:bc8c1cec3da6 | 22 | //e.--- constants for the CPLC regulator ------------------------------------------------------- //r.--- константы для контура СРП ------------------------------------------------------- |
igor_v | 0:8ad47e2b6f00 | 23 | |
igor_v | 21:bc8c1cec3da6 | 24 | #define PLC_SHIFT (6) |
igor_v | 21:bc8c1cec3da6 | 25 | #define PLC_PHASE_DET_SHIFT (18) //e. 18 - for analog output //r. 18 - для аналогового |
igor_v | 0:8ad47e2b6f00 | 26 | |
igor_v | 21:bc8c1cec3da6 | 27 | #define PLC_RESET_THRESHOLD (-3276) //e. correspond to the voltage +1.2 Volts //r. соответствует напряжению +1.2 вольта |
igor_v | 0:8ad47e2b6f00 | 28 | #define WP_REG32MAX_SATURATION (32767 << PLC_SHIFT) |
igor_v | 0:8ad47e2b6f00 | 29 | #define WP_REG32MIN_NEW_SATURATION (PLC_RESET_THRESHOLD << PLC_SHIFT) |
igor_v | 21:bc8c1cec3da6 | 30 | #define WP_TMP_THRESHOLD (7) //e. temperature threshold, defining heats up or cool down the device //r. температурный порог, определяющий нагревается или охлаждается прибор |
igor_v | 0:8ad47e2b6f00 | 31 | |
igor_v | 0:8ad47e2b6f00 | 32 | |
igor_v | 0:8ad47e2b6f00 | 33 | #define debugPLC |
igor_v | 0:8ad47e2b6f00 | 34 | |
igor_v | 21:bc8c1cec3da6 | 35 | int WP_reg32; |
igor_v | 21:bc8c1cec3da6 | 36 | int WP_Phase_Det; //e. output of the phase detector of the CPLC (in a digital kind)//r. выход фазового детектора СРП (в цифровом виде) |
igor_v | 21:bc8c1cec3da6 | 37 | int WP_reset_heating; //e. voltage of reset at heating //r. напряжение сброса при нагревании |
igor_v | 21:bc8c1cec3da6 | 38 | int WP_reset_cooling; //e. voltage of reset at cooling //r. напряжение сброса при охлаждении |
igor_v | 21:bc8c1cec3da6 | 39 | int MaxDelayPLC; |
igor_v | 21:bc8c1cec3da6 | 40 | int sin_func[100]; |
igor_v | 0:8ad47e2b6f00 | 41 | |
igor_v | 0:8ad47e2b6f00 | 42 | int phase_Digital; |
igor_v | 0:8ad47e2b6f00 | 43 | |
igor_v | 21:bc8c1cec3da6 | 44 | int WP_PhaseDetectorRate(int PhaseDetInput, int IntegrateTime); |
igor_v | 0:8ad47e2b6f00 | 45 | |
igor_v | 0:8ad47e2b6f00 | 46 | /****************************************************************************** |
igor_v | 0:8ad47e2b6f00 | 47 | ** Function name: init_PLC |
igor_v | 0:8ad47e2b6f00 | 48 | ** |
igor_v | 21:bc8c1cec3da6 | 49 | ** Descriptions: Initialization procedure for PLC regulator |
igor_v | 0:8ad47e2b6f00 | 50 | ** |
igor_v | 21:bc8c1cec3da6 | 51 | ** Parameters: None |
igor_v | 21:bc8c1cec3da6 | 52 | ** Returned value: None |
igor_v | 21:bc8c1cec3da6 | 53 | ** |
igor_v | 0:8ad47e2b6f00 | 54 | ******************************************************************************/ |
igor_v | 0:8ad47e2b6f00 | 55 | void init_PLC(void) |
igor_v | 0:8ad47e2b6f00 | 56 | { |
igor_v | 21:bc8c1cec3da6 | 57 | int i; |
igor_v | 21:bc8c1cec3da6 | 58 | //( 1,2 вольта) |
igor_v | 21:bc8c1cec3da6 | 59 | if (Device_blk.Str.WP_reset < PLC_RESET_THRESHOLD) //e. напряжение после сброса на нагревателе не должно превышать 1,2 вольта. |
igor_v | 21:bc8c1cec3da6 | 60 | //(исходное значение регулятора СРП (после сброса)) < (-3276). |
igor_v | 21:bc8c1cec3da6 | 61 | { |
igor_v | 21:bc8c1cec3da6 | 62 | Device_blk.Str.WP_reset = PLC_RESET_THRESHOLD + 1;//(-3275) |
igor_v | 21:bc8c1cec3da6 | 63 | } |
igor_v | 21:bc8c1cec3da6 | 64 | //напряжение на СРП = (мин. значение на нагревателе + мах. значение на нагревателе)/2 |
igor_v | 21:bc8c1cec3da6 | 65 | Output.Str.WP_reg = (Device_blk.Str.WP_rup + Device_blk.Str.WP_rdw) >> 1; //e. WP_reg start voltage is (WP_rup - WP_rdw)/2 |
igor_v | 21:bc8c1cec3da6 | 66 | |
igor_v | 21:bc8c1cec3da6 | 67 | // напряжение на СРП << 6 |
igor_v | 21:bc8c1cec3da6 | 68 | WP_reg32 = Output.Str.WP_reg<<PLC_SHIFT; |
igor_v | 21:bc8c1cec3da6 | 69 | |
igor_v | 21:bc8c1cec3da6 | 70 | if ((Device_blk.Str.PI_b3>100)||(Device_blk.Str.PI_b3<10)) //e. Если требуемая частота модулятора СРП больше 1kHz или меньше 100Hz |
igor_v | 21:bc8c1cec3da6 | 71 | Device_blk.Str.PI_b3 = 40; //e. Установить частоту в 250Hz (частота дребездения) |
igor_v | 0:8ad47e2b6f00 | 72 | |
igor_v | 21:bc8c1cec3da6 | 73 | for (i = 0; i<Device_blk.Str.PI_b3; i++) { //e. Сканирование СРП сигнала |
igor_v | 21:bc8c1cec3da6 | 74 | float temp = sin((float)i*2.0*PI/(float)Device_blk.Str.PI_b3); /// вычисление значений синуса |
igor_v | 21:bc8c1cec3da6 | 75 | /// для частоты модулятора срп (PI_b3), |
igor_v | 21:bc8c1cec3da6 | 76 | sin_func[i] = (int)(temp*32767); /// и калибровка этих значений для АЦП. |
igor_v | 21:bc8c1cec3da6 | 77 | if (sin_func[i] < 0) |
igor_v | 21:bc8c1cec3da6 | 78 | sin_func[i] += 65536; |
igor_v | 0:8ad47e2b6f00 | 79 | } |
igor_v | 21:bc8c1cec3da6 | 80 | |
igor_v | 21:bc8c1cec3da6 | 81 | //e. calculation of filter coefficients for PLC |
igor_v | 0:8ad47e2b6f00 | 82 | // 250 Hz 10 KHz |
igor_v | 21:bc8c1cec3da6 | 83 | init_BandPass( 1.0/(float)Device_blk.Str.PI_b3, 10.0/(float)(DEVICE_SAMPLE_RATE_HZ), PLC); //полософой фильтр для выделения частоты колебания модулятора |
igor_v | 21:bc8c1cec3da6 | 84 | //и определение коэфициентов(aPLC[0-2] и bPLC[0-2]) |
igor_v | 21:bc8c1cec3da6 | 85 | //(дребездение срп для определения греть или охлождать основной элемент управления.) |
igor_v | 0:8ad47e2b6f00 | 86 | |
igor_v | 21:bc8c1cec3da6 | 87 | Device_blk.Str.WP_scl <<= 1; //e. during fist 10 seconds after start we state Device_blk.Str.WP_scl = 2*Device_blk.Str.WP_scl |
igor_v | 21:bc8c1cec3da6 | 88 | // первые 10 секунд работать с коэфициентом передачи * 2 |
igor_v | 21:bc8c1cec3da6 | 89 | |
igor_v | 21:bc8c1cec3da6 | 90 | MaxDelayPLC = Device_blk.Str.PI_b3>>1; //e. max expected delay for phase detector output |
igor_v | 0:8ad47e2b6f00 | 91 | } // init_PLC |
igor_v | 21:bc8c1cec3da6 | 92 | |
igor_v | 0:8ad47e2b6f00 | 93 | /****************************************************************************** |
igor_v | 0:8ad47e2b6f00 | 94 | ** Function name: PLC_MeanderDelay |
igor_v | 0:8ad47e2b6f00 | 95 | ** |
igor_v | 21:bc8c1cec3da6 | 96 | ** Descriptions: Outgoing of the delayed meander signal for the PLC regulator |
igor_v | 0:8ad47e2b6f00 | 97 | ** |
igor_v | 21:bc8c1cec3da6 | 98 | ** parameters: Input value |
igor_v | 21:bc8c1cec3da6 | 99 | ** Returned value: Delayed value |
igor_v | 21:bc8c1cec3da6 | 100 | ** |
igor_v | 0:8ad47e2b6f00 | 101 | ******************************************************************************/ |
igor_v | 0:8ad47e2b6f00 | 102 | int PLC_MeanderDelay(int flag) |
igor_v | 0:8ad47e2b6f00 | 103 | { |
igor_v | 21:bc8c1cec3da6 | 104 | static int poz_counter = 0, neg_counter = 0, flg_delay; |
igor_v | 21:bc8c1cec3da6 | 105 | |
igor_v | 21:bc8c1cec3da6 | 106 | if (Device_blk.Str.WP_ref == 0) { |
igor_v | 21:bc8c1cec3da6 | 107 | return (flag); |
igor_v | 21:bc8c1cec3da6 | 108 | } |
igor_v | 21:bc8c1cec3da6 | 109 | |
igor_v | 21:bc8c1cec3da6 | 110 | //e. check whether delay exceeds the greatest possible value //r. проверка не превосходит ли задержка максимально возможную |
igor_v | 21:bc8c1cec3da6 | 111 | if (Device_blk.Str.WP_ref > MaxDelayPLC) { |
igor_v | 21:bc8c1cec3da6 | 112 | Device_blk.Str.WP_ref = MaxDelayPLC; |
igor_v | 21:bc8c1cec3da6 | 113 | } |
igor_v | 0:8ad47e2b6f00 | 114 | |
igor_v | 21:bc8c1cec3da6 | 115 | if (flag) { //e. outgoing poz_sin_flag flag, which delayed by the WP_ref //r. формирование задержанного на величину WP_ref флага poz_sin_flag |
igor_v | 21:bc8c1cec3da6 | 116 | neg_counter = 0; |
igor_v | 21:bc8c1cec3da6 | 117 | poz_counter++; |
igor_v | 21:bc8c1cec3da6 | 118 | } else { |
igor_v | 21:bc8c1cec3da6 | 119 | poz_counter = 0; |
igor_v | 21:bc8c1cec3da6 | 120 | neg_counter++; |
igor_v | 21:bc8c1cec3da6 | 121 | } |
igor_v | 21:bc8c1cec3da6 | 122 | if (poz_counter == Device_blk.Str.WP_ref) { |
igor_v | 21:bc8c1cec3da6 | 123 | flg_delay = 0; |
igor_v | 21:bc8c1cec3da6 | 124 | } |
igor_v | 21:bc8c1cec3da6 | 125 | if (neg_counter == Device_blk.Str.WP_ref) { |
igor_v | 21:bc8c1cec3da6 | 126 | flg_delay = 1; |
igor_v | 21:bc8c1cec3da6 | 127 | } |
igor_v | 21:bc8c1cec3da6 | 128 | return (flg_delay); |
igor_v | 21:bc8c1cec3da6 | 129 | } |
igor_v | 0:8ad47e2b6f00 | 130 | /****************************************************************************** |
igor_v | 0:8ad47e2b6f00 | 131 | ** Function name: clc_PLC |
igor_v | 0:8ad47e2b6f00 | 132 | ** |
igor_v | 21:bc8c1cec3da6 | 133 | ** Descriptions: Procedure of initial processing for the CPLC regulator |
igor_v | 0:8ad47e2b6f00 | 134 | ** |
igor_v | 21:bc8c1cec3da6 | 135 | ** parameters: None |
igor_v | 21:bc8c1cec3da6 | 136 | ** Returned value: None |
igor_v | 21:bc8c1cec3da6 | 137 | ** |
igor_v | 0:8ad47e2b6f00 | 138 | ******************************************************************************/ |
Kovalev_D | 112:4a96133a1311 | 139 | /*void clc_PLC(void) |
igor_v | 0:8ad47e2b6f00 | 140 | { |
igor_v | 21:bc8c1cec3da6 | 141 | static int is_zeroing = 0; |
igor_v | 21:bc8c1cec3da6 | 142 | static int zero_delay = 0; |
igor_v | 0:8ad47e2b6f00 | 143 | // static int WP_DelaySin_Array[21] = {0}; |
igor_v | 0:8ad47e2b6f00 | 144 | // int phase_Digital; |
igor_v | 21:bc8c1cec3da6 | 145 | int poz_sin_flag; |
igor_v | 21:bc8c1cec3da6 | 146 | int poz_sin_flag_delayed; |
igor_v | 21:bc8c1cec3da6 | 147 | |
igor_v | 0:8ad47e2b6f00 | 148 | |
igor_v | 21:bc8c1cec3da6 | 149 | static int plc_reset32; |
igor_v | 21:bc8c1cec3da6 | 150 | static enum { |
igor_v | 21:bc8c1cec3da6 | 151 | //r. состояние линейного перехода при обнулении СРП |
igor_v | 21:bc8c1cec3da6 | 152 | FINISHED, //r. линейный переход завершен |
igor_v | 21:bc8c1cec3da6 | 153 | TRANS_HEATING, //r. переход выполняется при нагревании |
igor_v | 21:bc8c1cec3da6 | 154 | TRANS_COOLING //r. переход выполняется при охлаждении |
igor_v | 21:bc8c1cec3da6 | 155 | } plc_transiton = FINISHED; |
igor_v | 0:8ad47e2b6f00 | 156 | |
igor_v | 0:8ad47e2b6f00 | 157 | // int i; |
igor_v | 0:8ad47e2b6f00 | 158 | |
igor_v | 21:bc8c1cec3da6 | 159 | if (Output.Str.WP_sin >= 32768) { |
igor_v | 21:bc8c1cec3da6 | 160 | poz_sin_flag = 0; |
igor_v | 21:bc8c1cec3da6 | 161 | } else { |
igor_v | 21:bc8c1cec3da6 | 162 | poz_sin_flag = 1; |
igor_v | 21:bc8c1cec3da6 | 163 | } |
igor_v | 0:8ad47e2b6f00 | 164 | |
igor_v | 21:bc8c1cec3da6 | 165 | //r. полосовой фильтр для контура СРП |
Kovalev_D | 112:4a96133a1311 | 166 | WP_Phase_Det = PLC_PhaseDetFilt(Output.Str.WP_sin/Input.StrIn.WP_sel);*/ |
Kovalev_D | 112:4a96133a1311 | 167 | /* |
igor_v | 0:8ad47e2b6f00 | 168 | |
igor_v | 21:bc8c1cec3da6 | 169 | if (WP_Phase_Det >0) { |
igor_v | 21:bc8c1cec3da6 | 170 | //r. WP_sel>0 |
igor_v | 21:bc8c1cec3da6 | 171 | phase_Digital = 1; |
igor_v | 21:bc8c1cec3da6 | 172 | } else { |
igor_v | 21:bc8c1cec3da6 | 173 | phase_Digital = -1; |
igor_v | 21:bc8c1cec3da6 | 174 | } |
igor_v | 21:bc8c1cec3da6 | 175 | // from this WP_Phase_Det - modulated signal like LIM_DIG |
igor_v | 21:bc8c1cec3da6 | 176 | |
igor_v | 21:bc8c1cec3da6 | 177 | poz_sin_flag_delayed = PLC_MeanderDelay(poz_sin_flag); |
igor_v | 0:8ad47e2b6f00 | 178 | |
igor_v | 21:bc8c1cec3da6 | 179 | if(poz_sin_flag_delayed) { |
igor_v | 21:bc8c1cec3da6 | 180 | WP_Phase_Det = -WP_Phase_Det; |
igor_v | 21:bc8c1cec3da6 | 181 | phase_Digital = -phase_Digital; |
igor_v | 21:bc8c1cec3da6 | 182 | } |
igor_v | 21:bc8c1cec3da6 | 183 | // from this WP_Phase_Det - demodulated signal like LIDEM_DIG |
igor_v | 0:8ad47e2b6f00 | 184 | |
igor_v | 21:bc8c1cec3da6 | 185 | if (!is_zeroing) { //r. Не пора выполнять обнуление |
igor_v | 21:bc8c1cec3da6 | 186 | //r. нет обнуления |
igor_v | 21:bc8c1cec3da6 | 187 | if ((WP_reg32 > (Device_blk.Str.WP_rup << PLC_SHIFT)) && IsHeating) { //r. происходит нагревание |
igor_v | 21:bc8c1cec3da6 | 188 | is_zeroing = 1; |
igor_v | 21:bc8c1cec3da6 | 189 | //r. напряжение сброса при нагревании |
igor_v | 21:bc8c1cec3da6 | 190 | WP_reset_heating = CPL_reset_calc(Device_blk.Str.WP_reset, Device_blk.Str.K_WP_rst_heating, Temp_Aver, Device_blk.Str.TemperNormal); |
igor_v | 21:bc8c1cec3da6 | 191 | plc_transiton = TRANS_HEATING; |
igor_v | 21:bc8c1cec3da6 | 192 | plc_reset32 = WP_reset_heating << PLC_SHIFT;; |
igor_v | 0:8ad47e2b6f00 | 193 | |
igor_v | 21:bc8c1cec3da6 | 194 | Device_blk.Str.HF_scl = Device_blk.Str.HF_scl_2; //r. изменяем коэффициент передачи контура ГВЧ от номинального на время обнуления |
igor_v | 21:bc8c1cec3da6 | 195 | } else if ((WP_reg32 < (Device_blk.Str.WP_rdw << PLC_SHIFT)) && !IsHeating) { //r. охлаждение |
igor_v | 21:bc8c1cec3da6 | 196 | is_zeroing = 1; |
igor_v | 21:bc8c1cec3da6 | 197 | //r. напряжение сброса при охлаждении |
igor_v | 21:bc8c1cec3da6 | 198 | WP_reset_cooling = CPL_reset_calc(Device_blk.Str.WP_reset2, Device_blk.Str.K_WP_rst_cooling, Temp_Aver, Device_blk.Str.TemperNormal); |
igor_v | 0:8ad47e2b6f00 | 199 | |
igor_v | 21:bc8c1cec3da6 | 200 | plc_transiton = TRANS_COOLING; |
igor_v | 21:bc8c1cec3da6 | 201 | plc_reset32 = WP_reset_cooling << PLC_SHIFT; |
igor_v | 21:bc8c1cec3da6 | 202 | |
igor_v | 21:bc8c1cec3da6 | 203 | Device_blk.Str.HF_scl = Device_blk.Str.HF_scl_2; //r. изменяем коэффициент передачи контура ГВЧ от номинального на время обнуления |
igor_v | 21:bc8c1cec3da6 | 204 | } else //r. пороги не превышены, обычная работа контура |
igor_v | 21:bc8c1cec3da6 | 205 | WP_reg32 = L_mac(WP_reg32, phase_Digital, Device_blk.Str.WP_scl ); // WP_reg32 += phase_Digital * Device_blk.Str.WP_scl; |
igor_v | 0:8ad47e2b6f00 | 206 | |
igor_v | 21:bc8c1cec3da6 | 207 | } else { //r. флаг установлен (1) - режим обнуления |
igor_v | 21:bc8c1cec3da6 | 208 | |
igor_v | 21:bc8c1cec3da6 | 209 | if (plc_transiton != FINISHED) { |
igor_v | 21:bc8c1cec3da6 | 210 | if (plc_transiton == TRANS_HEATING) { |
igor_v | 0:8ad47e2b6f00 | 211 | |
igor_v | 21:bc8c1cec3da6 | 212 | WP_reg32 = L_sub(WP_reg32, Device_blk.Str.WP_transition_step); // WP_reg32 -= Device_blk.Str.WP_transition_step; |
igor_v | 21:bc8c1cec3da6 | 213 | if (WP_reg32 < plc_reset32) { |
igor_v | 21:bc8c1cec3da6 | 214 | zero_delay = 0; |
igor_v | 21:bc8c1cec3da6 | 215 | plc_transiton = FINISHED; //r.false; |
igor_v | 21:bc8c1cec3da6 | 216 | WP_reg32 = plc_reset32; |
igor_v | 21:bc8c1cec3da6 | 217 | } |
igor_v | 21:bc8c1cec3da6 | 218 | } else { // plc_transiton == TRANS_COOLING |
igor_v | 21:bc8c1cec3da6 | 219 | WP_reg32 = L_add(WP_reg32, Device_blk.Str.WP_transition_step); // WP_reg32 += Device_blk.Str.WP_transition_step; |
igor_v | 21:bc8c1cec3da6 | 220 | if (WP_reg32 > plc_reset32) { |
igor_v | 21:bc8c1cec3da6 | 221 | zero_delay = 0; |
igor_v | 21:bc8c1cec3da6 | 222 | plc_transiton = FINISHED; //r.false; |
igor_v | 21:bc8c1cec3da6 | 223 | WP_reg32 = plc_reset32; |
igor_v | 21:bc8c1cec3da6 | 224 | } |
igor_v | 21:bc8c1cec3da6 | 225 | } |
igor_v | 21:bc8c1cec3da6 | 226 | } else |
igor_v | 0:8ad47e2b6f00 | 227 | |
igor_v | 21:bc8c1cec3da6 | 228 | if (zero_delay < Device_blk.Str.WP_mdy) { |
igor_v | 21:bc8c1cec3da6 | 229 | zero_delay++; |
igor_v | 21:bc8c1cec3da6 | 230 | } else { //e. resetting was completed //r. обнуление закончилось |
igor_v | 21:bc8c1cec3da6 | 231 | is_zeroing = 0; |
igor_v | 21:bc8c1cec3da6 | 232 | //e. save the temperature for further comparison //r. запоминаем температуру для дальнейшего сравнения |
igor_v | 21:bc8c1cec3da6 | 233 | // TempOfReset = Temp_Aver; //r.x. Temp5_Aver; //r. Tmp_Out[TSENS_NUMB]; // T4; |
igor_v | 21:bc8c1cec3da6 | 234 | //r.x Zero_Numb_dbg++; // так можно подсчитывать число обнулений |
igor_v | 0:8ad47e2b6f00 | 235 | |
igor_v | 21:bc8c1cec3da6 | 236 | // DithFreqRangeCalc(); //e. calculation of range of the division factor for the dither drive frequency, depending on current temperature //r. расчет границ коэффициента деления для частоты вибропривода, зависящих от текущей температуры |
igor_v | 21:bc8c1cec3da6 | 237 | } |
igor_v | 21:bc8c1cec3da6 | 238 | } |
igor_v | 0:8ad47e2b6f00 | 239 | |
igor_v | 21:bc8c1cec3da6 | 240 | Saturation(WP_reg32, WP_REG32MAX_SATURATION, WP_REG32MIN_NEW_SATURATION); //e. the minimum corresponds to a small negative number, appropriate to PLC_RESET_THRESHOLD //r. минимум соответствует небольшому отрицательному числу, соотв-му PLC_RESET_THRESHOLD |
igor_v | 0:8ad47e2b6f00 | 241 | |
igor_v | 21:bc8c1cec3da6 | 242 | |
igor_v | 21:bc8c1cec3da6 | 243 | if ( loop_is_closed(WP_REG_ON) ) { //e. the regulator loop is closed //r. контур замкнут |
igor_v | 21:bc8c1cec3da6 | 244 | Output.Str.WP_reg = (int)(WP_reg32 >> PLC_SHIFT); //e. we use as controlling - voltages of the integrator //r. используем как управляющее - напряжения интегратора |
igor_v | 21:bc8c1cec3da6 | 245 | |
igor_v | 21:bc8c1cec3da6 | 246 | } else { //e. the regulator loop is open //r. контур разомкнут |
igor_v | 21:bc8c1cec3da6 | 247 | WP_reg32 = Output.Str.WP_reg << PLC_SHIFT; //e. set the previous value of the WP_reg //r. присваиваем предыдущее значение WP_reg |
igor_v | 0:8ad47e2b6f00 | 248 | |
igor_v | 21:bc8c1cec3da6 | 249 | } |
igor_v | 0:8ad47e2b6f00 | 250 | |
igor_v | 21:bc8c1cec3da6 | 251 | //e. integartion of output of the PD of the CPLC regulator for the technological output on the Rate command //r. интегрирование выхода ФД контура СРП для технологического вывода по команде Rate |
igor_v | 0:8ad47e2b6f00 | 252 | |
igor_v | 21:bc8c1cec3da6 | 253 | Output.Str.WP_pll = WP_PhaseDetectorRate( WP_Phase_Det, time_1_Sec); |
igor_v | 0:8ad47e2b6f00 | 254 | |
igor_v | 0:8ad47e2b6f00 | 255 | } // clc_PLC |
Kovalev_D | 112:4a96133a1311 | 256 | */ |
igor_v | 0:8ad47e2b6f00 | 257 | /****************************************************************************** |
igor_v | 0:8ad47e2b6f00 | 258 | ** Function name: Signal_2_Oscill |
igor_v | 0:8ad47e2b6f00 | 259 | ** |
igor_v | 21:bc8c1cec3da6 | 260 | ** Descriptions: Procedure of analog worm output |
igor_v | 21:bc8c1cec3da6 | 261 | ** |
igor_v | 21:bc8c1cec3da6 | 262 | ** parameters: Type of output |
igor_v | 21:bc8c1cec3da6 | 263 | ** Returned value: code to DAC |
igor_v | 0:8ad47e2b6f00 | 264 | ** |
igor_v | 0:8ad47e2b6f00 | 265 | ******************************************************************************/ |
igor_v | 21:bc8c1cec3da6 | 266 | int Signal_2_Oscill() //e. the signal for the control by scope on DAC output (was DS) //r. сигнал для контроля осциллографом на выходе ЦАП (бывший ДУП) |
igor_v | 0:8ad47e2b6f00 | 267 | { |
igor_v | 21:bc8c1cec3da6 | 268 | // Scope_Mode var not used now, reserved for future applications |
igor_v | 21:bc8c1cec3da6 | 269 | return (-WP_Phase_Det << 2); |
igor_v | 0:8ad47e2b6f00 | 270 | } // Signal_2_Oscill |
igor_v | 0:8ad47e2b6f00 | 271 | |
igor_v | 0:8ad47e2b6f00 | 272 | /****************************************************************************** |
igor_v | 0:8ad47e2b6f00 | 273 | ** Function name: clc_WP_sin |
igor_v | 0:8ad47e2b6f00 | 274 | ** |
igor_v | 21:bc8c1cec3da6 | 275 | ** Descriptions: Procedure of scan signal generating |
igor_v | 0:8ad47e2b6f00 | 276 | ** |
igor_v | 21:bc8c1cec3da6 | 277 | ** parameters: None |
igor_v | 0:8ad47e2b6f00 | 278 | ** Returned value: Current code for scan signal DAC of PLC |
igor_v | 21:bc8c1cec3da6 | 279 | ** |
igor_v | 0:8ad47e2b6f00 | 280 | ******************************************************************************/ |
igor_v | 0:8ad47e2b6f00 | 281 | int clc_WP_sin(void) |
igor_v | 0:8ad47e2b6f00 | 282 | { |
igor_v | 21:bc8c1cec3da6 | 283 | static int index = 0; |
igor_v | 21:bc8c1cec3da6 | 284 | index++; |
igor_v | 0:8ad47e2b6f00 | 285 | |
igor_v | 21:bc8c1cec3da6 | 286 | if (index >= 40/*Device_blk.Str.PI_b3*/) |
igor_v | 21:bc8c1cec3da6 | 287 | index = 0; |
igor_v | 21:bc8c1cec3da6 | 288 | /* if (index > 20) |
igor_v | 21:bc8c1cec3da6 | 289 | LPC_GPIO0->FIOSET = (1<<26); |
igor_v | 21:bc8c1cec3da6 | 290 | else |
igor_v | 21:bc8c1cec3da6 | 291 | LPC_GPIO0->FIOCLR = (1<<26); */ |
igor_v | 21:bc8c1cec3da6 | 292 | DAC_Output(sin_func[index]); //output to DAC |
igor_v | 21:bc8c1cec3da6 | 293 | |
igor_v | 21:bc8c1cec3da6 | 294 | return (sin_func[index]); |
igor_v | 0:8ad47e2b6f00 | 295 | } // clc_WP_sin |
igor_v | 0:8ad47e2b6f00 | 296 | |
igor_v | 0:8ad47e2b6f00 | 297 | /****************************************************************************** |
igor_v | 0:8ad47e2b6f00 | 298 | ** Function name: WP_PhaseDetectorRate |
igor_v | 0:8ad47e2b6f00 | 299 | ** |
igor_v | 21:bc8c1cec3da6 | 300 | ** Descriptions: Integartion of output of the PD of the CPLC regulator |
igor_v | 21:bc8c1cec3da6 | 301 | for the technological output on the Rate command |
igor_v | 0:8ad47e2b6f00 | 302 | ** |
igor_v | 21:bc8c1cec3da6 | 303 | ** Parameters: Current PD magnitude, period of integration |
igor_v | 21:bc8c1cec3da6 | 304 | ** Returned value: Integrated magnitude of PD |
igor_v | 21:bc8c1cec3da6 | 305 | ** |
igor_v | 0:8ad47e2b6f00 | 306 | ******************************************************************************/ |
igor_v | 21:bc8c1cec3da6 | 307 | int WP_PhaseDetectorRate(int PhaseDetInput, int IntegrateTime) |
igor_v | 0:8ad47e2b6f00 | 308 | { |
igor_v | 0:8ad47e2b6f00 | 309 | |
igor_v | 21:bc8c1cec3da6 | 310 | static int SampleAndHoldOut = 0; |
igor_v | 21:bc8c1cec3da6 | 311 | static int WP_PhasDet_integr = 0;//, WP_PhasDetector = 0; |
igor_v | 21:bc8c1cec3da6 | 312 | |
igor_v | 21:bc8c1cec3da6 | 313 | if (IntegrateTime == DEVICE_SAMPLE_RATE_uks) { |
igor_v | 21:bc8c1cec3da6 | 314 | SampleAndHoldOut = (int)(WP_PhasDet_integr >> PLC_PHASE_DET_SHIFT); |
igor_v | 21:bc8c1cec3da6 | 315 | WP_PhasDet_integr = 0; |
igor_v | 21:bc8c1cec3da6 | 316 | } else { |
igor_v | 21:bc8c1cec3da6 | 317 | WP_PhasDet_integr += PhaseDetInput; |
igor_v | 21:bc8c1cec3da6 | 318 | } |
igor_v | 21:bc8c1cec3da6 | 319 | return (SampleAndHoldOut); |
igor_v | 0:8ad47e2b6f00 | 320 | } // WP_PhaseDetectorRate |