新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > PID算法調節C51程序(4)

        PID算法調節C51程序(4)

        作者: 時間:2016-11-23 來源:網絡 收藏
        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;



        double PIDCalc ( PID *pp, double NextPoint )

        { double dError, Error;

        pp->SumError += (Error = pp->SetPoint - NextPoint);
        dError = pp->LastError - pp->PrevError;
        pp->PrevError = pp->LastError;
        pp->LastError = Error;
        return ( pp->Proportion * Error
        + pp->Integral * pp->SumError
        + pp->Derivative * dError
        );
        }



        void PIDInit ( PID *pp )

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



        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
        }
        }


        關鍵詞: PID算法調節C51程

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 雅江县| 扶余县| 专栏| 买车| 宿松县| 中阳县| 龙州县| 昭苏县| 含山县| 衡东县| 宝坻区| 北票市| 湄潭县| 尼玛县| 榆中县| 卓资县| 襄汾县| 司法| 台中县| 石嘴山市| 东乌珠穆沁旗| 梅州市| 泰顺县| 昌都县| 启东市| 青冈县| 务川| 盐源县| 郴州市| 塔城市| 大庆市| 息烽县| 鸡泽县| 佛冈县| 旌德县| 田东县| 独山县| 犍为县| 甘洛县| 资源县| 华阴市|