Executing Power Calibration

Other topics about Application Programs

Overview

The pow_cal.vba shows a sample program (VBA program) for executing power calibration using the E4418B power meter and the E4412A power sensor. This VBA program consists of the following modules:

Object name

Module type

Description

mdlPowCal

Standard module

Executes power calibration

Module1
Module2

Standard module

Definition files for using VISA library

Program Overview

The program connects the E5071C and the E4418B (GPIB address: 13) through the USB/GPIB interface as shown below. Then, the program executes the zero adjustment and calibration of the power sensor (E4412A) connected to the power meter (E4418B) as necessary. Finally, it executes the power calibration of the E5071C and saves the obtained power calibration data array into a file.

Connection between E5071C and power meter

 

Program Description

When you run this VBA program, reset is performed, the GPIB address of the power meter to be controlled and the measurement conditions of the E5071C are set, and the message "Do you want to zero and calibrate the power sensor?" is displayed. If you want to execute the zero adjustment and the calibration of the power sensor, click Yes, otherwise click No.

If you want to execute the zero adjustment and calibration of the power sensor, follow the displayed messages to connect the power sensor connected to the A channel of the power meter to the POWER RF port of the power meter and click OK. When the zero adjustment and calibration of the power sensor is complete, the message "Zeroing and calibrating the power sensor is complete" is displayed.

When a message that prompts you to connect the power sensor to port 1 of the E5071C is displayed, make the connection and then click OK. The power calibration data measurement is executed immediately and the obtained power calibration data array is saved in a file named CORR_DATA.

The power calibration execution program (object name: mdlPowCal) is described in detail below. Line numbers are added for description purpose only and do not appear in the actual program source code.

Lines 100 to 150

Assign the sweep type (power sweep), the number of points (41), the power range (-20 to +12 dBm), the sweep start value (-20 dBm), the sweep stop value (-10 dBm), and the fixed frequency (1 GHz) to the Swp_type, Nop, Pow_rang, Start_p, Stop_p, and Cw_freq variables, respectively.

Lines 160 to 170

Assign the number of power calibration data measurements for each measurement point (4) and the limit value of the power calibration data array (10 dBm) into the Num_avg and Limit variables, respectively.

Line 200

Returns the E5071C to the preset state.

Line 230

Sets the power meter's GPIB address (13) in the E5071C.

Lines 260 to 310

For channel 1, these lines assign the sweep type to the Swp_type variable, the number of points to the Nop variable, the power range to the Pow_rang variable, the sweep start value to the Start_p variable, the sweep stop value to the Stop_p variable, and the fixed frequency to the Cw_freq variable.

Lines 340 to 370

Display a message asking whether to execute the zero adjustment and calibration of the power sensor. If the Yes button is clicked, these lines call the procedure: Control_PowerMeter (Line 900 to Line 1340). On the other hand, if the No button is clicked, the program skips the zero adjustment and calibration of the power sensor.

Lines 410 to 420

Clear the error queue. Then, these lines prompt you to connect the power sensor to port 1 of the E5071C and wait for the OK button to be clicked after the connection.

Lines 450 to 470

For port 1 of channel 1, these lines set the number of power calibration data measurements for each measurement point to the Num_avg variable and then start the measurement of the power calibration data and wait for the completion of the measurement.

Line 500

Reads out an error that has occurred in the E5071C during the measurement of the power calibration data and sets it in the Err variable.

Lines 510 to 590

If no error has occurred, these lines read out the power calibration data array and set it in the Corr_data variable. In addition, the program uses the Limit_Test function to check whether the read out power calibration data array exceeds the specified limit value. If the limit value is exceeded, the return value of the Limit_Test function, False, is returned. Then, a message is displayed asking whether to perform the power calibration again. Click the Yes button to return to the start of the power calibration data measurement. Click the No button to terminate the program.

Lines 610 to 660

If an error occurs, display an error message and a message asking whether to execute the power calibration again. Click the Yes button to return to the start of the power calibration data measurement. Click the No button to terminate the program.

Lines 690 to 790

Write the read out power calibration data array into a file named CORR_DATA. Then, these lines display a message that saving into a file has been successfully completed.

Procedure: Control_PowerMeter (lines 900 to 1340)

Lines 990 to 1000

Initialize and start up the VISA system and output the startup information to the Defrm variable. During this process, if an error occurs, the program goes to the error handling routine (Lines 1260 to 1300).

Lines 1030 to 1040

Establish the connection to the power meter in use (GPIB address: 13) and output the connection information to the E4418 variable. During this process, if an error occurs, the program goes to the error handling routine (Lines 1260 to 1300).

Lines 1070 to 1090

Return the power meter to the preset state through VISA and clear the status byte register and the standard event status register. Then, these lines enable the standard event status register's bit 0.

Line 1100

Prompts you to connect the power sensor to the POWER REF port of the power meter and waits for the OK button to be clicked after the connection.

Lines 1110 to 1120

Execute the zero adjustment and calibration of the power sensor through VISA. These lines make the setting so that 1 is set to bit 0 of the standard event status register when all pending operations are completed.

Lines 1130 to 1190

Retrieve the value of the status byte register through VISA and set it into the Rgst variable. These lines set the AND of the read-out value and 32 (the value in which only bit 5 is 1) into the Rslt variable and display a message that the zero adjustment and calibration of the power sensor is completed when Rslt becomes 1 (when the zero adjustment and calibration of the power sensor is completed).

Line 1220

Breaks the communication and terminates the VISA system.

Lines 1260 to 1300

If an error occurs in a VISA function, these lines display the details of the error and terminate the program.

Function: Limit_Test (Lines 1360 to 1530)

Lines 1420 to 1470

If the absolute value of the read out power calibration data array exceeds the specified limit value, these lines turn off the power calibration function and return the value of False. Otherwise, the value of True is returned.

 Measurement of power calibration (object name: mdlPowCal)

10| Sub Main()

20|

30| Dim Swp_type As String, File As String

40| Dim Start_p As Double, Stop_p As Double, Cw_freq As Double, Limi t As Double

50| Dim Nop As Long, Pow_rang As Long, Num_avg As Long, Data_size As Long, Buff As Long, Dmy As Long

60| Dim Corr_data As Variant, Err As Variant

70| Dim Verifier As Boolean

80| Dim FileNo As Integer, I As Integer

90|

100| Swp_type = "POW" 'Sweep type : POWER

110| Nop = 41 'Number of points : 41

120| Pow_rang = 0 'Power range : -20 to +12 dBm

130| Start_p = -20# 'Start power : -20 dBm

140| Stop_p = -10# 'Stop power : -10 dBm

150| Cw_freq = 1000000000# 'CW frequency : 1 GHz

160| Num_avg = 4 'Number of averaging : 4

170| Limit = 10# 'limit for corrected data : 10 dBm

180|

190| '''Presetting the ENA

200| SCPI.SYSTem.PRESet

210|

220| '''Setting GPIB address of the power meter to ENA

230| SCPI.SYSTem.COMMunicate.GPIB.PMETer.address = 13

240|

250| '''Setting measurement conditions

260| SCPI.SENSe(1).SWEep.TYPE = Swp_type

270| SCPI.SENSe(1).SWEep.POINts = Nop

280| SCPI.Source(1).POWer.ATTenuation.DATA = Pow_rang

290| SCPI.Source(1).POWer.STARt = Start_p

300| SCPI.Source(1).POWer.STOP = Stop_p

310| SCPI.SENSe(1).FREQuency.CW = Cw_freq

320|

330| '''Performing a calibration in the power meter

340| Buff = MsgBox("Do you perform zeroing and calibrating the power sensor?", vbYesNo, "Power meter calibration")

350| If Buff = vbYes Then

360| Control_PowerMeter

370| End If

380|

390| Meas_Start:

400| '''Connecting the power sensor to the port 1 in the ENA

410| SCPI.IEEE4882.CLS

420| MsgBox "Set the power sensor connected to the port 1 in the ENA.", vbOKOnly, "Power meter calibration"

430|

440| '''Performing power calibration measurement

450| SCPI.Source(1).POWer.PORT(1).CORRection.COLLect.AVERage.count = Num_avg

460| SCPI.Source(1).POWer.PORT(1).CORRection.COLLect.ACQuire = "ASEN "

470| Dmy = SCPI.IEEE4882.OPC

480|

490| '''Error handling at power meter calibration

500| Err = SCPI.SYSTem.Error

510| If Err(0) = 0 Then

520| Corr_data = SCPI.Source(1).POWer.PORT(1).CORRection.DATA

530| Verifier = Limit_Test(Nop, Limit, Corr_data)

540| If Verifier = False Then

550| Buff = MsgBox("Do you perform the power meter calibration me asurement again?", vbYesNo, "Power meter calibration")

560| If Buff = vbYes Then GoTo Meas_Start

570| If Buff = vbNo Then GoTo Prog_Stop

580| End If

590| MsgBox "Power meter calibration measurement is complete.", vbO KOnly, "Power meter calibration"

600|

610| Else

620| MsgBox "Error: " & Err(1)

630| Buff = MsgBox("Do you perform the power meter calibration meas urement again?", vbYesNo, "Power meter calibration")

640| If Buff = vbYes Then GoTo Meas_Start

650| If Buff = vbNo Then GoTo Prog_Stop

660| End If

670|

680| '''Installing the corrected data to a file

690| FileNo = FreeFile

700| File = "CORR_DATA"

710|

720| Open File For Output As FileNo

730|

740| For I = 0 To Nop - 1

750| Write #FileNo, Val(Corr_data(I))

760| Next I

770| Close #FileNo

780|

790| MsgBox "Installing the corrected data to the file is DONE.", vbO KOnly, "Power meter calibration"

800|

810| GoTo Prog_End

820|

830| Prog_Stop:

840| MsgBox "Program Interruption", vbOKOnly, "Power meter calibratio n"

850|

860| Prog_End:

870|

880| End Sub

890|

900| Private Sub Control_PowerMeter()

910|

920| Dim Status As Long 'VISA function status return

930| Dim Defrm As Long 'Session to default resource code

940| Dim E4418 As Long 'Session to power meter

950| Dim Rslt As Integer

960| Dim Rgst As String * 10

970|

980| '''Initializing the VISA system

990| Status = viOpenDefaultRM(Defrm)

1000| If (Status <> VI_SUCCESS) Then GoTo VisaErrorHandler

1010|

1020| '''Opening the session to the power meter

1030| Status = viOpen(Defrm, "GPIB0::13::INSTR", 0, 0, E4418)

1040| If (Status <> VI_SUCCESS) Then GoTo VisaErrorHandler

1050|

1060| '''Zeroing and calibratingthe power meter

1070| Status = viVPrintf(E4418, "SYST:PRES" & Chr$(10), 0)

1080| Status = viVPrintf(E4418, "*CLS" & Chr$(10), 0)

1090| Status = viVPrintf(E4418, "*ESE 1" & Chr$(10), 0)

1100| MsgBox "Set the power sensor connected to the POWER REF port in the power meter.", vbOKOnly, "Power meter calibration"

1110| Status = viVPrintf(E4418, "CAL1:ALL" & Chr$(10), 0)

1120| Status = viVPrintf(E4418, "*OPC" & Chr$(10), 0)

1130| Do While Rslt = 0

1140| Status = viVPrintf(E4418, "*STB?" & Chr$(10), 0)

1150| Status = viVScanf(E4418, "%t", Rgst)

1160| Rslt = CInt(CInt(Rgst) And 32)

1170| Loop

1180|

1190| MsgBox "Zeroing and Calibrating the power sensor is complete.", vbOKOnly, "Power meter calibration"

1200|

1210| '''Closing the resource manager session

1220| Call viClose(Defrm)

1230|

1240| GoTo Prog_End

1250|

1260| VisaErrorHandler:

1270| Dim VisaErr As String * 200

1280| Call viStatusDesc(Defrm, Status, VisaErr)

1290| MsgBox "Error : " & VisaErr, vbExclamation

1300| End

1310|

1320| Prog_End:

1330|

1340| End Sub

1350|

1360| Function Limit_Test(Nop As Long, Limit As Double, Corr_data As Var iant) As Boolean

1370|

1380| Dim I As Integer

1390|

1400| For I = 0 To Nop - 1

1410|

1420| If Abs(Corr_data(I)) > Limit Then

1430| SCPI.Source(1).POWer.PORT(1).CORRection.STATe = False

1440| MsgBox "The corrected data is out of limit!", vbExclamation, "Power meter calibration"

1450| Limit_Test = False

1460| Exit Function

1470| End If

1480|

1490| Next I

1500|

1510| Limit_Test = True

1520|

1530| End Function