📄 frmcalibratecurrent.frm
字号:
VERSION 5.00
Begin VB.Form frmCalibrateCurrent
Caption = "Calibrate Current Measurement"
ClientHeight = 2925
ClientLeft = 60
ClientTop = 345
ClientWidth = 5175
Icon = "frmCalibrateCurrent.frx":0000
LinkTopic = "Form1"
ScaleHeight = 2925
ScaleWidth = 5175
StartUpPosition = 2 'CenterScreen
Begin VB.CommandButton cmdUpdate
Caption = "Apply"
Height = 375
Left = 2280
TabIndex = 2
Top = 2520
Width = 1335
End
Begin VB.CommandButton cmdCancel
Cancel = -1 'True
Caption = "Cancel"
Height = 375
Left = 840
TabIndex = 4
Top = 2520
Width = 1335
End
Begin VB.CommandButton cmdOK
Caption = "OK"
Default = -1 'True
Height = 375
Left = 3720
TabIndex = 3
Top = 2520
Width = 1335
End
Begin VB.Frame Frame1
Height = 2415
Left = 0
TabIndex = 0
Top = 0
Width = 5175
Begin VB.TextBox txtOffsetRegister
Alignment = 1 'Right Justify
Height = 285
Left = 1965
MultiLine = -1 'True
TabIndex = 1
Text = "frmCalibrateCurrent.frx":030A
Top = 240
Width = 615
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "Offset Register"
Height = 255
Index = 1
Left = 120
TabIndex = 18
Top = 240
Width = 1935
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "mAmps"
Height = 255
Index = 9
Left = 4200
TabIndex = 17
Top = 960
Width = 855
End
Begin VB.Label lblAverageCurrent
Alignment = 1 'Right Justify
BackStyle = 0 'Transparent
Caption = "0.000"
Height = 255
Left = 3240
TabIndex = 16
Top = 960
Width = 855
End
Begin VB.Label Label4
BackStyle = 0 'Transparent
Caption = "LSb"
Height = 255
Index = 3
Left = 2640
TabIndex = 15
Top = 960
Width = 495
End
Begin VB.Label lblAverageLSB
Alignment = 1 'Right Justify
BackStyle = 0 'Transparent
Caption = "0"
Height = 255
Left = 1440
TabIndex = 14
Top = 960
Width = 1095
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "Average Current"
Height = 255
Index = 4
Left = 120
TabIndex = 13
Top = 960
Width = 1575
End
Begin VB.Label lblOffsetRegister
Alignment = 1 'Right Justify
BackStyle = 0 'Transparent
Caption = "0.000"
Height = 255
Left = 3240
TabIndex = 12
Top = 300
Width = 855
End
Begin VB.Label Label4
BackStyle = 0 'Transparent
Caption = "LSb"
Height = 255
Index = 2
Left = 2640
TabIndex = 11
Top = 285
Width = 375
End
Begin VB.Label Label4
BackStyle = 0 'Transparent
Caption = "LSb"
Height = 255
Index = 1
Left = 2640
TabIndex = 10
Top = 600
Width = 495
End
Begin VB.Label lblCorrectedLSB
Alignment = 1 'Right Justify
BackStyle = 0 'Transparent
Caption = "0"
Height = 255
Left = 1560
TabIndex = 9
Top = 600
Width = 975
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "mAmps"
Height = 255
Index = 7
Left = 4200
TabIndex = 8
Top = 300
Width = 855
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "mAmps"
Height = 255
Index = 6
Left = 4200
TabIndex = 7
Top = 600
Width = 855
End
Begin VB.Label lblCorrectedCurrent
Alignment = 1 'Right Justify
BackStyle = 0 'Transparent
Caption = "0.000"
Height = 255
Left = 3240
TabIndex = 6
Top = 600
Width = 855
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "Current Register"
Height = 255
Index = 2
Left = 120
TabIndex = 5
Top = 600
Width = 1575
End
End
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 1000
Left = 0
Top = 0
End
End
Attribute VB_Name = "frmCalibrateCurrent"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim AverageCurrent As Single
Dim CurrentArray(8) As Single
Dim ArrayCount As Integer
Private Sub cmdCancel_Click()
frmEvalKit.ReadTimer.Enabled = True
Unload Me
End Sub
Private Sub cmdOK_Click()
cmdUpdate_Click
Unload Me
End Sub
Private Sub cmdUpdate_Click()
Dim SRAM(16) As Integer
Dim i As Integer
Dim temp As String
temp = Val(txtSenseResistor.Text) / 1000
If Not (SenseResistor = temp) Then
temp = ((txtSenseResistor.Text))
If Not (txtSenseResistor.Text = temp) Then
MsgBox "The Sense Resistor entry is not formatted correctly."
txtSenseResistor.Text = Format(SenseResistor * 1000, "#0.0")
Exit Sub
ElseIf Val(txtSenseResistor.Text) < 0 Then
MsgBox "The Sense Resistor entry cannot be negative."
txtSenseResistor.Text = Format(SenseResistor * 1000, "#0.0")
Exit Sub
ElseIf Val(txtSenseResistor.Text) = 0 Then
MsgBox "The Sense Resistor entry cannot be zero."
txtSenseResistor.Text = Format(SenseResistor * 1000, "#0.0")
Exit Sub
End If
SenseResistor = Val(txtSenseResistor.Text) / 1000
txtSenseResistor.Text = Format(SenseResistor * 1000, "#0.0")
Else
txtSenseResistor.Text = Format(SenseResistor * 1000, "#0.0")
End If
temp = (Val(txtOffsetRegister.Text))
If Not (txtOffsetRegister.Text = temp) Then
MsgBox "Offset entry is not formatted correctly."
txtOffsetRegister.Text = CurrentOffsetBias
Exit Sub
End If
CurrentOffsetBias = Int(Val(txtOffsetRegister.Text))
If CurrentOffsetBias < 0 Then
CurrentOffsetBias = CurrentOffsetBias + 256
End If
If CurrentOffsetBias > 255 Then
CurrentOffsetBias = 255
End If
DataIn(51) = CurrentOffsetBias
WriteBytes 51, 1
ReadBytes 51, 1
CurrentOffsetBias = DataRead(51)
If CurrentOffsetBias > 127 Then
CurrentOffsetBias = CurrentOffsetBias - 256
End If
txtOffsetRegister.Text = CurrentOffsetBias
ReadBytes 48, 16
For i = 0 To 15
SRAM(i) = DataRead(i + 48)
Next i
RecallBytes 48
ReadBytes 48, 16
For i = 0 To 15
DataIn(i + 48) = DataRead(i + 48)
Next i
DataIn(51) = SRAM(3)
WriteBytes 48, 16
CopyBytes 48
For i = 0 To 15
DataIn(i + 48) = SRAM(i)
Next i
WriteBytes 48, 16
End Sub
Private Sub Form_Load()
frmEvalKit.ReadTimer = False
txtSenseResistor.Text = Format(SenseResistor * 1000, "#0.0")
If ExternalResistor = True Then
optExternalResistor.Value = True
txtSenseResistor.Visible = True
Else
optInternalResistor.Value = True
txtSenseResistor.Visible = False
End If
ReadBytes 51, 1
CurrentOffsetBias = DataRead(51)
If CurrentOffsetBias > 127 Then
CurrentOffsetBias = CurrentOffsetBias - 256
End If
txtOffsetRegister.Text = CurrentOffsetBias
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim temp As Single
Dim i As Integer
If optInternalResistor.Value = True Then
txtSenseResistor.Visible = False
ExternalResistor = False
Else
txtSenseResistor.Visible = True
ExternalResistor = True
End If
ReadBytes 14, 2
gCurrentMSB = DataRead(14)
gCurrentLSB = DataRead(15)
temp = gCurrentMSB
If gCurrentMSB > 127 Then
lblCorrectedLSB.Caption = (((temp * 256 + gCurrentLSB) And &HFFF8) - 65536) / 8
Else
lblCorrectedLSB.Caption = (((temp * 256 + gCurrentLSB) And &HFFF8)) / 8
End If
ReadBytes 51, 1
CurrentOffsetBias = DataRead(51)
If CurrentOffsetBias > 127 Then
CurrentOffsetBias = CurrentOffsetBias - 256
End If
For i = 7 To 1 Step -1
CurrentArray(i) = CurrentArray(i - 1)
Next i
CurrentArray(0) = Val(lblCorrectedLSB.Caption)
ArrayCount = ArrayCount + 1
If ArrayCount > 7 Then
ArrayCount = 0
AverageCurrent = 0
For i = 0 To 7
AverageCurrent = AverageCurrent + (CurrentArray(i) / 8)
Next i
End If
lblAverageLSB.Caption = Format(AverageCurrent, "#0.000")
If ExternalResistor = True Then
lblOffsetRegister.Caption = Format(CurrentOffsetBias * 0.015625 / SenseResistor, "#0.000") ' in mA
lblCorrectedCurrent.Caption = Format(Val(lblCorrectedLSB.Caption) * 0.015625 / SenseResistor, "#0.000") 'in mA
lblAverageCurrent.Caption = Format(Val(lblAverageLSB.Caption) * 0.015625 / SenseResistor, "#0.000") 'in mA
Else
lblOffsetRegister.Caption = Format(CurrentOffsetBias * 0.625, "#0.000") ' in mA
lblCorrectedCurrent.Caption = Format(Val(lblCorrectedLSB.Caption) * 0.625, "#0.000") 'in mA
lblAverageCurrent.Caption = Format(Val(lblAverageLSB.Caption) * 0.625, "#0.000") 'in mA
End If
End Sub
Private Sub txtOffsetRegister_GotFocus()
txtOffsetRegister.SelStart = 0
txtOffsetRegister.SelLength = Len(txtOffsetRegister.Text)
End Sub
Private Sub txtSenseResistor_GotFocus()
txtSenseResistor.SelStart = 0
txtSenseResistor.SelLength = Len(txtSenseResistor.Text)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -