// USER CODE BEGIN (MAIN_General,1)


// USER CODE END


// USER CODE BEGIN (MAIN_General,2)

// MAIN_General_2_IAF_CODE_BEGIN

// MAIN_General_2_IAF_CODE_END

// USER CODE END


// USER CODE BEGIN (MAIN_General,3)

// MAIN_General_3_IAF_CODE_BEGIN

// MAIN_General_3_IAF_CODE_END

// USER CODE END


// USER CODE BEGIN (MAIN_General,4)

// USER CODE END

// USER CODE BEGIN (MAIN_General,5)


// USER CODE END


// USER CODE BEGIN (MAIN_General,6)

// MAIN_General_6_IAF_CODE_BEGIN

// MAIN_General_6_IAF_CODE_END

// USER CODE END


// USER CODE BEGIN (MAIN_General,7)
// MAIN_General_7_IAF_CODE_BEGIN
#if DAVECG_ControlAlgoKBS.SDCC
	bit  			gb_Off;
		bit 			gb_On;
		bit 			gb_time_out;
		bit  			gb_ctrap;
		bit 			gb_hs_error;
		bit				gb_overcurrent;
#if DAVECG_ControlAlgoKBS.CP_ENABLE
	 	bit 			bitNewCMD0;
#endif
data	at 0x0020	unsigned char Status_word;
data 	at 0x2E 	unsigned int 	g_direction;							  
data 	at 0x2C 	int 			g_current;
#if DAVECG_ControlAlgoKBS.HALL
idata 	at 0x90 	unsigned int  	g_speed_CC60;
#endif
#if DAVECG_ControlAlgoKBS.BEMF
 idata  at 0x0090	int 			motor_speed ;
 idata 	at 0x0080	unsigned int 	g_start_freq;
 idata  at 0x0082	int 			g_freq_increment;	
 idata  at 0x0084	int 			g_volt_increment;
 idata	at 0x0086	unsigned int 	g_start_duty_c;

 idata 	at 0x0088	unsigned int 	g_bemf_check_freq ;					   
 idata 	at 0x008A	unsigned int  	g_bemf_end_freq;
#endif
#endif
#if DAVECG_ControlAlgoKBS.KEIL
bdata 	unsigned char 	Status_word;
		sbit			gb_overcurrent = Status_word^5;
		sbit 			gb_hs_error      = Status_word^4;
		sbit 			gb_ctrap      = Status_word^3;
		sbit 			gb_time_out = Status_word^2;
		sbit 			gb_On        = Status_word^1;
		sbit 			gb_Off       = Status_word^0;
#if DAVECG_ControlAlgoKBS.CP_ENABLE
	 	bit 			bitNewCMD0;
#endif
data  	int 			g_current 			_at_(0x002C);
data  	unsigned int 	g_direction 		_at_(0x2E);
#if DAVECG_ControlAlgoKBS.HALL
 idata 	unsigned int  	g_speed_CC60 		_at_(0x0090);
#endif
#if DAVECG_ControlAlgoKBS.BEMF
 idata	int 			motor_speed 		_at_(0x90);
 idata 	unsigned int 	g_start_freq 		_at_(0x0080);
 idata  int 			g_freq_increment 	_at_(0x0082);	
 idata  int 			g_volt_increment 	_at_(0x0084);
 idata	unsigned int 	g_start_duty_c 		_at_(0x0086);
 idata 	unsigned int 	g_bemf_check_freq 	_at_(0x0088);					   
 idata 	unsigned int  	g_bemf_end_freq 	_at_(0x008A);	
#endif
#endif

#if DAVECG_ControlAlgoKBS.VOLTAGE_CTRL 
#if DAVECG_ControlAlgoKBS.KEIL
 data   unsigned int 	g_nv_start_ref 	  _at_(0x0028);	
 idata  unsigned int  	g_nv_end_ref  	  _at_(0x008C); 	 		
 idata	int   		    Rampup_Counter 	  _at_(0x008E);
#endif
#if DAVECG_ControlAlgoKBS.SDCC
data   at 0x0028	unsigned int    g_nv_start_ref;	
idata  at 0x008C	unsigned int 	g_nv_end_ref; 	 		
idata  at 0x008E	int   			Rampup_Counter;
#endif
#endif

#if DAVECG_ControlAlgoKBS.SPEED_CTRL

#if DAVECG_ControlAlgoKBS.SDCC
 data 	at 0x0028	unsigned int 	g_speed_start_ref;	
 idata 	at 0x008C	unsigned int 	g_speed_end_ref; 		

 idata	at 0x008E	int   		    Rampup_Counter ;

 idata 	at 0x0092	unsigned int 	speed_kp;
 idata 	at 0x0094	unsigned int 	speed_ki;
#endif
#if DAVECG_ControlAlgoKBS.KEIL
 data   unsigned int 	g_speed_start_ref 	_at_(0x0028);	
 idata  unsigned int  	g_speed_end_ref  	_at_(0x008C); 	 		

 idata	int   		    Rampup_Counter 		_at_(0x008E);

 idata 	unsigned int  	speed_kp  			_at_(0x0092);
 idata	unsigned int  	speed_ki  			_at_(0x0094);

#endif
#endif

#if DAVECG_ControlAlgoKBS.CURRENT_CTRL

#if DAVECG_ControlAlgoKBS.SDCC
 data 	at 0x0028	unsigned int	g_current_ref;
 idata 	at 0x0092	unsigned int 	current_kp;
 idata 	at 0x0094 	unsigned int 	current_ki;
#endif
#if DAVECG_ControlAlgoKBS.KEIL
 data 	unsigned int  	g_current_ref  		_at_(0x0028);
 idata 	unsigned int  	current_kp  		_at_(0x0092);
 idata	unsigned int  	current_ki  		_at_(0x0094);
#endif
#endif
#if DAVECG_ControlAlgoKBS.SPEED_CURRENT_CTRL

#if DAVECG_ControlAlgoKBS.SDCC
 data 	at 0x0028	unsigned int 	g_speed_start_ref;	
 idata 	at 0x008C	unsigned int 	g_speed_end_ref; 		

 idata	at 0x008E	int   		    Rampup_Counter ;

 idata 	at 0x0092	unsigned int 	speed_kp;
 idata 	at 0x0094	unsigned int 	speed_ki;

 data  	at 0x002A 	unsigned int 	current_kp;
 idata 	at 0x0096	unsigned int 	current_ki;	
#endif
#if DAVECG_ControlAlgoKBS.KEIL
 data   unsigned int 	g_speed_start_ref 	_at_(0x0028);	
 idata  unsigned int  	g_speed_end_ref  	_at_(0x008C); 	 		

 idata	int   		    Rampup_Counter 		_at_(0x008E);

 idata 	unsigned int  	speed_kp  			_at_(0x0092);
 idata	unsigned int  	speed_ki  			_at_(0x0094);

 data   unsigned int  	current_kp  		_at_(0x002A);
 idata 	unsigned int  	current_ki			_at_(0x0096);

#endif
#endif

int API_Ref=0;
 


// MAIN_General_7_IAF_CODE_END
// USER CODE END


// USER CODE BEGIN (MAIN_General,8)

// MAIN_General_8_IAF_CODE_BEGIN
 extern void MotorControl_vInit( void );
// MAIN_General_8_IAF_CODE_END
	
// USER CODE END


// USER CODE BEGIN (MAIN_General,9)


// USER CODE END


// USER CODE BEGIN (Init,1)


// USER CODE END


	// USER CODE BEGIN (Init,2)


	// USER CODE END


	// USER CODE BEGIN (Init,3)

	// Init_3_IAF_CODE_BEGIN

	// Init_3_IAF_CODE_END

	// USER CODE END


// USER CODE BEGIN (UnlockProtecReg,1)

// USER CODE END

// USER CODE BEGIN (MAIN_Init,3)

// MAIN_Init_3_IAF_CODE_BEGIN

	MotorControl_vInit();
	API_Ref=0;

// MAIN_Init_3_IAF_CODE_END

// USER CODE END


// USER CODE BEGIN (Main,1)


// USER CODE END


  // USER CODE BEGIN (MAIN_Main,2)



	// USER CODE END

  // USER CODE BEGIN (MAIN_Main,3)
	// Main_3_IAF_CODE_BEGIN

		// Main_3_IAF_CODE_END		
  // USER CODE END

  // USER CODE BEGIN (MAIN_Main,4)

	// Main_4_IAF_CODE_BEGIN

		
		// Main_4_IAF_CODE_END		


	
	// USER CODE END

// USER CODE BEGIN (MAIN_General,10)


// USER CODE END
