// USER CODE BEGIN (MAIN_Header,1)

// USER CODE END


// USER CODE BEGIN (MAIN_Header,2)

// USER CODE END

// USER CODE BEGIN (MAIN_Header,3)

// USER CODE END

// USER CODE BEGIN (MAIN_Header,4)

// USER CODE END


// USER CODE BEGIN (MAIN_Header,5)

// USER CODE END

// USER CODE BEGIN (MAIN_Header,6)

// USER CODE END


// USER CODE BEGIN (MAIN_Header,7)

// USER CODE END


// USER CODE BEGIN (MAIN_Header,8)

// USER CODE END


// USER CODE BEGIN (MAIN_Header,9)

// USER CODE END


// USER CODE BEGIN (MAIN_Header,10)
 // MAIN_HEADER_10_IAF_CODE_BEGIN
	#if DAVECG_ControlAlgoKBS.KEIL

	#define  C_BDATA 	int bdata
	#define  C_SBIT 	sbit
	#define  C_SDATA    sdata
	#define  INLINE  	__inline
   	#define  C_ATBIT(var, bit_pos)  =(var)^(bit_pos)

	#endif  //End of Keil

	#if DAVECG_ControlAlgoKBS.Tasking

	#define  C_BDATA 	_bita
	#define  C_SBIT 	_bit
	#define  C_SDATA    _system
	#define  INLINE  	_inline
   	#define  C_ATBIT(var, bit_pos)  _atbit(var,bit_pos)
	
	#endif   //End of TASKING


  #if DAVECG_ControlAlgoKBS.BEMF
  #if DAVECG_ControlAlgoKBS.VOLTAGE_CTRL
	typedef struct 
	{
		sword 	Volt_Start_Ref;
		sword 	Volt_End_Ref;
		uword 	Rampup_Counter;
		uword	Motor_Direction;
		//Bemf parameters
		uword 	Bemf_Check_Freq;
		uword 	Bemf_End_Freq;
		uword 	Freq_Increment;
		uword 	Volt_Increment;
		uword 	Start_Duty_Cyc;
		uword 	Start_Freq;
		//Graph Parameter
		uword 	Volt_Ref;
		sword 	Motor_Speed;
		uword 	Motor_Current;
		uword 	Duty_Cyc;

	}  cVCB;

 #endif //End of VCB

  #if DAVECG_ControlAlgoKBS.SPEED_CTRL
	typedef struct
	{
	  	uword	  	Kp;
	  	uword	  	Ki;
	  	uword	  	Ymin;
	  	uword	  	Ymax;
	  	slong   	Ibuf;
		uword		PI_Output;
	}PI_array;

	typedef struct 
	{
		sword 		Speed_Start_Ref;
		sword 		Speed_End_Ref;
		uword 		Rampup_Counter;
		uword		Motor_Direction;
		//Bemf parameters
		uword 		Bemf_Check_Freq;
		uword 		Bemf_End_Freq;
		uword 		Freq_Increment;
		uword 		Volt_Increment;
		uword 		Start_Duty_Cyc;
		uword 		Start_Freq;
   		//Graph Parameter
		uword 		Speed_Ref;
		sword 		Motor_Speed;
		uword 		Motor_Current;
		uword 		Duty_Cyc;
		
		PI_array	Speed;

	}  cSCB;

  #endif //End of SCB
  
  #if DAVECG_ControlAlgoKBS.CURRENT_CTRL

    typedef struct
	{
	  	uword	  	Kp;
	  	uword	  	Ki;
	  	uword	  	Ymin;
	  	uword	  	Ymax;
	  	slong   	Ibuf;
		uword		PI_Output;
	}PI_array;

	typedef struct 
	{
		sword 		Current_Ref;
		sword 		End_Ref;
		uword 		Rampup_Counter;
		uword		Motor_Direction;
		//Bemf parameters
		uword 		Bemf_Check_Freq;
		uword 		Bemf_End_Freq;
		uword 		Freq_Increment;
		uword 		Volt_Increment;
		uword 		Start_Duty_Cyc;
		uword 		Start_Freq;
   		//Graph Parameter
		sword 		Motor_Speed;
		uword 		Motor_Current;
		uword 		Duty_Cyc;
		
		PI_array	Current;

	}  cCCB;

	#endif //End of CCB
 
 #if DAVECG_ControlAlgoKBS.SPEED_CURRENT_CTRL
	typedef struct
	{
	  	uword	  	Kp;
	  	uword	  	Ki;
	  	uword	  	Ymin;
	  	uword	  	Ymax;
	  	slong   	Ibuf;
		uword		PI_Output;
	}PI_array;

	typedef struct 
	{
		sword 		Speed_Start_Ref;
		sword 		Speed_End_Ref;
		uword 		Rampup_Counter;
		uword		Motor_Direction;
		//Bemf parameters
		uword 		Bemf_Check_Freq;
		uword 		Bemf_End_Freq;
		uword 		Freq_Increment;
		uword 		Volt_Increment;
		uword 		Start_Duty_Cyc;
		uword 		Start_Freq;
   		//Graph Parameter
		uword 		Speed_Ref;
		sword 		Motor_Speed;
		uword 		Motor_Current;
		uword 		Duty_Cyc;
		
		PI_array	Speed;
		PI_array	Current;

	}  cSCCB;

 #endif //End of SCCB

#endif  //End of BEMF

#if DAVECG_ControlAlgoKBS.HALL
  #if DAVECG_ControlAlgoKBS.VOLTAGE_CTRL
	typedef struct 
	{
		sword 	Volt_Start_Ref;
		sword 	Volt_End_Ref;
		uword 	Rampup_Counter;
		uword	Motor_Direction;

		//Speed Measurement parameters
		ubyte 			Speed_Counter;
		ubyte 			Circ_Index;
		uword			Time_Measure;
		ulong 			Speed_Acumm;

		sword			I_Counter;
		sword 			Ramp_Scheduler;

		//Graph Parameter
		uword 	Volt_Ref;
		sword 	Motor_Speed;
		uword 	Motor_Current;
		uword 	Duty_Cyc;

	}  cVCH;

 #endif //End of VCH

  #if DAVECG_ControlAlgoKBS.SPEED_CTRL
	typedef struct
	{
	  	uword	  	Kp;
	  	uword	  	Ki;
	  	uword	  	Ymin;
	  	uword	  	Ymax;
	  	slong   	Ibuf;
		uword		PI_Output;
	}PI_array;

	typedef struct 
	{
		uword 	Speed_Start_Ref;
		uword 	Speed_End_Ref;
		uword 	Rampup_Counter;
		uword	Motor_Direction;

		//Speed Measurement parameters
		ubyte 	Speed_Counter;
		ubyte 	Circ_Index;
		uword	Time_Measure;
		ulong 	Speed_Acumm;

		sword	I_Counter;
		sword 	Ramp_Scheduler;

		//Graph Parameter
		uword 	Speed_Ref;
		uword 	Motor_Speed;
		uword 	Motor_Current;
		uword 	Duty_Cyc;
		
		PI_array	Speed;


	}  cSCH;
  #endif //End of SCH
  
  #if DAVECG_ControlAlgoKBS.CURRENT_CTRL
	typedef struct
	{
	  	uword	  	Kp;
	  	uword	  	Ki;
	  	uword	  	Ymin;
	  	uword	  	Ymax;
	  	slong   	Ibuf;
		uword		PI_Output;
	}PI_array;

	typedef struct 
	{
		uword 	Current_Ref;
		uword 	End_Ref;
		uword 	Rampup_Counter;
		uword	Motor_Direction;

		//Speed Measurement parameters
		ubyte 	Speed_Counter;
		ubyte 	Circ_Index;
		uword	Time_Measure;
		ulong 	Speed_Acumm;

		sword	I_Counter;
		sword 	Ramp_Scheduler;

		//Graph Parameter

		uword 	Motor_Speed;
		uword 	Motor_Current;
		uword 	Duty_Cyc;
		
		PI_array	Current;


	}  cCCH;

  
  #endif //End of CCH
 
 #if DAVECG_ControlAlgoKBS.SPEED_CURRENT_CTRL
	typedef struct
	{
	  	uword	  	Kp;
	  	uword	  	Ki;
	  	uword	  	Ymin;
	  	uword	  	Ymax;
	  	slong   	Ibuf;
		uword		PI_Output;
	}PI_array;

	typedef struct 
	{
		uword 	Speed_Start_Ref;
		uword 	Speed_End_Ref;
		uword 	Rampup_Counter;
		uword	Motor_Direction;

		//Speed Measurement parameters
		ubyte 	Speed_Counter;
		ubyte 	Circ_Index;
		uword	Time_Measure;
		ulong 	Speed_Acumm;

		sword	I_Counter;
		sword 	Ramp_Scheduler;

		//Graph Parameter
		uword 	Speed_Ref;
		uword 	Motor_Speed;
		uword 	Motor_Current;
		uword 	Duty_Cyc;
		
		PI_array	Speed;
		PI_array	Current;

	}  cSCCH;

 #endif //End of SCCH

#endif  //End of HALL
// MAIN_HEADER_10_IAF_CODE_END
// USER CODE END


