![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
HFO_Reg.c@150:29c9f7671bac, 2016-05-04 (annotated)
- Committer:
- Kovalev_D
- Date:
- Wed May 04 14:01:57 2016 +0000
- Revision:
- 150:29c9f7671bac
- Parent:
- 112:4a96133a1311
PLC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 1:f2adcae3d304 | 1 | #include "Global.h" |
igor_v | 0:8ad47e2b6f00 | 2 | |
igor_v | 0:8ad47e2b6f00 | 3 | #define HFO_NEG_MIN 8738 // -4.5 V |
igor_v | 0:8ad47e2b6f00 | 4 | #define HFO_NEG_MAX 25122 // -10.5 V |
igor_v | 0:8ad47e2b6f00 | 5 | #define HFO_POZ_MIN -32221 // +10.5 V |
igor_v | 0:8ad47e2b6f00 | 6 | #define HFO_POZ_MAX -15837 // +4.5 V |
igor_v | 0:8ad47e2b6f00 | 7 | |
igor_v | 0:8ad47e2b6f00 | 8 | /****************************************************************************** |
igor_v | 0:8ad47e2b6f00 | 9 | ** Function name: clc_HFO |
igor_v | 0:8ad47e2b6f00 | 10 | ** |
igor_v | 21:bc8c1cec3da6 | 11 | ** Descriptions: Procedure of the HFO regulator |
igor_v | 0:8ad47e2b6f00 | 12 | ** |
igor_v | 21:bc8c1cec3da6 | 13 | ** parameters: None |
igor_v | 21:bc8c1cec3da6 | 14 | ** Returned value: None |
igor_v | 21:bc8c1cec3da6 | 15 | ** |
igor_v | 0:8ad47e2b6f00 | 16 | ******************************************************************************/ |
Kovalev_D | 112:4a96133a1311 | 17 | /*void clc_HFO() // --- HFO regulator --- |
igor_v | 0:8ad47e2b6f00 | 18 | { |
igor_v | 0:8ad47e2b6f00 | 19 | |
igor_v | 21:bc8c1cec3da6 | 20 | static int hf_reg = 0; //r. значение интегратора в контуре ГВЧ |
igor_v | 0:8ad47e2b6f00 | 21 | |
igor_v | 0:8ad47e2b6f00 | 22 | |
igor_v | 21:bc8c1cec3da6 | 23 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 24 | //r. фильтрация выхода ампл. детектора перед передачей в контур ГВЧ |
Kovalev_D | 150:29c9f7671bac | 25 | int HFO_MovAverFilt (int Input) |
igor_v | 21:bc8c1cec3da6 | 26 | { |
igor_v | 21:bc8c1cec3da6 | 27 | static __int64 smooth_HF = 0; |
igor_v | 21:bc8c1cec3da6 | 28 | |
igor_v | 21:bc8c1cec3da6 | 29 | static int buffer_HF[BUF_SIZE]; |
igor_v | 21:bc8c1cec3da6 | 30 | |
igor_v | 21:bc8c1cec3da6 | 31 | static unsigned i_HF = 0; |
igor_v | 21:bc8c1cec3da6 | 32 | |
igor_v | 21:bc8c1cec3da6 | 33 | smooth_HF -= buffer_HF[i_HF]; |
igor_v | 21:bc8c1cec3da6 | 34 | buffer_HF[i_HF] = Input; |
igor_v | 21:bc8c1cec3da6 | 35 | smooth_HF += Input; |
igor_v | 21:bc8c1cec3da6 | 36 | |
igor_v | 21:bc8c1cec3da6 | 37 | i_HF++; |
igor_v | 21:bc8c1cec3da6 | 38 | i_HF &= (BUF_SIZE-1); |
igor_v | 21:bc8c1cec3da6 | 39 | |
igor_v | 21:bc8c1cec3da6 | 40 | return (smooth_HF>>22); //shift on additional 6 bits for smoothing 2^6 = 64 |
Kovalev_D | 150:29c9f7671bac | 41 | } |
igor_v | 21:bc8c1cec3da6 | 42 | |
igor_v | 21:bc8c1cec3da6 | 43 | |
Kovalev_D | 150:29c9f7671bac | 44 | HFO_SHIFT - число разрядов дробной части в 32-хбитовой переменной hf_reg32 |
Kovalev_D | 150:29c9f7671bac | 45 | Input.StrIn.HF_out = HFO_MovAverFilt(Input.StrIn.HF_out<<HFO_SHIFT); |
igor_v | 0:8ad47e2b6f00 | 46 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 47 | |
igor_v | 21:bc8c1cec3da6 | 48 | Output.Str.HF_dif = L_sub(Device_blk.Str.HF_ref, Input.StrIn.HF_out); // HF_dif = HF_out - Device_blk.Str.HF_ref; |
igor_v | 0:8ad47e2b6f00 | 49 | |
igor_v | 21:bc8c1cec3da6 | 50 | if ( loop_is_closed(HF_REG_ON) ) { //e. the regulator loop is closed //r. контур замкнут |
igor_v | 21:bc8c1cec3da6 | 51 | // коэффициент передачи |
igor_v | 21:bc8c1cec3da6 | 52 | hf_reg = L_mac( hf_reg, Output.Str.HF_dif, Device_blk.Str.HF_scl ); // hf_reg32 += HFO_error * Device_blk.Str.HF_scl; |
igor_v | 21:bc8c1cec3da6 | 53 | Saturation(hf_reg, Device_blk.Str.HF_max << HFO_SHIFT, Device_blk.Str.HF_min << HFO_SHIFT); //e. checking range //r. проверка диапазона if (Uin > UpSat) Uin = UpSat; if (Uin < DownSat) Uin = DownSat; |
igor_v | 21:bc8c1cec3da6 | 54 | Output.Str.HF_reg = (hf_reg >> HFO_SHIFT); // Output.Str.HF_reg - HFO output voltage |
igor_v | 21:bc8c1cec3da6 | 55 | } else { |
igor_v | 21:bc8c1cec3da6 | 56 | hf_reg = Output.Str.HF_reg << HFO_SHIFT; //r. интегратору присваиваем предыдущее значение HF_reg |
igor_v | 21:bc8c1cec3da6 | 57 | } |
igor_v | 21:bc8c1cec3da6 | 58 | |
igor_v | 21:bc8c1cec3da6 | 59 | // cyclic built-in test |
igor_v | 21:bc8c1cec3da6 | 60 | if (!(((Output.Str.HF_reg < HFO_NEG_MAX)&&(Output.Str.HF_reg > HFO_NEG_MIN))||((Output.Str.HF_reg < HFO_POZ_MAX) && (Output.Str.HF_reg > HFO_POZ_MIN)))) { |
igor_v | 21:bc8c1cec3da6 | 61 | Valid_Data |= HFO_VOLT_ERROR; |
igor_v | 21:bc8c1cec3da6 | 62 | } |
Kovalev_D | 112:4a96133a1311 | 63 | } |
Kovalev_D | 112:4a96133a1311 | 64 | */ |
igor_v | 0:8ad47e2b6f00 | 65 |