123
Fork of LG by
host/Source/App/HFO_Reg.c@22:12e6183f04d4, 2016-02-03 (annotated)
- Committer:
- Kovalev_D
- Date:
- Wed Feb 03 10:44:42 2016 +0300
- Revision:
- 22:12e6183f04d4
[thyz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kovalev_D |
22:12e6183f04d4 | 1 | #include "mathDSP.h" |
Kovalev_D |
22:12e6183f04d4 | 2 | #include "InputOutput.h" |
Kovalev_D |
22:12e6183f04d4 | 3 | #include "CntrlGLD.h" |
Kovalev_D |
22:12e6183f04d4 | 4 | |
Kovalev_D |
22:12e6183f04d4 | 5 | #define HFO_NEG_MIN 8738 // -4.5 V |
Kovalev_D |
22:12e6183f04d4 | 6 | #define HFO_NEG_MAX 25122 // -10.5 V |
Kovalev_D |
22:12e6183f04d4 | 7 | #define HFO_POZ_MIN -32221 // +10.5 V |
Kovalev_D |
22:12e6183f04d4 | 8 | #define HFO_POZ_MAX -15837 // +4.5 V |
Kovalev_D |
22:12e6183f04d4 | 9 | |
Kovalev_D |
22:12e6183f04d4 | 10 | /****************************************************************************** |
Kovalev_D |
22:12e6183f04d4 | 11 | ** Function name: clc_HFO |
Kovalev_D |
22:12e6183f04d4 | 12 | ** |
Kovalev_D |
22:12e6183f04d4 | 13 | ** Descriptions: Procedure of the HFO regulator |
Kovalev_D |
22:12e6183f04d4 | 14 | ** |
Kovalev_D |
22:12e6183f04d4 | 15 | ** parameters: None |
Kovalev_D |
22:12e6183f04d4 | 16 | ** Returned value: None |
Kovalev_D |
22:12e6183f04d4 | 17 | ** |
Kovalev_D |
22:12e6183f04d4 | 18 | ******************************************************************************/ |
Kovalev_D |
22:12e6183f04d4 | 19 | void clc_HFO() // --- HFO regulator --- |
Kovalev_D |
22:12e6183f04d4 | 20 | { |
Kovalev_D |
22:12e6183f04d4 | 21 | |
Kovalev_D |
22:12e6183f04d4 | 22 | static int hf_reg = 0; //r. çíà÷åíèå èíòåãðàòîðà â êîíòóðå ÃÂ× |
Kovalev_D |
22:12e6183f04d4 | 23 | |
Kovalev_D |
22:12e6183f04d4 | 24 | |
Kovalev_D |
22:12e6183f04d4 | 25 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D |
22:12e6183f04d4 | 26 | //r. ôèëüòðàöèÿ âûõîäà àìïë. äåòåêòîðà ïåðåä ïåðåäà÷åé â êîíòóð ÃÂ× |
Kovalev_D |
22:12e6183f04d4 | 27 | /*int HFO_MovAverFilt (int Input) |
Kovalev_D |
22:12e6183f04d4 | 28 | { |
Kovalev_D |
22:12e6183f04d4 | 29 | static __int64 smooth_HF = 0; |
Kovalev_D |
22:12e6183f04d4 | 30 | |
Kovalev_D |
22:12e6183f04d4 | 31 | static int buffer_HF[BUF_SIZE]; |
Kovalev_D |
22:12e6183f04d4 | 32 | |
Kovalev_D |
22:12e6183f04d4 | 33 | static unsigned i_HF = 0; |
Kovalev_D |
22:12e6183f04d4 | 34 | |
Kovalev_D |
22:12e6183f04d4 | 35 | smooth_HF -= buffer_HF[i_HF]; |
Kovalev_D |
22:12e6183f04d4 | 36 | buffer_HF[i_HF] = Input; |
Kovalev_D |
22:12e6183f04d4 | 37 | smooth_HF += Input; |
Kovalev_D |
22:12e6183f04d4 | 38 | |
Kovalev_D |
22:12e6183f04d4 | 39 | i_HF++; |
Kovalev_D |
22:12e6183f04d4 | 40 | i_HF &= (BUF_SIZE-1); |
Kovalev_D |
22:12e6183f04d4 | 41 | |
Kovalev_D |
22:12e6183f04d4 | 42 | return (smooth_HF>>22); //shift on additional 6 bits for smoothing 2^6 = 64 |
Kovalev_D |
22:12e6183f04d4 | 43 | }*/ |
Kovalev_D |
22:12e6183f04d4 | 44 | |
Kovalev_D |
22:12e6183f04d4 | 45 | |
Kovalev_D |
22:12e6183f04d4 | 46 | // HFO_SHIFT - ÷èñëî ðàçðÿäîâ äðîáíîé ÷àñòè â 32-õáèòîâîé ïåðåìåííîé hf_reg32 |
Kovalev_D |
22:12e6183f04d4 | 47 | Input.StrIn.HF_out = HFO_MovAverFilt(Input.StrIn.HF_out<<HFO_SHIFT); |
Kovalev_D |
22:12e6183f04d4 | 48 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D |
22:12e6183f04d4 | 49 | |
Kovalev_D |
22:12e6183f04d4 | 50 | Output.Str.HF_dif = L_sub(Device_blk.Str.HF_ref, Input.StrIn.HF_out); // HF_dif = HF_out - Device_blk.Str.HF_ref; |
Kovalev_D |
22:12e6183f04d4 | 51 | |
Kovalev_D |
22:12e6183f04d4 | 52 | if ( loop_is_closed(HF_REG_ON) ) //e. the regulator loop is closed //r. êîíòóð çàìêíóò |
Kovalev_D |
22:12e6183f04d4 | 53 | {// êîýôôèöèåíò ïåðåäà÷è |
Kovalev_D |
22:12e6183f04d4 | 54 | hf_reg = L_mac( hf_reg, Output.Str.HF_dif, Device_blk.Str.HF_scl ); // hf_reg32 += HFO_error * Device_blk.Str.HF_scl; |
Kovalev_D |
22:12e6183f04d4 | 55 | 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; |
Kovalev_D |
22:12e6183f04d4 | 56 | Output.Str.HF_reg = (hf_reg >> HFO_SHIFT); // Output.Str.HF_reg - HFO output voltage |
Kovalev_D |
22:12e6183f04d4 | 57 | } |
Kovalev_D |
22:12e6183f04d4 | 58 | else |
Kovalev_D |
22:12e6183f04d4 | 59 | { |
Kovalev_D |
22:12e6183f04d4 | 60 | hf_reg = Output.Str.HF_reg << HFO_SHIFT; //r. èíòåãðàòîðó ïðèñâàèâàåì ïðåäûäóùåå çíà÷åíèå HF_reg |
Kovalev_D |
22:12e6183f04d4 | 61 | } |
Kovalev_D |
22:12e6183f04d4 | 62 | |
Kovalev_D |
22:12e6183f04d4 | 63 | // cyclic built-in test |
Kovalev_D |
22:12e6183f04d4 | 64 | 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)))) |
Kovalev_D |
22:12e6183f04d4 | 65 | { |
Kovalev_D |
22:12e6183f04d4 | 66 | Valid_Data |= HFO_VOLT_ERROR; |
Kovalev_D |
22:12e6183f04d4 | 67 | } |
Kovalev_D |
22:12e6183f04d4 | 68 | } // clc_HFO |