📄 计算机控制设计.frm
字号:
Private Sub Command1_Click() '显示波形调节
nn = nn / 2
If lab_VT = 1 Then
Picture1.Cls
Call gridding
Call p_VT
End If
End Sub
Private Sub Command2_Click()
nn = nn * 2
If lab_VT = 1 Then
Picture1.Cls
Call gridding
Call p_VT
End If
End Sub
Private Sub Command4_Click()
Call activate_showVT_FFT_Click
End Sub
Private Sub Command5_Click()
Call stop_Click
End Sub
Private Sub setting_Click()
Form2.Show
End Sub
Private Sub stop_Click() '停止动态
start = False
End Sub
Private Sub open_Click()
Dim source_data As String
Dim i As Integer
With CommonDialog1
.DialogTitle = "打开V-T数据..."
.CancelError = True
.Filter = "TXT文本文件(*.txt)|*.txt"
.InitDir = "c:\"
.Flags = cdlOFNFileMustExist Or cdlOFNReadOnly
End With '打开V-T原始数据对话框
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1
For i = 0 To n - 1
Input #1, source_data
data(i) = Val(source_data)
Next i
Call p_VT
Close #1
End Sub
Private Sub output_Click()
Dim i As Integer
lab_output = True
For i = 1 To n
If i Mod 5 = 0 Then
Text1.Text = Text1.Text & Chr(13) & Chr(10) '每行输出5个数据
End If
Text1.Text = Text1.Text & " " & Str(data(i))
Next i
End Sub
Private Sub save_Click()
Dim i As Integer
CommonDialog2.DialogTitle = "保存V-T原始数据..."
CommonDialog2.InitDir = "c:\"
CommonDialog2.Filter = "txt文本文件(*.txt)|*.txt"
CommonDialog2.ShowSave '保存V-T原始数据对话框
CommonDialog2.Flags = cdlOFNHideReadOnly Or cdlOFNOverwritePrompt
Open CommonDialog2.FileName For Output As #1
For i = 1 To n
Write #1, Str(data(i))
Next i
Close #1
End Sub
Private Sub cal_cyc() '信号周期分析
Dim data3(2100) As Double
Dim i, m1, m2 As Integer
For i = 1 To nn
data3(i) = data(i)
Next i
i = 1
L1: If data3(i) > 0 Then
While data3(i) > 0
i = i + 1
Wend
m1 = i
While data3(i) < 0
i = i + 1
Wend
m2 = i
Else:
If data3(i) < 0 Then
While data3(i) < 0
i = i + 1
Wend
m1 = i
While data3(i) > 0
i = i + 1
Wend
m2 = i
Else:
If data3(i) = 0 Then i = i + 1
End If
GoTo L1
End If
cyc = ((p1w / nn * (m2 - 1)) - (p1w / nn * (m1 - 1))) / pp1w * s_n * 2
End Sub
Private Sub analyze_Click() '求最值,和,平均值,采样频率并显示
Dim sum, average, max, min As Single
Dim i As Integer
lab_analyze = True
max = min = data(1)
For i = 1 To n
sum = sum + data(i)
If (max < data(i)) Then max = data(i)
If (min > data(i)) Then min = data(i)
Next i
average = sum / n
frequency = 1000 / Interval
s_n = nn / (frequency * 40 * 10 ^ 3) * 10 ^ 6
Call cal_cyc
Text2.Text = "最大值:" & Str(max) & Chr(13) & Chr(10) _
& "最小值:" & Str(min) & Chr(13) & Chr(10) & "平均值:" _
& Str(average) & Chr(13) & Chr(10) & "和:" & Str(sum) & Chr(13) & Chr(10) _
& "采样频率:" & Str(frequency) + "KHZ" & Chr(13) & Chr(10) _
& "信号周期:" & Str(cyc) & "微秒"
End Sub
Private Sub close_Click()
End
End Sub
Private Sub Form_Activate() '试验数据
End Sub
Private Sub Form_Load()
Interval = 40 '8253默认计数值
n = 512 '采样默认点数为2^n数
nn = n
f1t = Frame3.Top: f1l = Frame3.Left: f1w = Frame3.Width: f1h = Frame3.Height
f2t = Frame2.Top: f2l = Frame2.Left: f2w = Frame2.Width: f2h = Frame2.Height
f3t = Frame1.Top: f3l = Frame1.Left: f3w = Frame1.Width: f3h = Frame1.Height
p1t = Picture1.Top: p1l = Picture1.Left: p1w = Picture1.Width: p1h = Picture1.Height
p2t = Picture2.Top: p2l = Picture2.Left: p2w = Picture2.Width: p2h = Picture2.Height
t1t = Text1.Top: t1l = Text1.Left: t1w = Text1.Width: t1h = Text1.Height
t2t = Text2.Top: t2l = Text2.Left: t2w = Text2.Width: t2h = Text2.Height
c5t = Command5.Top: c5l = Command5.Left: c5w = Command5.Width: c5h = Command5.Height
c4t = Command4.Top: c4l = Command4.Left: c4w = Command4.Width: c4h = Command4.Height
End Sub
Private Sub Form_Resize()
On Error GoTo cancel
Form1.ScaleHeight = 240.749
Form1.ScaleWidth = 201.085
Frame3.Top = f1t: Frame3.Left = f1l: Frame3.Width = f1w: Frame3.Height = f1h
Frame2.Top = f2t: Frame2.Left = f2l: Frame2.Width = f2w: Frame2.Height = f2h
Frame1.Top = f3t: Frame1.Left = f3l: Frame1.Width = f3w: Frame1.Height = f3h
Picture1.Top = p1t: Picture1.Left = p1l: Picture1.Width = p1w: Picture1.Height = p1h
Picture2.Top = p2t: Picture2.Left = p2l: Picture2.Width = p2w: Picture2.Height = p2h
Text1.Top = t1t: Text1.Left = t1l: Text1.Width = t1w: Text1.Height = t1h
Text2.Top = t2t: Text2.Left = t2l: Text2.Width = t2w: Text2.Height = t2h
Command5.Top = c5t: Command5.Left = c5l: Command5.Width = c5w: Command5.Height = c5h
Command4.Top = c4t: Command4.Left = c4l: Command4.Width = c4w: Command4.Height = c4h
Picture1.Cls
Picture2.Cls
Call gridding
cancel:
End Sub
Private Sub get_data_Click() '采样
Dim i As Integer
Dim channel, baseaddress, ntportio, temp As Single
channel = 0 'AC1059的操作通道号为0
baseaddress = &H210 'AC1059的IO地址取210H
ntportio = AC_OpenDriver_VB '获取驱动句柄
AC1059_Set8253Mode_VB ntportio, &H21B, &HB4 '设置8253工作模式,选择通道2,方式2(频率发生器),
AC1059_Set8253Timer_VB ntportio, &H21A, 2, Interval '写入8253计数值
For i = 1 To n
temp = AC1059_ADSampleAverage_VB(ntportio, baseaddress, channel, 1, 1) '设置1059E工作方式,定时器模式,采样次数为1,采样频率为1/40(us)
data(i) = (temp - 2048) * 5 / 2048 / 1 '转化为电压值,增益为1,双极性正负5V
Next i
AC_CloseDriver_VB (ntportio) '解除句柄
End Sub
Private Sub clear_Click() '清屏
lab_VT = 0
lab_FFT = 0
lab_analyze = False
lab_output = False
Picture1.Cls
Picture2.Cls
Text1.Text = ""
Text2.Text = ""
Call gridding
End Sub
Private Sub gridding()
Dim i As Integer
p1h = Picture1.Height
p1w = Picture1.Width
Picture1.Scale (0, p1h / 2)-(p1w, -p1h / 2)
pp1h = p1h / 22
pp1w = p1w / 40
For i = -11 To 11 '画水平线并标注
If i = 0 Then
Picture1.Line (0, pp1h * i)-(p1w, pp1h * i), QBColor(12)
Picture1.CurrentX = i
Picture1.CurrentY = i
Picture1.Print pp1h * i
Else: Picture1.Line (0, pp1h * i)-(p1w, pp1h * i), QBColor(9)
Picture1.CurrentX = 0
Picture1.CurrentY = pp1h * i
Picture1.Print i
End If
Next i
For i = 0 To 40 '画垂直线并标注
If i = 0 Then
Picture1.Line (0, p1h / 2)-(0, -p1h / 2), QBColor(12)
Else: Picture1.Line (pp1w * i, p1h / 2)-(pp1w * i, -p1h / 2), QBColor(9)
Picture1.CurrentX = pp1w * i
Picture1.CurrentY = 0
Picture1.Print i
End If
Next i
End Sub
Private Sub gridding2()
End Sub
Private Sub p_VT() '绘制V-T波形图
Dim i As Integer
Dim data1(2100) As Single
lab_VT = 1
frequency = 1000 / Interval
s_n = nn / (frequency * 40 * 10 ^ 3) * 10 ^ 6
Frame1.Caption = "时域波形显示" + "" + Str(s_n) + "(微秒/格)"
For i = 1 To nn - 1
data1(i) = data(i) * pp1h
data1(i + 1) = data(i + 1) * pp1h
Picture1.Line ((p1w / nn) * (i - 1), data1(i))-((p1w / nn) * i, data1(i + 1)), QBColor(12)
Next i
End Sub
Private Sub p_FFT() '绘制FFT图
Dim wr As Double, wi As Double, mmax As Double, i As Double
Dim j As Integer
lab_FFT = 1
t = Interval / 1000# / 2 * (n - 1)
For i = 1 To n
data2(i) = data(i)
Next i
wr = Cos(Pi / n)
wi = Sin(Pi / n)
Call Rdft(n, wr, wi, data2)
mmax = data2(1)
For j = 1 To n
If (data2(j) > mmax) Then mmax = data2(j)
Next j
v2 = 2 * mmax 'v2调整图形纵向比例
Picture2.Scale (-t, v2)-(t, -v2 / 5)
s = Interval / 1000#: j = 1 's调节图形横向比例
For i = -t To t - s Step s
Picture2.Line (i, Abs(data2(j)))-((i + s), Abs(data2(j + 1))), QBColor(12)
j = j + 1
Next i
End Sub
Private Sub refursh_Click()
Picture1.Cls
Picture2.Cls
Text1.Text = ""
Text2.Text = ""
Call gridding
If lab_VT = 1 Then
Call p_VT
End If
If lab_FFT = 1 Then
Call p_FFT
End If
If lab_analyze = True Then
Call analyze_Click
End If
If lab_output Then
Call output_Click
End If
End Sub
Private Sub show_FFT_Click()
Call stop_Click
Call p_FFT
End Sub
Private Sub show_VT_Click()
Call stop_Click
Call p_VT
End Sub
Private Sub Timer1_Timer()
If start Then
On Error GoTo concel
Picture1.Cls
Picture2.Cls
Call gridding
Call p_FFT
Call p_VT
End If
concel:
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -