DECLARE SUB imaggetiav (imag!, simag!) DECLARE SUB sr770autorange () DECLARE SUB sr770autoscale (trace%) DECLARE SUB sr770getxdata (trace%, spectrum!()) DECLARE SUB sr770getydata (trace%, spectrum!()) DECLARE SUB sr770init () DECLARE SUB sr770pausecont () DECLARE SUB sr770setpar (gpbin%, gpbout%, sr770addr$) DECLARE SUB sr770setupmeas (trace%, meas%, disp%, units%, wndo%) DECLARE SUB SR770GetData () DECLARE SUB SR770menu (selection$) DECLARE SUB gpibin (addr$, msg$) DECLARE SUB gpibout (addr$, cmd$) DECLARE SUB gpibterm (termin$, termout$) '**************************************************************************** 'Module SR770 'This module contains subroutines to control the SR770 FFT Network 'Analyzer. ' 'Zachary Wolf '2/27/96 '**************************************************************************** 'Common area for shared parameters COMMON SHARED /sr770/ gpibinP%, gpiboutP%, sr770addrP$ COMMON SHARED /testinfo/ projectP$, magtypeP$, magnameP$, barcodeP$, teststandP$, coilnameP$, operatorP$, runP%, commentP$, ivalP$ 'Semi-permanent parameters CONST sr770terminP$ = "LF" CONST sr770termoutP$ = "LF" SUB sr770 CALL sr770setpar(gpibinP%, gpiboutP%, sr770addrP$) WHILE selection$ <> "END" CALL SR770menu(selection$) IF selection$ = "Initialize" THEN CALL sr770init IF selection$ = "SetupDisplay" THEN CALL sr770setupmeas(-1, 0, 0, 1, 3) IF selection$ = "AutoScale" THEN CALL sr770autoscale(-1) IF selection$ = "AutoRange" THEN CALL sr770autorange IF selection$ = "PauseContinue" THEN CALL sr770pausecont IF selection$ = "GetData" THEN CALL SR770GetData IF selection$ = "END" THEN EXIT SUB PRINT : PRINT "Enter to continue: "; INPUT resp$ WEND END SUB SUB sr770autorange '**************************************************************************** 'This subroutine performs an autorange on the input of the SR770. ' 'Zachary Wolf '2/27/96 '**************************************************************************** PRINT : PRINT "Auto range the SR770 Spectrum Analyzer" 'Set the GPIB terminators CALL gpibterm(sr770terminP$, sr770termoutP$) 'Autorange CALL gpibout(sr770addrP$, "ARNG1") END SUB SUB sr770autoscale (trace%) '**************************************************************************** 'This subroutine performs an auto scale on a given trace of the SR770. ' 'Input: ' trace%, trace number, 0, 1, or -1 (active trace) ' 'Zachary Wolf '2/27/96 '**************************************************************************** PRINT : PRINT "Auto scale the SR770 Spectrum Analyzer" 'Set the GPIB terminators CALL gpibterm(sr770terminP$, sr770termoutP$) 'Auto Scale CALL gpibout(sr770addrP$, "AUTS" + LTRIM$(STR$(trace%))) END SUB SUB SR770GetData DIM ydata!(0 TO 399), xdata!(0 TO 399) 'Set the SR770 parameters CALL sr770setpar(gpibinP%, gpiboutP%, sr770addrP$) 'Get the power supply setting CALL imaggetiav(imag!, simag!) 'Pause the Spectrum Analyzer (hold) sr770pausecont 'Get the X and Y data from the Spectrum Annalyzer CALL sr770getydata(-1, ydata!()) CALL sr770getxdata(-1, xdata!()) 'Continue the Spectrum Analyzer (active) sr770pausecont 'Output the data to a file runP% = runP% + 1 run$ = LTRIM$(STR$(runP%)) outfile% = FREEFILE fileout$ = "sa.ru" + run$ OPEN fileout$ FOR OUTPUT AS outfile% PRINT #outfile%, "/et g '" + magnameP$ + ": "; imag!; " amps: Flat Top'" PRINT #outfile%, "/et y 'Voltage Amplitude (volts)' " PRINT #outfile%, "/et x 'Frequency (Hz)'" PRINT #outfile%, "/sm OFF" PRINT #outfile%, "/sc ON" PRINT #outfile%, "/sd OFF " PRINT #outfile%, "/ol y on" FOR i% = 0 TO 399 PRINT #outfile%, xdata!(i%); ydata!(i%) NEXT CLOSE outfile% 'Inform user of output PRINT : PRINT "The following file has been created: "; fileout$ END SUB SUB sr770getxdata (trace%, spectrum!()) '**************************************************************************** 'This subroutine gets the 400 data points in the trace of interest from 'the spectrum analyzer. ' 'Input: ' trace%, trace number, 0, 1, or -1 (active trace) ' 'Output: ' spectrum!(0 to 399), array for the data values ' 'Zachary Wolf '2/27/96 '**************************************************************************** 'Message PRINT PRINT "Reading the X-Data from the SR770 FFT Network Analyzer..." 'Set the GPIB terminators CALL gpibterm(sr770terminP$, sr770termoutP$) 'Loop over the data points FOR i% = 0 TO 399 cmd$ = "BVAL?" + LTRIM$(STR$(trace%)) + "," + LTRIM$(STR$(i%)) CALL gpibout(sr770addrP$, cmd$) CALL gpibin(sr770addrP$, value$) spectrum!(i%) = VAL(value$) NEXT i% END SUB SUB sr770getydata (trace%, spectrum!()) '**************************************************************************** 'This subroutine gets the 400 data points in the trace of interest from 'the spectrum analyzer. ' 'Input: ' trace%, trace number, 0, 1, or -1 (active trace) ' 'Output: ' spectrum!(0 to 399), array for the data values ' 'Zachary Wolf '2/27/96 '**************************************************************************** 'Message PRINT PRINT "Reading the Y-Data from the SR770 FFT Network Analyzer..." 'Set the GPIB terminators CALL gpibterm(sr770terminP$, sr770termoutP$) 'Loop over the data points FOR i% = 0 TO 399 cmd$ = "SPEC?" + LTRIM$(STR$(trace%)) + "," + LTRIM$(STR$(i%)) CALL gpibout(sr770addrP$, cmd$) CALL gpibin(sr770addrP$, value$) spectrum!(i%) = VAL(value$) NEXT i% END SUB SUB sr770init '**************************************************************************** 'This subroutine initializes the SR770. ' 'Zachary Wolf '2/27/96 '**************************************************************************** 'Set the GPIB terminators CALL gpibterm(sr770terminP$, sr770termoutP$) 'Message PRINT PRINT "Resetting the SR770 FFT Network Analyzer..." 'Reset the Analyzer CALL gpibout(sr770addrP$, "*RST") SLEEP 2 'Set the output interface to GPIB CALL gpibout(sr770addrP$, "OUTP1") 'Allow the front panel controls to continue to function CALL gpibout(sr770addrP$, "OVRM1") 'Display the instrument ID CALL gpibout(sr770addrP$, "*IDN?") CALL gpibin(sr770addrP$, msg$) PRINT msg$ END SUB SUB SR770menu (selection$) CLS PRINT "SR770 Spectrum Analyzer" PRINT PRINT "Menu selection for operation:" PRINT PRINT "1) Initialize the SR770" PRINT "2) Setup Display" PRINT "3) Auto Scale." PRINT "4) Auto Range." PRINT "5) Pause/Continue" PRINT "6) Get trace data" PRINT "7) Exit from menu." PRINT WHILE sel% < 1 OR sel% > 7 PRINT "Enter SR770 menu selection: "; INPUT sel% WEND IF sel% = 1 THEN selection$ = "Initialize" IF sel% = 2 THEN selection$ = "SetupDisplay" IF sel% = 3 THEN selection$ = "AutoScale" IF sel% = 4 THEN selection$ = "AutoRange" IF sel% = 5 THEN selection$ = "PauseContinue" IF sel% = 6 THEN selection$ = "GetData" IF sel% = 7 THEN selection$ = "END" END SUB SUB sr770pausecont '**************************************************************************** 'This subroutine pauses measurements by the SR770. The next time it is 'called, it continues the measurements. It does the equivalent of toggling 'the pause/continue switch on the front panel. ' 'Zachary Wolf '2/27/96 '**************************************************************************** 'PRINT : PRINT "Pause/Continue the SR770 Spectrum Analyzer" 'Set the GPIB terminators CALL gpibterm(sr770terminP$, sr770termoutP$) 'Pause CALL gpibout(sr770addrP$, "STCO") END SUB SUB sr770setpar (gpbin%, gpbout%, sr770addr$) '**************************************************************************** 'This subroutine initializes the SR770. ' 'Input: ' gpibin%, gpib input file number ' gpibout%, gpib output file number ' sr770addr$, gpib address in a string ' 'Zachary Wolf '2/27/96 '**************************************************************************** 'Make sure the input parameters have reasonable values IF gpbin% < 0 OR gpibn% > 100 THEN PRINT "SR770: GPIB problem" EXIT SUB END IF IF gpbout% < 0 OR gpbout% > 100 THEN PRINT "SR770: GPIB problem" EXIT SUB END IF IF sr770addr$ = "" THEN PRINT "SR770: GPIB problem" EXIT SUB END IF 'Save the GPIB information in a common block for future use gpibinP% = gpbin% gpiboutP% = gpbout% sr770addrP$ = sr770addr$ END SUB SUB sr770setupdisp (atrace%, format%) '**************************************************************************** 'This subroutine sets the display settings for the SR770. ' 'Input: ' atrace%, active trace number, 0, 1 ' format%, integer giving the display format, 0 = single, 1 = up/dwn ' 'Zachary Wolf '2/27/96 '**************************************************************************** 'Set the GPIB terminators CALL gpibterm(sr770terminP$, sr770termoutP$) 'Set the active trace CALL gpibout(sr770addrP$, "ACTG" + LTRIM$(STR$(atrace%))) 'Set the display format CALL gpibout(sr770addrP$, "FMTS" + LTRIM$(STR$(format%))) END SUB SUB sr770setupfreq (span%, startf!) '**************************************************************************** 'This subroutine sets the frequency settings for the SR770. ' 'Input: ' span%, integer giving the span setting, see p. 6-4 of the manual ' startf!, start frequency of the span ' 'Zachary Wolf '2/27/96 '**************************************************************************** 'Set the GPIB terminators CALL gpibterm(sr770terminP$, sr770termoutP$) 'Set the span CALL gpibout(sr770addrP$, "SPAN" + LTRIM$(STR$(span%))) 'Set the start frequency CALL gpibout(sr770addrP$, "STRF" + LTRIM$(STR$(startf!))) END SUB SUB sr770setupinput (config%, gnd%, coupl%, rngdbv%) '**************************************************************************** 'This subroutine sets the scale settings for the SR770. ' 'Input: ' config%, input configuration, 0 = A, 1 = A-B ' gnd%, ground configuration, 0 = float, 1 = ground ' coupl%, input coupling, 0 = AC, 1 = DC ' rngdbv%, input range in dBV, -60 to 34 ' 'Zachary Wolf '2/27/96 '**************************************************************************** 'Set the GPIB terminators CALL gpibterm(sr770terminP$, sr770termoutP$) 'Set the input configuration CALL gpibout(sr770addrP$, "ISRC" + LTRIM$(STR$(config%))) 'Set the input ground configuration CALL gpibout(sr770addrP$, "IGND" + LTRIM$(STR$(gnd%))) 'Set the input coupling CALL gpibout(sr770addrP$, "ICPL" + LTRIM$(STR$(coupl%))) 'Set the input range CALL gpibout(sr770addrP$, "IRNG" + LTRIM$(STR$(rngdbv%))) 'Perform an offset adjustment PRINT PRINT "Performing an input offset calibration..." PRINT "This will take about 10 seconds." CALL gpibout(sr770addrP$, "AOFF") SLEEP 11 'Turn off auto offset CALL gpibout(sr770addrP$, "AOFM0") END SUB SUB sr770setupmeas (trace%, meas%, disp%, units%, wndo%) '**************************************************************************** 'This subroutine sets the measurement settings for the SR770. ' 'Input: ' trace%, trace number, 0, 1, or -1 (active trace) -1 ' meas%, integer giving the measurement type, see p. 6-5 of the manual 0 ' disp%, integer giving the display type, see p. 6-5 of the manual 0 ' units%, integer giving the display units, see p. 6-5 of the manual 1 ' wndo%, integer giving the window type, see p. 6-5 of the manual 3 ' 'Zachary Wolf '2/27/96 '**************************************************************************** 'Set the GPIB terminators CALL gpibterm(sr770terminP$, sr770termoutP$) 'Set the measurement type CALL gpibout(sr770addrP$, "MEAS" + LTRIM$(STR$(trace%)) + "," + LTRIM$(STR$(meas%))) 'Set the display type CALL gpibout(sr770addrP$, "DISP" + LTRIM$(STR$(trace%)) + "," + LTRIM$(STR$(disp%))) 'Set the units CALL gpibout(sr770addrP$, "UNIT" + LTRIM$(STR$(trace%)) + "," + LTRIM$(STR$(units%))) 'Set the window type CALL gpibout(sr770addrP$, "WNDO" + LTRIM$(STR$(trace%)) + "," + LTRIM$(STR$(wndo%))) END SUB SUB sr770setupscale (trace%, yperdiv!, topval!) '**************************************************************************** 'This subroutine sets the scale settings for the SR770. ' 'Input: ' trace%, trace number, 0, 1, or -1 (active trace) ' yperdiv!, vertical scale units per division ' topval!, vertical scale top value ' 'Zachary Wolf '2/27/96 '**************************************************************************** 'Set the GPIB terminators CALL gpibterm(sr770terminP$, sr770termoutP$) 'Set the Y units per division CALL gpibout(sr770addrP$, "YDIV" + LTRIM$(STR$(trace%)) + "," + LTRIM$(STR$(yperdiv!))) 'Set the upper value of the Y scale CALL gpibout(sr770addrP$, "TREF" + LTRIM$(STR$(trace%)) + "," + LTRIM$(STR$(topval!))) END SUB