新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 單片機PID算法實現

        單片機PID算法實現

        作者: 時間:2016-12-01 來源:網絡 收藏
        在avr單片機上實現的100%通過測試,用單片機調的倒立擺非常穩定.
        #include
        #include

        struct _pid
        {
        int pv; //integer that contains the process value 過程量
        int sp; //*integer that contains the set point 設定值
        float integral; // 積分值
        float pgain;
        float igain;
        float dgain;
        int deadband; //死區
        int last_error;
        };

        struct _pid warm,*pid;
        int process_point, set_point,dead_band;
        float p_gain, i_gain, d_gain, integral_val,new_integ;;

        void pid_init(struct _pid *warm, int process_point, int set_point)
        {
        struct _pid *pid;
        pid = warm;
        pid->pv = process_point;
        pid->sp = set_point;
        }


        void pid_tune(struct _pid *pid, float p_gain, float i_gain, float d_gain, int dead_band)
        {
        pid->pgain = p_gain;
        pid->igain = i_gain;
        pid->dgain = d_gain;
        pid->deadband = dead_band;
        pid->integral= integral_val;
        pid->last_error=0;
        }



        void pid_setinteg(struct _pid *pid,float new_integ)
        {
        pid->integral = new_integ;
        pid->last_error = 0;
        }


        void pid_bumpless(struct _pid *pid)
        {
        pid->last_error = (pid->sp)-(pid->pv); //設定值與反饋值偏差
        }




        float pid_calc(struct _pid *pid)
        int err;
        float pterm, dterm, result, ferror;

        // 計算偏差
        err = (pid->sp) - (pid->pv);

        // 判斷是否大于死區
        if (abs(err) > pid->deadband)
        {
        ferror = (float) err; //do integer to float conversion only once 數據類型轉換

        上一頁 1 2 下一頁

        關鍵詞: 單片機PID算

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 陵川县| 澜沧| 汶上县| 海口市| 扎赉特旗| 吴旗县| 濉溪县| 三河市| 安阳市| 英德市| 留坝县| 法库县| 桂东县| 登封市| 九江市| 洛阳市| 舞钢市| 垦利县| 海门市| 洪泽县| 曲沃县| 玛纳斯县| 昌江| 阳西县| 穆棱市| 吴忠市| 瓮安县| 宁都县| 长春市| 北海市| 西青区| 余干县| 松原市| 鹤庆县| 察哈| 兴隆县| 南岸区| 工布江达县| 瑞安市| 双城市| 吉安市|