Part Number:TMS320F28335Other Parts Discussed in Thread:CONTROLSUITE
for(;;){while(AdcRegs.ADCST.bit.INT_SEQ1==0);AdcRegs.ADCST.bit.INT_SEQ1_CLR=1;U1=(AdcRegs.ADCRESULT0>>4)*3.3/4096*24.3;U2=(AdcRegs.ADCRESULT1>>4)*3.3/4096*24;//OLED_ShowString(15,0,"Vo:",16);// OLED_ShowString(15,3,"Vi:",16);// OLED_ShowNum(40,0,U2,2,2,20);// OLED_ShowNum(40,3,U1,2,2,20);//(行,列,显示物,小数点前几位,小数点后几位,字体大小)//PID_control(15,20);Un1=PID_control(15,20);///if(Un1>270)Un1=270;// if(Un1<5)Un1=5;EPwm1Regs.CMPA.half.CMPA=270;OLED_ShowNum(40,3,Un1,3,2,20);//(行,列,显示物,小数点前几位,小数点后几位,字体大小 )}主函数
void PID(void) {pid.KP=1;pid.KI=0;pid.KD =0.5; } float PID_control(float adc,float set) { float Inck=0.0; pid.error = set - adc; Inck = pid.KP*(pid.error - pid.error_1)+pid.KI*pid.error+pid.KD*(pid.error-2*pid.error_1+pid.error_2); pid.error_2 = pid.error_1; pid.error_1 = pid.error; pid.dacout = Inck; return pid.dacout; }PID
上面是函数,功能是adc处理采样信号,经过处理送给epwm的cmpa处来改变epwm的占空比,但pid控制的epwm跳变非常大,我想让它稳定下来,求教。
#include"bsp_pwm.h" #include "DSP28x_Project.h" void epwm1_gpio() {EALLOW;GpioCtrlRegs.GPAMUX1.bit.GPIO0=1;//复用IO模式GpioCtrlRegs.GPAMUX1.bit.GPIO1=1;EDIS; } void epwm2_gpio() {EALLOW;GpioCtrlRegs.GPAMUX1.bit.GPIO2=1;//复用IO模式GpioCtrlRegs.GPAMUX1.bit.GPIO3=1;EDIS; } void epwm1_init() {EPwm1Regs.TBPRD=375;//f=TBPRDx1/时钟频率EPwm1Regs.TBPHS.half.TBPHS=0;EPwm1Regs.TBCTR=0x000;EPwm1Regs.CMPA.half.CMPA=375;EPwm1Regs.CMPB=375;EPwm1Regs.TBCTL.bit.CLKDIV=1;EPwm1Regs.TBCTL.bit.HSPCLKDIV=1;EPwm1Regs.TBCTL.bit.PHSEN=0;EPwm1Regs.TBCTL.bit.CTRMODE=TB_COUNT_UPDOWN;EPwm1Regs.TBCTL.bit.PRDLD=0;// EPwm1Regs.TBCTL.bit.SYNCOSEL=1;EPwm1Regs.CMPCTL.bit.SHDWAMODE= 0;EPwm1Regs.CMPCTL.bit.SHDWBMODE= 0;EPwm1Regs.CMPCTL.bit.LOADAMODE= 0;EPwm1Regs.CMPCTL.bit.LOADBMODE= 0;EPwm1Regs.AQCTLA.bit.CAU=1;EPwm1Regs.AQCTLA.bit.CAD=2;EPwm1Regs.AQCTLB.bit.CAU=1;EPwm1Regs.AQCTLB.bit.CAD=2;EPwm1Regs.ETSEL.bit.INTEN= 1;EPwm1Regs.ETSEL.bit.INTSEL= 2;EPwm1Regs.ETSEL.bit.SOCAEN=1;EPwm1Regs.ETSEL.bit.SOCASEL=4;EPwm1Regs.ETPS.bit.INTPRD= 1;EPwm1Regs.DBCTL.bit.IN_MODE=0;EPwm1Regs.DBCTL.bit.OUT_MODE=3;EPwm1Regs.DBCTL.bit.POLSEL=2;EPwm1Regs.DBRED = 100;EPwm1Regs.DBFED = 100; } //epwm
Green Deng:
你好,请问你是基于哪一个TI提供的例程设计的程序吗?
PID的话其实本身就是需要不断调校参数才能达到一个较为理想的控制结果的,你可以参考PID库文件中的说明文档进行参数调整:
C:\ti\controlSUITE\libs\app_libs\motor_control\math_blocks\v4.3\~Docs
,
haotian zhao:
不是的,是自己编写的
,
Green Deng:
抱歉这边的话一般只能判断官方例程的问题,可以参考上述的文档进行PID调优