欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
增量式pid控制 單片機源程序
[打印本頁]
作者:
ggycode
時間:
2020-8-6 00:03
標題:
增量式pid控制 單片機源程序
單片機源程序如下:
#include <reg51.h>
#include <intrins.h>
#include <absacc.h>
#include "define.h"
#include "delay.h"
#include "da0832.h"
#include "DS18B20_5.h"
#include "lcd1602.h"
#include "zlg.h"
#define PMAX 100
#define PMIN 0
typedef struct
{
char kp,ki,kd;
int e2,e1,e0;
long pa,vpa;
}mypid;
mypid p1;
int final_tem,cur_tem;
//uchar point_on;
//sbit point0=P1^3;
//sbit pout=P1^4;
#define Time_Unit 80
uchar num_unit=0;
uint num100unit=0;
int2char pwm_dtime;
uchar Action();//執行控制量
uint Set_Tem4();//設定4位的溫度值
int PID();//增量式pid算法,輸出為控制量增量p1.vpa 和 p1.pa
void main()
{
uchar keyv;
Lcd_Initial();
Key_Initial();
p1.kp=50;//pid參數設置
p1.ki=10;
p1.kd=5;
da_1=0;
final_tem=Set_Tem4();//設定溫度
p1.pa=0;
p1.e2=0;
p1.e1=0;
p1.e0=0;
//point_on=100;//不導通
TR0=0;//開定時器0
TMOD=0x11;
TH0=0xff;
TL0=0xe0;
TR0=1;
IE=IE|0x02;
EA=1;
num_unit=0;
//=======================以上為始化
while(1)
{
if(key)//查詢按鍵
{
keyv=Keyscan();
if(keyv==15)
{
da_1=0;
final_tem=Set_Tem4();//設定溫度
p1.pa=0;
p1.e2=0;
p1.e1=0;
p1.e0=0;
//point_on=100;//不導通
}
else if(keyv==14)//停止加熱
{
EA=0;
//pout=0;
da_1=0;
}
}
if((num100unit&0x00ff)==0)//2.56s為周期
{
Lcd_Puts(1,0,"aim_tem:");
Lcd_Putfloat(9,0,3,1,final_tem);
cur_tem=GetTemperature();//讀取當前溫度值并顯示
Lcd_Puts(1,1,"now_tem:");
Lcd_Putfloat(9,1,3,1,cur_tem);
PID();//pid控制
Action();//控制執行
}
}
}
uint Set_Tem4()//設定4位的溫度值
{
uchar a,b,c,d;
Lcd_Clr();
Lcd_Puts(1,0,"set Tem:");
while(!key);
a=Keyscan();
Lcd_Putint(10,0,1,a);
while(!key);
b=Keyscan();
Lcd_Putint(11,0,1,b);
while(!key);
c=Keyscan();
Lcd_Putint(12,0,1,c);
while(!key);
d=Keyscan();
Lcd_Putint(13,0,1,d);
return (a*1000+b*100+c*10+d);
}
void Int_T0()interrupt 1 using 2 //ie0x02//TMOD=0x11;
{
EA=0;
TR0=0;
pwm_dtime.time=0xffff-Time_Unit;
TH0=pwm_dtime.hl[0];
TL0=pwm_dtime.hl[1];//定時us
TR0=1;//開定時器0
//t0f=1;//標志置1
/*if(point0==0)//查詢到0點
{
num_unit=0;
}*/
if(num_unit==100)
{
num_unit=0;
num100unit++;
}
/*if(num_unit==0)//0點不導通
{
pout=0;
}
if(num_unit==point_on)//導通點
{
pout=1;
}*/
num_unit++;
EA=1;
}
int PID()//增量式pid算法,輸出為控制量增量p1.vpa 和 p1.pa
{
p1.e2=final_tem - cur_tem;
p1.vpa=p1.kp*((long)p1.e2-p1.e1)
+p1.ki*(long)p1.e2
+p1.kd*((long)p1.e2+p1.e0-2*p1.e1);
p1.e1=p1.e2;
p1.e0=p1.e1;
p1.pa+=p1.vpa;
}
uchar Action()//執行控制量
{
long temp;
if(p1.pa>0)//控制量大于0
{
temp=p1.pa;
temp=temp>>5;
if(temp>PMAX)//完全導通
{
//point_on=0;
da_1=255;
}
else if(temp<PMIN)//完全截至
{
//point_on=100;
da_1=0;
}
else
{
//point_on=100*(PMAX-temp)/(PMAX-PMIN);
da_1=255*temp/(PMAX-PMIN);
}
}
else
{
//point_on=100;//完全截至
da_1=0;
}
return 1;
}
復制代碼
51hei.png
(10.91 KB, 下載次數: 35)
下載附件
2020-8-6 01:32 上傳
所有資料51hei提供下載:
增量式pid-da控制.rar
(56.58 KB, 下載次數: 50)
2020-8-6 00:03 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1