fork

Dependencies:   mbed

Fork of LG by igor Apu

HFO_Reg.c

Committer:
igor_v
Date:
2016-01-30
Revision:
1:f2adcae3d304
Parent:
0:8ad47e2b6f00
Child:
21:bc8c1cec3da6

File content as of revision 1:f2adcae3d304:

#include "Global.h"

#define		HFO_NEG_MIN			8738	// -4.5 V
#define		HFO_NEG_MAX			25122	// -10.5 V
#define		HFO_POZ_MIN			-32221	// +10.5 V
#define		HFO_POZ_MAX			-15837 	// +4.5 V

/******************************************************************************
** Function name:		clc_HFO
**
** Descriptions: Procedure of the HFO regulator 		
**
** parameters:	None		
** Returned value:	None	
** 
******************************************************************************/
void clc_HFO() // --- HFO regulator ---
{

	static int  hf_reg = 0; //r. �������� ����������� � ������� ���

	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//r. ���������� ������ ����. ��������� ����� ��������� � ������ ���
	/*int HFO_MovAverFilt (int Input)
{   
  static __int64 smooth_HF = 0;
  
	static  int buffer_HF[BUF_SIZE];
   
	static unsigned i_HF = 0;
  
	smooth_HF        -=  buffer_HF[i_HF];
  buffer_HF[i_HF]   =  Input;
	smooth_HF        +=  Input;

	 i_HF++;
   i_HF &= (BUF_SIZE-1);

   return (smooth_HF>>22);	//shift on additional 6 bits for smoothing 2^6 = 64 
}*/


//                                                       HFO_SHIFT - ����� �������� ������� ����� � 32-�������� ���������� hf_reg32
Input.StrIn.HF_out = HFO_MovAverFilt(Input.StrIn.HF_out<<HFO_SHIFT);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Output.Str.HF_dif = L_sub(Device_blk.Str.HF_ref, Input.StrIn.HF_out); // HF_dif	= HF_out - Device_blk.Str.HF_ref;
 
	if ( loop_is_closed(HF_REG_ON) )	//e. the regulator loop is closed //r. ������ �������
	{//                                           ����������� ��������
		hf_reg = L_mac( hf_reg, Output.Str.HF_dif, Device_blk.Str.HF_scl ); // hf_reg32 += HFO_error * Device_blk.Str.HF_scl;
		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;
		Output.Str.HF_reg = (hf_reg >> HFO_SHIFT); 	// Output.Str.HF_reg - HFO output voltage
	}
	else
	{
		hf_reg = Output.Str.HF_reg << HFO_SHIFT;	 //r. ����������� ����������� ���������� �������� HF_reg
	}

	// cyclic built-in test
	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))))
	{
		Valid_Data |= HFO_VOLT_ERROR;
	}
} // clc_HFO