- 积分
- 45
- 回帖
- 0
- 西莫币
-
- 贡献
-
- 威望
-
- 存款
-
- 阅读权限
- 5
- 最后登录
- 1970-1-1
该用户从未签到
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
现在在做一个50HZ,1500转的单相交流电机的调速器(闭环,测速通过测速发电机),遇到一些问题:
1、空载时,有轻微的震荡。
2、假负载后,电机时快,时慢,稳定不下来;
采用的是模糊算法,仅有积分和微分相。
这里面是模糊算法程序,请高人指点
void ChangePwm(uint n)
{
uint i;
static uchar accint=0,t=0;
if(++accint>10) //100ms
{
accint =0;
if((setSpeed+2)>conSpeed)
{
i= conSpeed + myReg[REG_ACCT];
if(i>setSpeed) i=setSpeed;
conSpeed = i;
}
else if(setSpeed<(conSpeed-2))
{
i= conSpeed - myReg[REG_ACCT];
if((i< setSpeed)||(i>0x8000)) i=setSpeed; //ÆúíûËù¶èμÄÖμ
conSpeed = i;
}
}
//é趨Ëù¶è óë êμ¼êËù¶è±è½Ï
pwm_cal = conSpeed/5;
diff = conSpeed-n;
if(diff>200)
{
pwm_cal = pwm_cal + 80;
}
else if(diff<(-200))
{
pwm_cal = pwm_cal - 80;
}
else
{
if(conSpeed> n) //PIDμ÷½ú ′Ë′|ê1óÃμÄêÇÄ£ÄaPID 2Îêyí¨1yê±¼äμ÷½ú
{
if(diff> 100) { pwm_cal = pwm_cal + diff/2; }
else if(diff> 50) { pwm_cal = pwm_cal + diff/4; }
else if(diff >20) { pwm_cal =pwm_cal + 4; }
else if(diff> 4)
pwm_cal = pwm_cal +1;
}
else if(conSpeed<n)
{
if(diff< -100) { pwm_cal = pwm_cal+diff/2 ; }
else if(diff< -50) { pwm_cal = pwm_cal +diff/4; }
else if(diff< -20) { pwm_cal =pwm_cal - 4; }
else if(diff< -4)
pwm_cal = pwm_cal -1;
}
//±¾′Îêμ¼êËù¶è óë éÏ′Îêμ¼êËù¶è±è½Ï diff
if(t>2)
{
t = 0;
if((diff<50)&&(diff>-50))
pwm_cal = pwm_cal;
else if((diff<100)&&(diff>-100))
pwm_cal = pwm_cal + (diff-last_diff)*3;
else
pwm_cal = pwm_cal + (diff-last_diff)*8;
}
else
t++;
}
last_diff =diff;
if(pwm_cal< 0) pwm_cal= 0;
if(pwm_cal> 5000) pwm_cal= 5000;
out_pwm = (pwm_cal+last_pwm[0]+last_pwm[1]+last_pwm[2])/4; //′æÖü֮ǰμļ¸′ÎPWMÕ¼¿Õ±èÖμ
last_pwm[0] = last_pwm[1];
last_pwm[1] = last_pwm[2];
last_pwm[2]= pwm_cal;
} |
|