真心求教,VB 增量式 PID 算法的一个问题
增量式PID算法.zip
(2.75 KB)
Option Explicit
Dim EK1 As Single, EK2 As Single
Dim U As Single
Dim Uk As Single, Uk1 As Single, A As Single, B As Single, C As Single, Ek As Single
Dim Ti As Integer, Td As Integer, Kp As Integer
Dim SP As Single, PV As Single
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Timer1_Timer()
Ti = Val(Text1) '读取积分时间值
Td = Val(Text2) '读取微分时间值
Kp = Val(Text3) '读取比例值
SP = Val(Text4) '设定值
Text5.Text = Val(VScroll1.Value)
PV = Val(Text5) '模拟的反馈值
If Ti = 0 Then
A = Kp * (1 + Td)
Else
A = Kp * (1 + 1 / Ti + Td)
B = Kp * (1 + 2 * Td)
C = Kp * Td
Ek = SP - PV
Uk = A * Ek - B * EK1 + C * EK2
Text6.Text = Uk '输出显示
End If
EK2 = EK1
EK1 = Ek
End Sub
求助各位版主,这是我编写的PID控制程序,EK表示当前的测量误差,EK1是上次测量误差,EK2是上上次误差,然后PID算法根据这三次误差输出控制量UK,正确的功能应该是根据系统设定值和实际输出值求得Ek = SP - PV,然后将这个的EK值传递给EK1,下一次测量值编程Ek,以此类推!我现在的问题是,无法将当前的测量误差传递给上一次,按着我编的程序,这三次误差实际上都等于当前的误差,求各位版主看一下问题出在哪儿!