110,571
社区成员
发帖
与我相关
我的任务
分享
Private Sub Timer1_Timer()
On Error Resume Next
If Text2 < 0 Then
Text2 = 0
End If
If Text2 > 100 Then
Text2 = 100
End If
gain = Val(Text2)
If Text3 < 0 Then
Text3 = 0
End If
If Text3 > 120 Then
Text3 = 120
End If
reset = Val(Text3)
If Text4 < 0 Then
Text4 = 0
End If
If Text4 > 120 Then
Text4 = 120
End If
rate = Val(Text4)
If pv < 3101 Then
pv = pv + invalve
End If
If pv > 0 Then
pv = pv - outvalve
End If
Text1.Text = pv
error = sp - pv
Label30.Caption = error
Label38.Caption = supply
tank
If stability = 1 Then
watersupply
invalve = (HScroll1.Value * (supply / 100)) / 60
End If
If mode = 1 Then
pidloop
End If
' 画曲线PV过程变量
' Graph the PV, Process Variable
Picture1.Cls
pvgraph(100) = pv
For x = 0 To 99
pvgraph(x) = pvgraph(x + 1)
Picture1.PSet (x, 3000 - (pvgraph(x)))
Next x
' Display the SP line (yellow)
Picture1.Line (0, 3000 - sp)-(100, 3000 - sp), vbYellow
' Graph the OUTPUT VALVE position
Picture2.Cls
outgraph(100) = outvalve
For x = 0 To 99
outgraph(x) = outgraph(x + 1)
Picture2.PSet (x, 100 - (outgraph(x) * 2))
Next x
End Sub
'********************************************************
Private Sub tank()
If HScroll1.Value > 0 Then
Shape7.FillStyle = 0
Shape8.FillStyle = 0
Shape9.FillStyle = 0
Else: Shape7.FillStyle = 1
Shape8.FillStyle = 1
Shape9.FillStyle = 1
End If
If pv > -1 Then
Shape1(0).Top = (3100 - pv) + 1030
Shape1(0).Height = pv
End If
If (pv > 0) Or (HScroll1.Value > 0) Then
Shape10.FillStyle = 0
Else: Shape10.FillStyle = 1
End If
If (HScroll2.Value > 0) And (pv > 0) Then
Shape11.FillStyle = 0
Else: Shape11.FillStyle = 1
End If
End Sub
'********************************************************
Private Sub watersupply()
Randomize
s1 = Int(Rnd(1) * 20 + 1)
Randomize
s2 = Int(Rnd(1) * 1000 + 1)
If s2 < 100 Then
supply = supply + s1
End If
If s2 > 900 Then
supply = supply - s1
End If
If supply < 500 Then
supply = 500
End If
If supply > 2500 Then
supply = 2500
End If
End Sub
'********************************************************
Private Sub pidloop()
dfilter = 10 ' Filter value to scale down derivative effect.
inputd = pv + (inputlast - pv) * (rate / 60)
inputlast = pv
inputdf = inputdf + (inputd - inputdf) * dfilter / 60
output = (sp - inputdf) * (gain / 100) + feedback
If output > 100 Then ' clamp output valve between 0 and 100%
output = 100
End If
If output < 0 Then
output = 0
End If
HScroll2.Value = 100 - output ' Change slider value (AUTO MODE)
Picture4.Width = HScroll2.Value * 20
Label14.Caption = HScroll2.Value
feedback = feedback - (feedback - output) * reset / 60
End Sub