天堂草原最受欢迎的角色,天堂动漫,天堂在线,色天堂下载,天堂中文在线资源,亚洲男人天堂

技術熱線: 4007-888-234

技術支持

標準的PID處理例程標準的PID處理例程

更新時間: 2019-03-23

十年專注單片機方案開發的方案公司英銳恩,分享標準的PID處理例程標準的PID處理例程。英銳恩現提供服務產品涉及主控芯片:8位單片機、16位單片機、32位單片機及各類運算放大器等。

--- 工業控制中常用算法 ---

/*====================================================================================================

    這是從網上找來的一個比較典型的PID處理程序,在使用單片機作為控制cpu時,請稍作簡化,具體的PID

參數必須由具體對象通過實驗確定。由于單片機的處理速度和ram資源的限制,一般不采用浮點數運算,

而將所有參數全部用整數,運算到最后再除以一個2的N次方數據(相當于移位),作類似定點數運算,可

大大提高運算速度,根據控制精度的不同要求,當精度要求很高時,注意保留移位引起的“余數”,做好余

數補償。這個程序只是一般常用pid算法的基本架構,沒有包含輸入輸出處理部分。

=====================================================================================================*/

#include

#include 

/*====================================================================================================

    PID Function

    

    The PID (比例、積分、微分) function is used in mainly

    control applications. PIDCalc performs one iteration of the PID

    algorithm.

 

    While the PID function works, main is just a dummy program showing

    a typical usage.

=====================================================================================================*/

 

typedef struct PID {

 

        double  SetPoint;           //  設定目標 Desired Value

 

        double  Proportion;         //  比例常數 Proportional Const

        double  Integral;           //  積分常數 Integral Const

        double  Derivative;         //  微分常數 Derivative Const

 

        double  LastError;          //  Error[-1]

        double  PrevError;          //  Error[-2]

        double  SumError;           //  Sums of Errors

 

} PID;

/*==================================================================

==================================

   PID計算部分

=====================================================================================================*/

 

double PIDCalc( PID *pp, double NextPoint )

{

    double  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             // 微分項

        );

}

 

/*====================================================================================================

Initialize PID Structure

=====================================================================================================*/

 

void PIDInit (PID *pp)

{

    memset ( pp,0,sizeof(PID));

}

 

/*====================================================================================================

    Main Program

=====================================================================================================*/

 

double sensor (void)                    //  Dummy Sensor Function

{

    return 100.0;

}

void actuator(double rDelta)            //  Dummy Actuator Function

{}

 

void main(void)

{

    PID         sPID;                   //  PID Control Structure

    double      rOut;                   //  PID Response (Output)

    double      rIn;                    //  PID Feedback (Input)

 

    PIDInit ( &sPID );                  //  Initialize Structure

    sPID.Proportion = 0.5;              //  Set PID Coefficients

    sPID.Integral   = 0.5;

    sPID.Derivative = 0.0;

    sPID.SetPoint   = 100.0;            //  Set PID Setpoint

 

    for (;;) {                          //  Mock Up of PID Processing

 

        rIn = sensor ();                //  Read Input

 rOut = PIDCalc ( &sPID,rIn );   //  Perform PID Interation

        actuator ( rOut );              //  Effect Needed Changes

    }

}

404
返回首頁 |  返回上一頁
联系我们: 大连市| 合肥市| 台安县| 五大连池市| 云霄县| 白河县| 遵义县| 镶黄旗| 邯郸县| 四子王旗| 丰台区| 揭西县| 宁国市| 栾城县| 横山县| 裕民县| 丰县| 蓝田县| 万山特区| 亚东县| 贵阳市| 定西市| 泰和县| 潞城市| 晋州市| 嘉峪关市| 额济纳旗| 德阳市| 满洲里市| 庆元县| 特克斯县| 西城区| 安远县| 太仆寺旗| 英山县| 阿城市| 洪泽县| 祁阳县| 尼木县| 扬州市| 饶平县|