📄 form10.frm
字号:
Text = "227.291456615078992"
Top = 1200
Width = 2175
End
Begin VB.Label Label1
Caption = "Ohms"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 255
Left = 2520
TabIndex = 18
Top = 1320
Width = 735
End
Begin VB.Label Label2
Caption = "AD5933 Rout"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 255
Left = 240
TabIndex = 4
Top = 960
Width = 1335
End
End
End
Attribute VB_Name = "Form10"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Form10.Visible = False ' hide the cal form
Form1.Visible = True ' return to the main form
End Sub
Public Function phase2(ByVal img As Double, ByVal real As Double) _
As Double
Dim theta As Double
Dim pi As Double
pi = 3.141592654
If ((real > 0) And (img > 0)) Then
theta = Atn(img / real) ' theta = arctan (imaginary part/real part)
phase2 = (theta * 180) / pi 'convert to degrees
ElseIf ((real > 0) And (img < 0)) Then
theta = Atn(img / real) 'fourth quadrant theta = minus angle
phase2 = ((theta * 180) / pi) + 360
ElseIf ((real < 0) And (img < 0)) Then
theta = -pi + Atn(img / real) '3rd quadrant img/real is positive
phase2 = (theta * 180) / pi
ElseIf ((real < 0) And (img > 0)) Then
theta = pi + Atn(img / real) '2nd quadrant img/real is neg
phase2 = (theta * 180) / pi
End If
End Function
Private Sub Command2_click()
On Error GoTo sweepErrorMsg
Dim ReadbackStatusRegister As Long
Dim RealData As Double
Dim RealDataUpper As Long
Dim RealDataLower As Long
Dim ImagineryData As Double
Dim ImagineryDataLower As Long
Dim ImagineryDataUpper As Long
Dim Magnitude As Double
Dim Impedance As Double
Dim MaxMagnitude As Double
Dim MinMagnitude As Double
Dim sweep_phase As Double
Dim Frequency As Double
Dim Increment As Long ' number of increments
Dim i As Integer
Dim xy As Variant
Dim varray As Variant
IndexArray = 0
Increment = NumberIncrements + 1 ' number of increments in the sweep
Frequency = StartFrequency ' the sweep starts from here
' Enter normal mode
EnterStandbyMode
UpdateStartFrequency
UpdateNumberIncrements
UpdateFrequencyIncrement
UpdateSettlingTime
'----------------------------- systemn clock ---------------------
If (Form1.ExternalClock.Value = True) Then
' Enable external Oscillator
WritetToControlRegister2 &H81, &H8
Else
' Enable internal Oscillator
WritetToControlRegister2 &H81, &H0
End If
'----------------------------initialise sensor----------------------
' Initialise Sensor with Start Frequency
WritetToControlRegister &H80, &H10
msDelay 2 'this is user determined
'------------------------start the frequency sweep-------------------
' Start Frequency Sweep
WritetToControlRegister &H80, &H20
'--------------------------------------------------------------------
' Enter Frequency Sweep Loop
ReadbackStatusRegister = PortRead(&HD, &H8F)
ReadbackStatusRegister = ReadbackStatusRegister And &H4 ' mask off bit D2
Do While ((ReadbackStatusRegister <> 4) And (Increment <> 0))
' check to see if current sweep point complete
ReadbackStatusRegister = PortRead(&HD, &H8F)
ReadbackStatusRegister = ReadbackStatusRegister And &H2 ' mask off bit D1
'------------------------------------------------------------------------
If (ReadbackStatusRegister = 2) Then
' this sweep point has returned valid data so we can proceed with sweep
Else
Do
'if valid data has not been returned then we need to pole stat reg until such time as valid data
'has been returned
'i.e. if point is not complete then Repeat sweep point and pole staus reg until valid data returned
WritetToControlRegister &H80, &H40 'repeat sweep point
Do
ReadbackStatusRegister = PortRead(&HD, &H8F)
ReadbackStatusRegister = ReadbackStatusRegister And &H2 ' mask off bit D1- Wait until dft complete
Loop While (ReadbackStatusRegister <> 2)
Loop Until (ReadbackStatusRegister = 2)
End If
'-------------------------------------------------------------------------
RealDataUpper = PortRead(&HD, &H94)
RealDataLower = PortRead(&HD, &H95)
RealData = RealDataLower + (RealDataUpper * 256)
If RealData < &H7FFF Then ' h7fff 32767
' Positive
Else
' Negative
RealData = RealData And &H7FFF
RealData = RealData - &H7FFF
End If
ImagineryDataUpper = PortRead(&HD, &H96)
ImagineryDataLower = PortRead(&HD, &H97)
ImagineryData = ImagineryDataLower + (ImagineryDataUpper * 256)
If ImagineryData < &H7FFF Then
' Positive Data.
Else
' Negative
ImagineryData = ImagineryData And &H7FFF
ImagineryData = ImagineryData - &H7FFF
End If
Magnitude = ((RealData ^ 2) + (ImagineryData ^ 2)) ^ 0.5
' If (Form1.Option7.Value = True And Form1.Option8.Value = False) Then
' ' mid point cal
' sweep_phase = -(calibration_phase_mid_point - phase2(ImagineryData, RealData))
' GainFactor = Val(Text5.Text)
' Impedance = 1 / (Magnitude * GainFactor)
'
' End If
' If (Form1.Option7.Value = False And Form1.Option8.Value = True) Then
' ' multipoint cal
' sweep_phase = -(calibration_phase_multi_point(IndexArray) - phase2(ImagineryData, RealData))
' GainFactor = calibration_GainFactors(IndexArray)
' Impedance = 1 / (Magnitude * GainFactor)
' End If
' Write Data to each array.
' MagnitudeArray(IndexArray) = Impedance
' PhaseArray(IndexArray) = sweep_phase
' ImagineryDataArray(IndexArray) = ImagineryData
code(IndexArray) = Magnitude
' RealDataArray(IndexArray) = RealData
Increment = Increment - 1 ' incremet was set to number of increments of sweep at the start
' FrequencyPoints(IndexArray) = Frequency
Frequency = Frequency + FrequencyIncrements ' holds the current value of the sweep freq
IndexArray = IndexArray + 1
'------------- Check to see if sweep complete ----------------------
ReadbackStatusRegister = PortRead(&HD, &H8F)
ReadbackStatusRegister = ReadbackStatusRegister And &H4 ' mask off bit D2
' Increment to next frequency point Frequency
WritetToControlRegister &H80, &H30
Loop
'--- the sweep is complete at this point now we plot the data --------------
'Calculate the average impedance
Average_impedance = code(0)
Sum_impedance = 0
For i = 0 To NumberIncrements
Sum_impedance = Sum_impedance + code(i)
Next i
Average_impedance = Sum_impedance / NumberIncrements
Sum_impedance = 0
'----------------------------------------------------------------------------
Text9.Text = Average_impedance
Average_impedance = 0
MsgBox " sweep complete "
Command3.Enabled = True
Exit Sub
sweepErrorMsg:
MsgBox "Error completing Calibration sweep check values"
End Sub
Private Sub Command3_Click()
On Error GoTo sweepErrorMsg2
Dim ReadbackStatusRegister As Long
Dim RealData As Double
Dim RealDataUpper As Long
Dim RealDataLower As Long
Dim ImagineryData As Double
Dim ImagineryDataLower As Long
Dim ImagineryDataUpper As Long
Dim Magnitude As Double
Dim Impedance As Double
Dim MaxMagnitude As Double
Dim MinMagnitude As Double
Dim sweep_phase As Double
Dim Frequency As Double
Dim Increment As Long ' number of increments
Dim i As Integer
Dim xy As Variant
Dim varray As Variant
IndexArray = 0
Increment = NumberIncrements + 1 ' number of increments in the sweep
Frequency = StartFrequency ' the sweep starts from here
' Enter normal mode
EnterStandbyMode
UpdateStartFrequency
UpdateNumberIncrements
UpdateFrequencyIncrement
UpdateSettlingTime
'----------------------------- systemn clock ---------------------
If (Form1.ExternalClock.Value = True) Then
' Enable external Oscillator
WritetToControlRegister2 &H81, &H8
Else
' Enable internal Oscillator
WritetToControlRegister2 &H81, &H0
End If
'----------------------------initialise sensor----------------------
' Initialise Sensor with Start Frequency
WritetToControlRegister &H80, &H10
msDelay 2 'this is user determined
'------------------------start the frequency sweep-------------------
' Start Frequency Sweep
WritetToControlRegister &H80, &H20
'--------------------------------------------------------------------
' Enter Frequency Sweep Loop
ReadbackStatusRegister = PortRead(&HD, &H8F)
ReadbackStatusRegister = ReadbackStatusRegister And &H4 ' mask off bit D2
Do While ((ReadbackStatusRegister <> 4) And (Increment <> 0))
' check to see if current sweep point complete
ReadbackStatusRegister = PortRead(&HD, &H8F)
ReadbackStatusRegister = ReadbackStatusRegister And &H2 ' mask off bit D1
'------------------------------------------------------------------------
If (ReadbackStatusRegister = 2) Then
' this sweep point has returned valid data so we can proceed with sweep
Else
Do
'if valid data has not been returned then we need to pole stat reg until such time as valid data
'has been returned
'i.e. if point is not complete then Repeat sweep point and pole staus reg until valid data returned
WritetToControlRegister &H80, &H40 'repeat sweep point
Do
ReadbackStatusRegister = PortRead(&HD, &H8F)
ReadbackStatusRegister = ReadbackStatusRegister And &H2 ' mask off bit D1- Wait until dft complete
Loop While (ReadbackStatusRegister <> 2)
Loop Until (ReadbackStatusRegister = 2)
End If
'-------------------------------------------------------------------------
RealDataUpper = PortRead(&HD, &H94)
RealDataLower = PortRead(&HD, &H95)
RealData = RealDataLower + (RealDataUpper * 256)
If RealData < &H7FFF Then ' h7fff 32767
' Positive
Else
' Negative
RealData = RealData And &H7FFF
RealData = RealData - &H7FFF
End If
ImagineryDataUpper = PortRead(&HD, &H96)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -