久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2993|回復: 0
收起左側

pid控溫程序存在,測了輸出端波形很亂,但變化有一定規律,pwm波不是方波嗎?怎么....

[復制鏈接]
ID:95878 發表于 2015-11-15 17:09 | 顯示全部樓層 |閱讀模式
#include<intrins.h>
#include<math.h>
#include<string.h>
struct PID
{
    unsigned int SetPoint ;
    // 設定目標 Desired Value
    unsigned int Proportion ;
    // 比例常數 Proportional Const
    unsigned int Integral ;
    // 積分常數 Integral Const
    unsigned int Derivative ;
    // 微分常數 Derivative Const
    unsigned int LastError ;
    // Error[-1]
    unsigned int PrevError ;
    // Error[-2]
    unsigned int SumError ;
    // Sums of Errors
}
;
struct PID spid ;
// PID Control Structure
unsigned int rout ;
// PID Response (Output)
unsigned int rin ;
// PID Feedback (Input)
unsigned int set_temper,temper,s ;


sbit output=P3^4;
unsigned char high_time,low_time,count=0 ;
//占空比調節參數


void PIDInit(struct PID*pp)
{
    memset(pp,0,sizeof(struct PID)); //PID參數初始化全部設置為0
}

unsigned int PIDCalc(struct PID*pp,unsigned int NextPoint)
{
    unsigned int dError,Error ;
    Error=pp->SetPoint-NextPoint ;
    // 偏差
    pp->SumError+=Error ;
    // 積分
    dError=pp->LastError-pp->PrevError ;
    // 當前微分
    pp->PrevError=pp->LastError ;
    pp->LastError=Error ;
    //比例
    //積分項
    return(pp->Proportion*Error+pp->Integral*pp->SumError+pp->Derivative*dError);
    // 微分項
}

/***********************************************************
溫度比較處理子程序
***********************************************************/
void compare_temper(unsigned int set_temper,unsigned int temper)
{
    unsigned char i ;
    //EA=0;
    if(set_temper>temper)
    {
        if(set_temper-temper>10)
        {
            high_time=100 ; //大于1°不進行PID運算
            low_time=0 ;
        }
        else
        {   //在1°范圍內進行PID運算
            for(i=0;i<10;i++)
            {
                //get_temper();
                rin=temper;
                // Read Input
                rout=PIDCalc(&spid,rin); //執行PID運算
                // Perform PID Interation
            }
            if(high_time<=100) //限制最大值
            high_time=(unsigned char)(rout/800);
            else
            high_time=100;
            low_time=(100-high_time);
        }
    }
/****************************************/
    else if(set_temper<=temper) //當實際溫度大于設置溫度時
    {
        if(temper-set_temper>0)//如果實際溫度大于設定溫度
        {
            high_time=0 ;
            low_time=100 ;
        }
        else
        {
            for(i=0;i<10;i++)
            {
                //get_temper();
                rin=temper;
                // Read Input
                rout=PIDCalc(&spid,rin);
                // Perform PID Interation
            }
            if(high_time<100) //此變量是無符號字符型
            high_time=(unsigned char)(rout/10000);
            else
            high_time=0 ;//限制不輸出負值
            low_time=(100-high_time);
            //EA=1;
        }
    }
}


/*****************************************************
T1中斷服務子程序,用于控制電平的翻轉 ,40us*100=4ms周期
******************************************************/
void serve_T1()interrupt 3 using 1
{
    if(++count<=(high_time))
         output=0 ;
    else if(count<=100)
    {
        output=1 ;
    }
    else
    count=0 ;
    TH1=0x2f ;
    TL1=0xe0 ;
}

void PIDBEGIN()
{


    TH1=0x2f ;
    TL1=0x40 ;


    ET1=1 ;
    TR1=1 ;

    high_time=50 ;
    low_time=50 ;
    PIDInit(&spid);
    // Initialize Structure
    spid.Proportion=10 ;
    // Set PID Coefficients
    spid.Integral=8 ;
    spid.Derivative=6 ;
    spid.SetPoint=100 ;
    // Set PID Setpoint

}
#endif
main
{
while(1){
PIDBEGIN();
if(hengwen==0)
{

  compare_temper(temp4,temp5);

}
}
}
temp4是設定溫度和temp5時實際溫度,求高人指點,急急急

回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久九九视频 | 久久88| 国产午夜影院 | 51av视频 | 久久99免费视频 | 午夜视频在线 | 成人免费视频一区二区 | 91在线精品秘密一区二区 | 成年人免费看片 | 日韩欧美综合 | 亚洲免费福利视频 | 国产综合久久 | 狠狠的操 | 高清视频一区二区 | 欧美一区二区免费 | 久久这里都是精品 | 天天躁狠狠躁 | 美女视频福利 | 国产不卡在线视频 | 中文字幕免费视频 | 免费观看av | 免费黄色一级 | av一区二区三区 | 亚洲综合激情网 | 成年人的免费视频 | 日韩欧美网站 | 久久亚洲精品视频 | 亚洲成人精品在线观看 | 欧美一区二区在线视频 | 日韩av在线网址 | 香蕉在线播放 | 五月婷婷丁香花 | 黄色a一级片 | 亚洲精品综合 | 美女无遮挡网站 | 欧美在线免费观看 | 欧美片网站yy | 波多野一区 | 日韩在线不卡 | 久久精品视频一区二区 | 男女操网站 |