單片機(jī)PID算法實(shí)現(xiàn)
#include
#include
struct _pid
{
int pv; //integer that contains the process value 過(guò)程量
int sp; //*integer that contains the set point 設(shè)定值
float integral; // 積分值
float pgain;
float igain;
float dgain;
int deadband; //死區(qū)
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); //設(shè)定值與反饋值偏差
}
float pid_calc(struct _pid *pid)
{·
int err;
float pterm, dterm, result, ferror;
// 計(jì)算偏差
err = (pid->sp) - (pid->pv);
// 判斷是否大于死區(qū)
if (abs(err) > pid->deadband)
{
ferror = (float) err; //do integer to float conversion only once 數(shù)據(jù)類型轉(zhuǎn)換
關(guān)鍵詞:
單片機(jī)PID算
相關(guān)推薦
技術(shù)專區(qū)
- FPGA
- DSP
- MCU
- 示波器
- 步進(jìn)電機(jī)
- Zigbee
- LabVIEW
- Arduino
- RFID
- NFC
- STM32
- Protel
- GPS
- MSP430
- Multisim
- 濾波器
- CAN總線
- 開(kāi)關(guān)電源
- 單片機(jī)
- PCB
- USB
- ARM
- CPLD
- 連接器
- MEMS
- CMOS
- MIPS
- EMC
- EDA
- ROM
- 陀螺儀
- VHDL
- 比較器
- Verilog
- 穩(wěn)壓電源
- RAM
- AVR
- 傳感器
- 可控硅
- IGBT
- 嵌入式開(kāi)發(fā)
- 逆變器
- Quartus
- RS-232
- Cyclone
- 電位器
- 電機(jī)控制
- 藍(lán)牙
- PLC
- PWM
- 汽車電子
- 轉(zhuǎn)換器
- 電源管理
- 信號(hào)放大器
評(píng)論