📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3870
ClientLeft = 2850
ClientTop = 4455
ClientWidth = 6450
BeginProperty Font
Name = "宋体"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Icon = "Form1.frx":0000
LinkTopic = "Form1"
LockControls = -1 'True
ScaleHeight = 3870
ScaleWidth = 6450
Begin VB.Frame frame1
Caption = "两路测频:"
Height = 2880
Left = 240
TabIndex = 2
Top = 750
Width = 5955
Begin VB.CommandButton cmdStopTestFreq
Caption = "停止测频"
Height = 450
Left = 3525
TabIndex = 4
Top = 2025
Width = 1380
End
Begin VB.CommandButton cmdStartTestFreq
Caption = "开始测频"
Height = 450
Left = 1620
TabIndex = 3
Top = 2025
Width = 1395
End
Begin VB.Label lblStatic
AutoSize = -1 'True
Caption = "计数器1用于定时中断:"
Height = 225
Index = 3
Left = 735
TabIndex = 10
Top = 525
Width = 2280
End
Begin VB.Label lblStatic
AutoSize = -1 'True
Caption = "计数2测频结果:"
Height = 225
Index = 0
Left = 1410
TabIndex = 9
Top = 960
Width = 1605
End
Begin VB.Label lblStatic
AutoSize = -1 'True
Caption = "计数3测频结果:"
Height = 225
Index = 2
Left = 1410
TabIndex = 8
Top = 1380
Width = 1605
End
Begin VB.Label lblCurrCTval
BorderStyle = 1 'Fixed Single
Caption = "当前值1"
Height = 330
Index = 0
Left = 3105
TabIndex = 7
Top = 450
Width = 2070
End
Begin VB.Label lblCurrCTval
BorderStyle = 1 'Fixed Single
Caption = "当前值2"
Height = 330
Index = 1
Left = 3105
TabIndex = 6
Top = 900
Width = 2070
End
Begin VB.Label lblCurrCTval
BorderStyle = 1 'Fixed Single
Caption = "当前值3"
Height = 330
Index = 2
Left = 3105
TabIndex = 5
Top = 1350
Width = 2070
End
End
Begin VB.Timer timerFreq
Left = 3990
Top = 165
End
Begin VB.Label lblBaseAddr
BorderStyle = 1 'Fixed Single
Caption = "板卡基地址"
Height = 360
Left = 1620
TabIndex = 1
Top = 120
Width = 1560
End
Begin VB.Label lblStatic
AutoSize = -1 'True
Caption = "板卡基地址:"
Height = 225
Index = 1
Left = 255
TabIndex = 0
Top = 195
Width = 1245
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public m_cardNO As Long 'pci卡的板卡索引号
Public m_timerFreqFinish As Boolean
Const m_CTchCount As Long = 3
Private Sub cmdStartTestFreq_Click()
'开始测频
Call ZT8361_CloseIRQ(m_cardNO) '关闭中断
Call ZT8361_DisableAD(m_cardNO) '停止定时AD
ZT8361_ClearSFifo m_cardNO, 4 '清计数器SFIFO
'计数通道1用于产生定时中断,每 1000/200=5ms 产生一次中断
ZT8361_Adv_CTinit m_cardNO, 1, 2, 0, 0, 12000000, 200, 0, 0
'计数通道2用于测频,挂接到计数通道1,每 5*4=20ms计算一次频率
ZT8361_Adv_CTinit m_cardNO, 2, 4, 0, 0, 0, 0, &H1, 4
'ZT8361_Adv_CTinit m_cardNO, 2, 1, 0, 0, 12000000, 2000000, 0, 0 '计数通道2用于分频,产生2M的时钟
'计数通道3用于测频,挂接到计数通道1,每 5*4=20ms计算一次频率
ZT8361_Adv_CTinit m_cardNO, 3, 4, 0, 0, 0, 0, &H1, 4
ZT8361_Adv_CTstart m_cardNO, &H7, 0 '启动3个计数器
Call ZT8361_ReadW(m_cardNO, 36) 'clear EI irq
Call ZT8361_WriteW(m_cardNO, 32, &H10) '打开中断
'Call ZT8361_InitIRQ(m_cardNO, &H3)
ZT8361_OpenIRQ m_cardNO, 0, 0, 0, 0, 0 '打开中断
m_timerFreqFinish = True
timerFreq.Interval = 100
timerFreq.Enabled = True
If ZT8361_GetLastErr <> 0 Then Me.Caption = "PCI8361BN测试程序(错误号: " & ZT8361_GetLastErr & ")" '返回函数执行的状态
End Sub
Private Sub cmdStopTestFreq_Click()
'停止测频
Call ZT8361_CloseIRQ(m_cardNO) '关闭中断
Call ZT8361_DisableAD(m_cardNO) '停止定时AD
End Sub
Private Sub Form_Load()
'打开设备
m_cardNO = 1
If ZT8361_OpenDevice(m_cardNO) <> 0 Then
MsgBox "打开设备失败,找不到指定的板卡。"
End
End If
lblBaseAddr.Caption = "&&H" & Hex(ZT8361_GetBaseAddr(m_cardNO))
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 3
'停止所有计数器
Dim i As Long
For i = 0 To m_CTchCount - 1
ZT8361_CTStop m_cardNO, i + 1, 0
Next i
Me.Caption = "PCI8361BN测试(错误号: " & ZT8361_GetLastErr & ")" '返回函数执行的状态
End Sub
Private Sub Form_Unload(Cancel As Integer)
'关闭设备
ZT8361_ClearLastErr
Call ZT8361_CloseIRQ(m_cardNO)
If ZT8361_CloseDevice(m_cardNO) <> 0 Then
'MsgBox "关闭设备失败 " & ZT8361_GetLastErr
End If
End Sub
Private Sub timerFreq_Timer()
'从计数器专用软件缓冲区中读频率值
If m_timerFreqFinish = False Then Exit Sub
m_timerFreqFinish = False
Dim retCount As Long, count As Long, wantCount As Long, i As Long
Dim readData(8000 - 1) As Long
wantCount = 30 * 2 '每通道3个数
count = ZT8361_GetSFifoDataCount(m_cardNO, 4) '判断计数器专用软件缓冲区中数据的数量
frame1.Caption = "计数器软件缓冲区中数据个数: " & count
If count >= wantCount Then
'读计数缓冲区中的值, 每个用于测频的通道每次定时中断产生3个数, 第1个数为计数间隔, 第2个数/第3个数=时间间隔
'开始测频后, 第1次得到的计数间隔值需要舍弃
retCount = ZT8361_ReadSFifo(m_cardNO, 4, 2, readData(0), wantCount) '读频率值
If readData(1) > 0 And readData(2) > 0 Then
lblCurrCTval(1).Caption = Format(readData(0) / (readData(1) / readData(2)), "0.##Hz")
End If
If readData(4) > 0 And readData(5) > 0 Then
lblCurrCTval(2).Caption = Format(readData(3) / (readData(4) / readData(5)), "0.##Hz")
End If
End If
If ZT8361_GetLastErr <> 0 Then Me.Caption = "PCI8361BN测试程序(错误号: " & ZT8361_GetLastErr & ")" '返回函数执行的状态
m_timerFreqFinish = True
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -