⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imvcf07.c

📁 2407的交流电机控制程序
💻 C
字号:
/******************************************************************************
	File Name	: IMVCF07.c                   
	Project		: IMVC position control on ACPM750 AC Power Module Kit with 
					  TMS320LF2407 DSP controller
===============================================================================
	Target Sys  : MSK2407 DSP board + ACPM750 v3.2 power module
	Description : General initialization functions for controllers, sensors,
					  PWM, interrupts, logger and reference generator 
	Originator/s: Technosoft Ltd.
	Status      : OK
===============================================================================
	Copyright ?2000 Technosoft
==============================================================================*/
/******************************************************************************
	Include Files
/******************************************************************************/
#include "IMVC07.h"		/* application parameters (motor, controllers) 	   */
#include "IMVC07h.h"		/* external variables prototypes 			   */
#include "DSP2407.h"		/* 'LF2407 registers definitions 			   */
#include "ini2407.h"		/* application settings for 'LF2407 register 
                           programming                                        */
/******************************************************************************
	Local variables
*******************************************************************************/
unsigned int ref_time;
unsigned int ref_cycles;
/******************************************************************************
	Functions
*******************************************************************************/

/******************************************************************************
	Routine Name: init_reg_id
	-------------------------
	Purpose           : Initialization routine, called from the main function
	Calling Convention: extern void init_reg_id();
	Description       : Initializes the parameters of the d-axis current controller.
*******************************************************************************/
void init_reg_id()
{
	Kps_id = KPS_ID;
	Kis_id = KIS_ID;
	sf_P_id = SF_P_ID;
	sf_I_id = SF_I_ID;
	init_pi_reg_id();
}

/******************************************************************************
	Routine Name: init_reg_iq
	-------------------------
	Purpose           : Initialization routine, called from the main function
	Calling Convention: extern void init_reg_iq();
	Description       : Initializes the parameters of the q-axis current controller.
*******************************************************************************/
void init_reg_iq()
{
	Kps_iq = KPS_IQ;
	Kis_iq = KIS_IQ;
	sf_P_iq =SF_P_IQ;
	sf_I_iq =SF_I_IQ;
	init_pi_reg_iq();
}

/******************************************************************************
Routine Name: init_reg_pos
	--------------------------
	Purpose           : Initialization routine, called from the main function
	Calling Convention: extern void init_reg_pos();
	Description       : Initializes the parameters of the position controller.
*******************************************************************************/
void init_reg_pos()
{
	Kps_pos = KPS_POS;
	Kis_pos = KIS_POS;
	init_pi_reg_pos();	
}

/******************************************************************************
	Routine Name: init_reg_omg
	--------------------------
	Purpose           : Initialization routine, called from the main function
	Calling Convention: extern void init_reg_omg();
	Description       : Initializes the parameters of the speed controller.
*******************************************************************************/
void init_reg_omg()
{
	Kps_omg = KPS_OMG;
	Kis_omg = KIS_OMG;
	sf_P_omg =SF_P_OMG;
	sf_I_omg =SF_I_OMG;
	init_pi_reg_omg();	
}

/******************************************************************************
	Routine Name: init_encoder
	--------------------------
	Purpose           : Initialization routine, called from the main function
	Calling Convention: extern void init_encoder();
	Description       : Initializes the parameters of the encoder interface.
*******************************************************************************/
void init_encoder()
{
	MCRA |= MCRA_ENC_OR_MASK;
	GPTCONA &= GPTCON_ENC_AND_MASK;
	T2PR = T2PR_INI;
	T2CNT = T2COUNT_INI;
	T2CON = T2CON_INI;
}

/******************************************************************************
	Routine Name: init_pwm
	----------------------
	Purpose           : Initialization routine, called from the main function
	Calling Convention: extern void init_pwm();
	Description       : Initializes the parameters of the PWM module.
*******************************************************************************/
void init_pwm()
{
	GPTCONA |= GPTCON_PWM_OR_MASK;
	GPTCONA &= GPTCON_PWM_AND_MASK;
	MCRA |= MCRA_PWM_OR_MASK;
	T1PR = SYM_PWM_PER;
	pwm_period = SYM_PWM_PER;
	T1CNT = T1COUNT_INI;
	DBTCONA = DBTCON_INI;
	ACTRA = ACTIVE_HI_LOW;
	CMPR1 = COMPR1_INI; 
	CMPR2 = COMPR2_INI; 
	CMPR3 = COMPR3_INI; 
	T1CON = T1CON_INI;
}	

/******************************************************************************
	Routine Name: init_adc
	----------------------
	Purpose           : Initialization routine, called from the main function
	Calling Convention: extern void init_adc();
	Description       : Initializes the parameters of the ADC currents measurement.
*******************************************************************************/
void init_adc()
{	
	ADCTRL1 = ADCTRL1_RESET_ADC;
	ADCTRL1 = ADCTRL1_INI;
	MAX_CONV = MAX_CONV_INI;
	CHSELSEQ1 = CHSELSEQ1_INI;
	CHSELSEQ2 = CHSELSEQ2_INI;
	CHSELSEQ3 = CHSELSEQ3_INI;
	CHSELSEQ4 = CHSELSEQ4_INI;
	ADCTRL2 = ADCTRL2_INI;
}

/*****************************************************************************
	Routine Name: InitializeKernel
	-------------------------------
	Description       : Initialization routine, called from the main function
	Calling Convention: extern void InitializeKernel();
	Description       : Enable T1UFINT and unmask INT2;
******************************************************************************/
	void InitializeKernel()
{
        
       flag_active_fast = 0;
       flag_active_middle = 0;
	flag_active_slow = 0;
	counter_fast = fast_max_count;
       counter_middle = middle_max_count;
	counter_slow = slow_max_count;
	tufintlvec = (unsigned int)&ISR_Kernel;
	EVAIMRA = IMRA_INI;
	IMR = IMR_INI;
}

/******************************************************************************
	Routine Name: get_ia_ib_offsets
	-------------------------------
	Purpose           : Rutine, called from the main function
	Calling Convention: extern void get_ia_ib_offsets();
	Description       : Detects the offsets of the two current measurement channels.
*******************************************************************************/
void get_ia_ib_offsets()
{
	unsigned int i_a_offset, i_b_offset;
	int i, j, i_ww, i_www, i_wwww;

	for(i_www=0; i_www<65000U; i_www++) 
	{ u_a_ref = -32700;  u_b_ref = -32700;  u_c_ref = -32700; update_pwm(); }

	for(i_wwww=0; i_wwww<10; i_wwww++)
	{
	 	offset_ia = 0;
		offset_ib = 0;

		for(i = 0; i < 64; i++)
		{
			get_adc_pair1();
			i_a_offset = ad_res_0>>1;
			i_b_offset = ad_res_1>>1;
			i_a = i_a_offset>>5;
			i_b = i_b_offset>>5; 
			offset_ia += i_a; 
			offset_ib += i_b;
			for(j = 0; j < 32; j++)
			{
				i_ww = 0; i_ww++;	
			}
 		}

		offset_ia += 32;
		offset_ib += 32; 
		offset_ia = offset_ia>>6;
		offset_ia = offset_ia<<6;
		offset_ib = offset_ib>>6; 
		offset_ib = offset_ib<<6; 

		i_a = 0;
		i_b = 0;
	}
}

/******************************************************************************
	Routine Name: init_logger
	-------------------------
	Purpose           : Initialization routine, called from the main function
	Calling Convention: extern void init_logger();
	Description       : Initialize the data logger parameters.
*******************************************************************************/
void init_logger()
{
	log_count = 0;
	log_time = 0;
}

/******************************************************************************
	Routine Name: logger
	--------------------
	Purpose           : Routine, called from the main function
	Calling Convention: extern void logger();
	Description       : Performs data logging.
*******************************************************************************/
void logger()
{
	if(log_time >= log_indx && log_indx != 0xffff)
	{
		int **crt_p = log_p;
		while(*crt_p)
		{
			log_table[log_count++] = **crt_p++;
		}
		if(log_count >= log_size) log_indx = 0xffff;
	}
	log_time++;
}

/******************************************************************************
	Routine Name: init_reference
	----------------------------
	Purpose           : Initialization routine, called from the main function
	Calling Convention: extern void init_reference();
	Description       : Initializes the reference generator parameters.
*******************************************************************************/
void init_reference()
{
	ref_long = ref_HL[0];
	ref_time = 1;
	ref_indx = 1;
}

/******************************************************************************
	Routine Name: reference
	-----------------------
	Purpose           : Routine, called from the main function
	Calling Convention: extern int reference();
	Description       : Implements the reference generator.
	Returns           : the computed value of the reference at calling instance
*******************************************************************************/
int reference()
{
	int retval;
	long crtInc;
	unsigned int crtTime;
				
	if(ref_long > 0) retval = (int)((ref_long + 32768) >> 16);
	else retval = (int)((ref_long - 32768) >> 16) + 1;

	if(ref_cycles != 1)
	{
		crtTime = ref_time_val[ref_indx];
		crtInc = ref_HL[ref_indx];
		ref_long += crtInc;
		if(crtTime <= ref_time++)
		{ 
			crtTime = ref_time_val[++ref_indx];
			if(!crtTime)
			{
				if(ref_cycles > 1)
				{
					ref_cycles--;
				}
				if(ref_cycles != 1)
				{
					ref_indx = 1;
					ref_time = 1;
					ref_long = ref_HL[0];
				}
			}
		}
	}
	return retval;
}

/******************************************************************************
	Routine Name: init_field_pos
	--------------------------
	Purpose           : Initialization routine, called from the main function
	Calling Convention: extern void init_field_pos();
	Description       : Initializes the parameters for the rotor field position 
					 estimation
*******************************************************************************/
void init_field_pos()
{
	C_omg = C_OMG;
	Sh_omg = SH_OMG;
	C_slip = C_SLIP;
	Sh_slip =SH_SLIP;
	theta = 0;
	theta_low = 0;
	theta_inc = 0;
}

/******************************************************************************
	Routine Name: reset_Error_ACPM
	--------------------------
	Purpose           : Routine, called from the main function to reset the ACPM Error
	Calling Convention: extern void reset_Error_ACPM();
	Description       : reset the error for ACPM 
*******************************************************************************/
void reset_Error_ACPM()
{
int i,k;
	cfgiopc1();
	resetiopc1();
	for (i=1; i<=1000;i++)
	{
		k++;
	}
	setiopc1();
}
/******************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -