VB写的PID控制源码公布

前端之家收集整理的这篇文章主要介绍了VB写的PID控制源码公布前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Private Function PIDcalc(SV As Integer,PV As Integer) As Double
Dim SVtemp As Double,PVtemp As Double
Kc = CDbl(Kcin / 10#)
Ti = CDbl(Tiin / 10#)
Td = CDbl(Tdin / 10#)
Ts = CDbl(Tsin / 10#)
Kp = Kc
Ki = Kc * Ts / Ti
Kd = Kc * Td / Ts

SVn_last = SVn_now
SVtemp = CDbl(SV / 32000&)
If SVtemp > 1# Then SVtemp = 1#
If SVtemp < 0# Then SVtemp = 0#
SVn_now = SVtemp

PVn_last = PVn_now
PVtemp = CDbl(PV / 32000&)
If PVtemp > 1# Then PVtemp = 1#
If PVtemp < 0# Then PVtemp = 0#
PVn_now = PVtemp
PVn_now = CDbl(PV / 32000&)

En_last = En_now
En_now = SVn_now - PVn_now

MPn = Kp * En_now


MIn = Ki * En_now + MXn_last
MXn_last = MIn

'MDn = Kd * (En_now - En_last)
MDn = Kd * (PVn_last - PVn_now)

Mn = MPn + MIn + MDn
If Mn > 1# Then MXn_last = 1# - (MPn + MDn)
If Mn < 0# Then MXn_last = 0# - (MPn + MDn)

If Mn > 1# Then Mn = 1#
If Mn < 0# Then Mn = 0#

PIDcalc = Mn

End Function

猜你在找的VB相关文章