Other topics about Application Programs
The apl_bsc.vba shows a sample program (VBA program) that demonstrates how to perform the basic measurement of the band-pass filter. This VBA program consists of the following standard module.
Object name |
Module type |
Content |
mdlBscMeas |
Standard module |
Performs basic measurement of band-pass filter |
The sample program performs full 2-port calibration using the 85032F calibration kit, measures a band-pass filter (center frequency: 947.5 MHz), and calculates and displays its bandwidth, insertion loss, and so on. This measurement is the same as Measurement Example of a Bandpass Filter in the Quick Start.
When you run this VBA program, reset is performed, the measurement conditions are automatically set, and the message "Perform the full 2-port calibration" is displayed. To perform the full 2-port calibration, click Yes; otherwise click No.
To perform the calibration, follow the onscreen messages to connect each standard of the Keysight 85032F calibration kit to the specified port, and then click OK to measure the calibration data. Click Cancel to return to the beginning of the calibration. You cannot skip the isolation calibration. When the calibration data measurement for all standards is complete, the message "All calibration data completion" is displayed, and the calibration coefficient is calculated.
When you cancel the calibration data measurement before completing the measurement of necessary calibration data, the settings condition may not be returned to its former state.
Then, the message "Connect DUT, and then press Macro Setup > Continue" is displayed in the instrument status bar in the lower part of the LCD display. Connect a DUT and perform Macro Setup > Continue. After the measurement, the search result is displayed in the echo window, as shown below. If no bandwidth search target is found, only the result of the insertion loss obtained with the marker is displayed.
Example of display after executing the program in "apl_bsc.vba"
The basic measurement program (object name: mdlBscMeas) is described in detail below. Line numbers are added for description purpose only and do not appear in the actual program source code.
Store the sweep center value (947.5 MHz), the sweep span value (200 MHz), the number of measurement points (401), the IF bandwidth (10 kHz), and the power level (-10 dBm) into the variables Center, Span, Nop, IfBw, and Pow, respectively.
Store the number of traces (1), the measurement parameter (S21), the data format (log amplitude), the calibration kit number (4: 85032F), and the save file name (State08.sta) into the variables, NumTrac, Par, Fmt, CalKit, and File, respectively.
Returns the E5071C to the preset state.
For channel 1, turn on the continuous trigger startup mode to On and set the trigger source to the bus trigger.
For channel 1, set the sweep center value to the Center variable, the sweep span value to the Span variable, the number of measurement points to the Nop variable, the IF bandwidth to the IfBw variable, and the power level to the Pow variable.
For channel 1, set the number of traces to the NumTrac variable, the measurement parameter to the Par variable, and the data format to the Fmt variable.
Stores the calibration kit number for channel 1 into the CalKit variable.
Stores 1 and 2 into the Port variable that indicates ports used for the full 2-port calibration.
Calls the Calib_Solt procedure (lines 1200 to 2130).
Save the instrument setting and the calibration coefficient into a file whose name is specified with the File variable.
Displays a message that prompts you to connect a DUT (Device Under Test) in the instrument status bar in the lower part of the LCD display and waits for the operation of Macro Setup > Continue after the connection.
Generate a trigger to start a single sweep and wait until the measurement finishes (1 is read out with the SCPI.IEEE4882.OPC object).
For trace 1 of channel 1, executes auto scale to set the optimum scale.
Display marker 1 and move it so that the stimulus value becomes equal to the value of the Center variable. Then, these lines read out the response value of marker 1 and store it into the MkrVal variable.
Enables the error handling routine starting from Bw_Err (lines 890 to 950). If a runtime error occurs, the program goes to the error handling routine.
Set the bandwidth definition value to -3 dB and the bandwidth search result display to on, read out the bandwidth search result (bandwidth, center frequency, Q value, and insertion loss), and store it into the BwData variable.
Based on the bandwidth search result, these lines store the bandwidth to the Bw variable, the center frequency to the Cent variable, the Q value to the Qfac variable, and the insertion loss to the Loss variable. Then, the program goes to the processing starting from Skip_Bw_Err.
Define a runtime error handler. These lines read out and display the error number and error message of the error that occurred and store 0 to the Bw, Cent, and Qfac variables and the response value of marker 1 (MkrVal(0) variable) to the Loss variable. Then, the program finishes the error handling and proceeds to the next processing.
Calculate the 2 (higher and lower) cutoff frequencies from the values in the Bw and Cent variables and store them into the CutLow and CutHigh variables.
Display the search result (the values of the Bw, Cent, CutLow, CutHigh, Qfac, and Loss variables) in the echo window.
Display the message asking whether you want to perform measurement again. Click Yes to return to the DUT connection section, otherwise click No to terminate the program.
Display the message that prompts for the execution of the full n-port calibration (specified with the SoltType variable). Click Cancel to cancel the calibration.
Set the calibration type to the full n-port calibration for the port specified with the Port variable.
Display the message that prompts for connecting the open standard to the specified port. These lines start the measurement of the open calibration data initiated by clicking OK after the connection and wait for the completion of the measurement. Click Cancel to return to the beginning of the calibration.
Display the message that prompts for connecting the short standard to the specified port. These lines start the measurement of the short calibration data initiated by clicking OK after the connection and wait for the completion of the measurement. Click Cancel to return to the beginning of the calibration.
Display the message that prompts for connecting the load standard to the specified port. These lines start the measurement of the load calibration data initiated by clicking OK after the connection and wait for the completion of the measurement. Click Cancel to return to the beginning of the calibration.
Display the message that prompts for connecting the thru standard between the specified ports. These lines start the measurement of the thru calibration data initiated by clicking OK after the connection and wait for the completion of the measurement. Click Cancel to return to the beginning of the calibration.
When the calibration type is not the 1-port calibration (a value other than 1 is specified for the SoltType variable), displays the message asking you whether you want to measure the isolation calibration data. When Yes is clicked, displays the message that prompts for connecting the load standard to the specified two ports (specified with the Port(I-1) and Port(J-1) variables). These lines start the measurement of the isolation calibration data initiated by clicking OK after the connection and wait for the completion of the measurement. Click Cancel to return to the beginning of the calibration.
Calculate the calibration coefficients from the measured calibration data and turn on the error correction function. Then, these lines display a calibration completion message.
Measuring a band-pass filter (object name: mdlBscMeas)
10| Sub Main()
20|
30| Dim Par As String, Fmt As String, File As String
40| Dim Center As Double, Span As Double, IfBw As Double, Pow As Double
50| Dim Bw As Double, Cent As Double
60| Dim CutLow As Double, CutHigh As Double
70| Dim Qfac As Double, Loss As Double
80| Dim MkrVal As Variant, BwData As Variant
90| Dim Nop As Long, NumTrac As Long, CalKit As Long, Buff As Long
100| Dim Port As Variant, Error As Variant
110|
120| Center = 947500000# 'Center freq : 947.5 MHz
130| Span = 200000000# 'Span freq : 200 MHz
140| Nop = 401 'Number of points : 401
150| IfBw = 10000# 'IF bandwidth : 10 kHz
160| Pow = -10 'Power level : -10dBm
170| NumTrac = 1 'Number of traces : 1
180| Par = "S21" 'Meas. parameter : S21
190| Fmt = "MLOG" 'Data format : Log Mag
200| CalKit = 4 'Calibration kit : 85032F
210| File = "State08.sta" 'Saved file name : State08.sta
220|
230| '''Presetting the E5071C
240|
250| SCPI.SYSTem.PRESet
260|
270| '''Setting measurement conditions
280|
290| SCPI.INITiate(1).CONTinuous = True
300| SCPI.TRIGger.SEQuence.Source = "BUS"
310|
320| SCPI.SENSe(1).FREQuency.Center = Center
330| SCPI.SENSe(1).FREQuency.Span = Span
340| SCPI.SENSe(1).SWEep.POINts = Nop
350| SCPI.SENSe(1).BANDwidth.RESolution = IfBw
360| SCPI.Source(1).POWer.LEVel.IMMediate.AMPLitude = Pow
370|
380| SCPI.CALCulate(1).PARameter.Count = NumTrac
390| SCPI.CALCulate(1).PARameter(1).DEFine = Par
400| SCPI.CALCulate(1).PARameter(1).Select
410| SCPI.CALCulate(1).SELected.Format = Fmt
420|
430| '''Performing full 2-port calibration
440|
450| SCPI.SENSe(1).CORRection.COLLect.CKIT.Select = CalKit
460| Port = Array(1, 2)
470|
480| Calib_Solt 1, 2, Port
490|
500| '''Saving state & cal data
510|
520| SCPI.MMEMory.STORe.STYPe = "CST"
530| SCPI.MMEMory.STORe.STATe = File
540|
550| '''Connecting DUT
560|
570| Meas_Start:
580| Prompt ("Connect DUT, and then press [Macro Setup]-Continue button.")
590|
600| '''Performing single sweep
610|
620| SCPI.TRIGger.SEQuence.SINGle
630| Dmy = SCPI.IEEE4882.OPC
640|
650| SCPI.DISPlay.WINDow(1).TRACe(1).Y.SCALe.AUTO
660|
670| '''Analyzing the results
680|
690| SCPI.CALCulate(1).SELected.MARKer(1).STATe = True
700| SCPI.CALCulate(1).SELected.MARKer(1).X = Center
710| MkrVal = SCPI.CALCulate(1).SELected.MARKer(1).Y
720|
730| On Error GoTo Bw_Err
740|
750| SCPI.CALCulate(1).SELected.MARKer(1).BWIDth.THReshold = -3
760| SCPI.CALCulate(1).SELected.MARKer(1).BWIDth.STATe = True
770| BwData = SCPI.CALCulate(1).SELected.MARKer(1).BWIDth.DATA
780|
790| Bw = BwData(0)
800| Cent = BwData(1)
810| Qfac = BwData(2)
820| Loss = BwData(3)
830|
840| GoTo Skip_Bw_Err
850|
860| Bw_Err:
870|
880| Error = SCPI.SYSTem.Error
890| MsgBox "Error No:" & Error(0) & " , Description:" & Error( 1)
900|
910| Bw = 0
920| Cent = 0
930| Qfac = 0
940| Loss = MkrVal(0)
950|
960| Resume Skip_Bw_Err
970|
980| Skip_Bw_Err:
990|
1000| CutLow = Cent - Bw / 2
1010| CutHigh = Cent + Bw / 2
1020|
1030| ECHO "##Measurement Result##"
1040| ECHO " BW:" & Bw
1050| ECHO "cent:" & Cent
1060| ECHO " low:" & CutLow
1070| ECHO "high:" & CutHigh
1080| ECHO " Q:" & Qfac
1090| ECHO "loss:" & Loss
1100| SCPI.DISPlay.TABLe.TYPE = "ECHO"
1110| SCPI.DISPlay.TABLe.STATe = True
1120|
1130| Buff = MsgBox("Do you make another measurement?", vbYesNo, "Bandpass fileter measurement")
1140| If Buff = vbYes Then
1150| GoTo Meas_Start
1160| End If
1170|
1180| End Sub
1190|
1200| Private Sub Calib_Solt(Chan As Long, SoltType As Long, Port As Variant)
1210|
1220| Dim Dmy As Long, I As Long, J As Long, Buff As Long
1230|
1240| Cal_Start:
1250|
1260| Buff = MsgBox("Perform the full " & SoltType & "-port cali bration.", vbOKCancel, "Full" & SoltType & "-port calibration")
1270|
1280| If Buff = vbCancel Then
1290| GoTo Cal_Skip
1300| End If
1310|
1320| Select Case SoltType
1330| Case 1
1340| SCPI.SENSe(Chan).CORRection.COLLect.METHod.SOLT1 = Port(0)
1350| Case 2
1360| SCPI.SENSe(Chan).CORRection.COLLect.METHod.SOLT2 = Port
1370| Case 3
1380| SCPI.SENSe(Chan).CORRection.COLLect.METHod.SOLT3 = Port
1390| Case 4
1400| SCPI.SENSe(Chan).CORRection.COLLect.METHod.SOLT4 = Port
1410| End Select
1420|
1430| For I = 1 To SoltType
1440|
1450| Buff = MsgBox("Connect the Open standard to Port " & CS tr(Port(I - 1)) & ".", _
1460| vbOKCancel, "Full" & SoltType & "-port calibration")
1470| If Buff = vbOK Then
1480| SCPI.SENSe(Chan).CORRection.COLLect.ACQuire.OPEN = Port(I - 1)
1490| Dmy = SCPI.IEEE4882.OPC
1500| Else
1510| GoTo Cal_Start
1520| End If
1530|
1540| Buff = MsgBox("Connect the Short standard to Port " & CStr(Port(I - 1)) & ".", _
1550| vbOKCancel, "Full" & SoltType & "-port calibration")
1560| If Buff = vbOK Then
1570| SCPI.SENSe(Chan).CORRection.COLLect.ACQuire.Short = Port(I - 1)
1580| Dmy = SCPI.IEEE4882.OPC
1590| Else
1600| GoTo Cal_Start
1610| End If
1620|
1630| Buff = MsgBox("Connect the Load standard to Port " & CStr(Port(I - 1)) & ".", _
1640| vbOKCancel, "Full" & SoltType & "-port calibration")
1650| If Buff = vbOK Then
1660| SCPI.SENSe(Chan).CORRection.COLLect.ACQuire.Load = Port(I - 1)
1670| Dmy = SCPI.IEEE4882.OPC
1680| Else
1690| GoTo Cal_Start
1700| End If
1710| Next I
1720|
1730| For I = 1 To SoltType - 1
1740| For J = I + 1 To SoltType
1750| Buff = MsgBox("Connect the Thru standard between Por t " & CStr(Port(I - 1)) & _
1760| " and Port " & CStr(Port(J - 1)) & ".", vbOKCancel, "Full" & SoltType & "-port calibration")
1770| If Buff = vbOK Then
1780| SCPI.SENSe(Chan).CORRection.COLLect.ACQuire.THRU = Array(Port(I - 1 ), Port(J - 1))
1790| Dmy = SCPI.IEEE4882.OPC
1800| SCPI.SENSe(Chan).CORRection.COLLect.ACQuire.THRU = Array(Port(J - 1 ), Port(I - 1))
1810| Dmy = SCPI.IEEE4882.OPC
1820| Else
1830| GoTo Cal_Start
1840| End If
1850| Next J
1860| Next I
1870|
1880| If SoltType <> 1 Then
1890| Buff = MsgBox("Do you measure the Isolation (Optional) ?", vbYesNo, "Full" & SoltType & "-port calibration")
1900| If Buff = vbYes Then
1910| For I = 1 To SoltType - 1
1920| For J = I + 1 To SoltType
1930| Buff = MsgBox("Connect the Load standard to Port " & Port(I - 1) & " and Port " & Port(J - 1) & ".", _
1940| vbOKCancel, "Full" & Solt Type & "-port calibration")
1950| If Buff = vbOK Then
1960| SCPI.SENSe(Chan).CORRection.COLLect.ACQuire.ISOLation = Array(Port( I - 1), Port(J - 1))
1970| Dmy = SCPI.IEEE4882.OPC
1980| SCPI.SENSe(Chan).CORRection.COLLect.ACQuire.ISOLation = Array(Port( J - 1), Port(I - 1))
1990| Dmy = SCPI.IEEE4882.OPC
2000| Else
2010| GoTo Cal_Start
2020| End If
2030| Next J
2040| Next I
2050| End If
2060| End If
2070|
2080| SCPI.SENSe(1).CORRection.COLLect.SAVE
2090| MsgBox "All calibration data completion."
2100|
2110| Cal_Skip:
2120|
2130| End Sub