F28377 2P2Z(PID)设置与使用

2P2Z是比较常用的电源环路补偿算法,这里对它的使用做一个简单的总结,便于后续使用

首先需要申明结构体:

//CNTL2P2Z
volatile CNTL_2P2Z_F_C_Coeffs coeff1;//补偿参数结构体
volatile CNTL_2P2Z_F_C_Vars var1;//控制相关结构体,var1.out就是控制的输出量

然后在main函数里面将coeff1和var1这两个要用的结构体初始化,基本上都是赋零值

	CNTL_2P2Z_F_C_VAR_INIT(var1);
	CNTL_2P2Z_F_C_COEFF_INIT(coeff1);

往coeff1结构体内填充控制用的补偿参数:

		coeff1.Coeff_B2   = (float)(CNTL_3p3z_B2_1);                // B2
		coeff1.Coeff_B1   = (float)(CNTL_3p3z_B1_1);  				// B1
		coeff1.Coeff_B0   = (float)(CNTL_3p3z_B0_1);      			// B0
		coeff1.Coeff_A2   = (float)(CNTL_3p3z_A2_1);                // A2
		coeff1.Coeff_A1   = (float)(CNTL_3p3z_A1_1);                // A1
		coeff1.Max   = (float)CNTL_3p3z_Max_1;					  	//Clamp Hi
		coeff1.Min   = (float)CNTL_3p3z_Min_1; 					  	//Clamp Min
		coeff1.IMin  = (float)CNTL_3p3z_IMin_1; 					//Clamp IMin
连接var1结构体的输入量和参考量:
	var1.Ref = Vout_Ref_wInj;
	var1.Fdbk = Adc_Vout1;//0-1之间的值

之后便可以在控制ISR函数里使用2P2Z进行控制了

		var1.Ref = Vout1SetSlewed;
		Adc_Vout1 = ADCDRV_1ch_F_C(Vout1R);				//Read Vout and convert to float
		var1.Fdbk = Adc_Vout1;
		if (Start_Flag == 0 && No_2p2z == 0)
		{
			CNTL_2P2Z_F_C(coeff1,var1);
			Duty1A = var1.Out;
		}

	PWMDRV_1ch_F_C(BUCK_PWM_REG, BUCK_PWM_PERIOD, Duty1A);

在部分程序里还有如下代码,但是在程序里的其他地方调用到:

struct CNTL_2P2Z_CoefStruct {
	long b2;
	long b1;
	long b0;
	long a2;
	long a1;
	long max;
	long i_min;
	long min;
	};

#pragma DATA_SECTION(CNTL_2P2Z_CoefStruct1, "CNTL_2P2Z_Coef");//程序里没用到
struct CNTL_2P2Z_CoefStruct CNTL_2P2Z_CoefStruct1;//程序里没用到





你可能感兴趣的:(TI,DSP)