'spectrumanalyzer.bas: version 111 7-27-08: (Previous version 110) 'for Original MSA and SLIM MSA, Tracking Generator, and VNA '[EstablishUserVariables] 'all of the following are "default" values and are dependent on the construction of your Spectrum Analyzer masterclock = 64 'enter the exact frequency of the Master Clock (in MHz). Example: 64.000056 or 63.999937 'if exact frequency is unknown, enter the nominal value of Master Clock. Example: 64. You can chage it when calibrating. centfreq = 0 'enter the default center frequency, in MHz. For initial set-up use "0" sweepwidth = .04 'enter the default sweep width, in MHz. For initial set-up use 10 times the BW of Final Xtal Filter wate = 0 'value to "slow" the sweep speed for more accurate data. Use "0" as default. glitchtime = 0 'default=0. "glitchtime" x value in "Wait" box = 1 msec. In my Toshiba, "80" delays data taking by 1 msec.ver111-27 steps = 400 'whole number of steps per sweep. 1 thru 720 is acceptable. 400 is a good number. marker1 = 100 'marker 1 step placement, default. A marker will be placed on the graph, at this step number marker2 = 200 'marker 2 step placement, default. If no markers are wanted, enter the value, 750, in each marker default marker3 = 300 'marker 3 step placement, default. If the value is greater than "steps", no marker will display adconv = 16 'AtoD topology."8" for original 8 bit,"12" for optional 12 bit ladder,"16" for serial 16 bit AtoD, or "22" for serial 12 bit AtoD ver111-36e topref = 0 'default, top magnitude reference line on scale, in dBm input to MSA. For initial set-up, use "0" botref = -100 'default, bottom magnitude reference line on scale, in dBm input to MSA. For initial set-up, use "-100" finalfreq1 = 10.7 'freq of Final Xtal Filter # 1, in MHz finalbw1 = 4.0 'BW (in KHz)of Final Xtal Filter # 1 finalfreq2 = 10.7 'freq of Final Xtal Filter # 2, in MHz. If only Final Xtal Filter # 1 is used, enter duplicate values. finalbw2 = 10 'BW (in KHz)of Final Xtal Filter # 2 finalfreq3 = 10.7 'freq of Final Xtal Filter # 3, in MHz finalbw3 = 30 'BW (in KHz)of Final Xtal Filter # 3 finalfreq4 = 10.7 'freq of Final Xtal Filter # 4, in MHz finalbw4 = 200 'BW (in KHz)of Final Xtal Filter # 4 cb = 2 '0= old Control Board, 1= old Control Board with new harness, 2 = SLIM Control Board ver111-22 dds1parser = 1 '0 if DDS 1 is commanded in parallel mode, 1 if serial commanding 'ver111-21."0" not allowed on SLIM Control Board ver111-29 appxdds1 = 10.695 '10.7 'this is the nominal DDS1 output frequency (in MHz) that steers PLL 1, must be the center freq. of DDS1 xtal filter dds1filbw = .015 'this is the DDS1 xtal filter bandwidth (in MHz, at the 3 dB points) PLL1 = 2326 'enter PLL #: ie. 2325, 2326, 2350, 2353, or 4112 PLL1phasefreq = .974 'approximate Phase Detector Frequency (MHz) for PLL 1. Use .974 when DDS1 filter is 15 KHz wide 'PLL1phasefreq must be less than the following formula: PLL1phasefreq < (VCO 1 minimum frequency) x dds1filbw/appxdds1 PLL1mode = 0 '0 = Integer Mode, 1 = Fractional Mode for PLL 1. I don't recommend Fractional Mode for PLL 1, although it will work (noiser) PLL1phasepolarity = 0 'for non-inverting loop filter, enter 1; for inverting op amp, enter 0(SLIM MSA) PLL2 = 2326 'enter PLL #: 2325, 2326, 2350, 2353, 4112, or 0 for SRD multiplier appxLO2 = 1024 '2nd LO frequency (MHz). 1024 is nominal, Must be a whole number multiple of "PLL2phasefreq" PLL2phasefreq = 4 'PLL2 phase frequency (MHz). This must be a numerical sub-multiple of "appxLO2". 4 is nominal PLL2phasepolarity = 1 'for non-inverting loop filter, enter 1(SLIM MSA); for inverting op amp, enter 0 TGtop = 2 'Tracking Generator Topology:"0" for not installed, "1" for original Trk Gen, "2" for New TG (DDS3/PLL3 combination) ver111-18 PLL3 = 2326 'enter PLL #: 2325, 2326, 2350, 2353, 4112. Enter "0" (zero) for no Tracking Generator. 2350 and 2353 can be used as fractional-N appxdds3 = 10.695 '10.7 'Nominal DDS3 output frequency (in MHz) that steers PLL 3 (center freq of DDS 3 filter) 'Enter "0" if TGtop = 0(no TG) or 1. The original Trk Gen does not use a DDS3. ver111-17 'If no Tracking Generator is installed, do not change the following 8 global variables. dds3filbw = .015 'this is the DDS3 xtal filter bandwidth (3 dB points), in MHz PLL3phasepolarity = 0 'enter 1 for non-inverting loop filter; for inverting op amp, enter 0(SLIM MSA) PLL3mode = 0 '0 = Integer Mode, 1 = Fractional Mode for PLL 3. Enter "1" only if PLL3 = 2350 or 2353. Enter "0" for new DDS3/PLL3 combination (SLIM MSA). PLL3phasefreq = .974 'TrkGen PLL3 phase frequency (MHz). If TG is DDS3/PLL3 combo, use same technique as PLL1phasefreq 'if Original TG (TGtop=1) then this must be a sub-multiple of both Master Clock and Final Xtal Filter Frequency sgpreset = 10 '(in MHz)Default Output freq of Tracking Generator when in Signal Generator Mode offset = 0 'Enter "0" (Mhz). Default Tracking Generator frequency output, relative to MSA input. ver111-18 maxpdmout = 65535 'bit count for Phase AtoD converter when Phase Det Module output is maximum. invdeg = 169.89 'actual phase change when PDM is inverted. Nominally, 180. Enter actual value after calibration. 'The calibration tables are at the end of the code. Their default values may need changing. '--Normally, nothing else, below this line will ever need changing---------- '[EstablishHardVariables]'used when my recommended Control Board is the interface x = 720 'graph horizontal is 720 pixels in width(x), for 800x600 pixel monitor y = 300 'graph vertical is 300 pixels in amplitude(y) windowwide = 800 'Working and Graph Windows are 800 pixels wide maxscale = 255 'height of Log Scale, in pixels, must be less than y windowhigh = 185 'Working Window is 180 pixels in height graphhigh = 415 'Graph Window is 415 pixels in height finalfreq = finalfreq1 'default freq for the last filter center freq using finalfreq1 finalbw = finalbw1 'default bw for the last filter center freq using finalbw1 'the following lines of code are operations and will not be changed by the user unless 'a different type of Control Board is used. port = hexdec("&H378") 'LPT printer port, data address for most computers status = hexdec("&H379") 'LPT printer port, status address for most computers control = hexdec("&H37A") 'LPT printer port, control address for most computers contclear = 11 'global to take all LPT control lines low STRB = 10 'global to take LPT-pin 1 high. (Strobe line,STRB)(was fqud) ver111-22 AUTO = 9 'global to take LPT-pin 14 high. (Auto Feed line,AUTO)(was wclk) ver111-22 INIT = 15 'global to take LPT-pin 16 high. (Init Printer line,INIT)(was enat) ver111-22 SELT = 3 'global to take LPT-pin 17 high. (Select In line,SELT)(was enap) ver111-22 INITSELT = 7 'global to take both LPT-pins 16 & 17 high. (INIT,SELT)(was enapt) ver111-22 STRBAUTO = 8 'global to take both LPT-pins 1 & 14 high. (FQUD,WCLK)(was wclkfqud) ver111-22 dim datatable(800,3) 'data from most current sweep, (0)thisstep,(1)thisfreq,(2)magpower,(3)phaseofpdm dim magarray(800,3) 'magni pixels for each step#: (0)thispointx, (1)oldmagpixel,(2)thispointmag(3)magdata dim phaarray(800,4) '(0)pdmcmd; phase pixels for each step#:(1)oldphapixel,(2)thispointphase,(3)phadata,(4)pdmread ver111-39d dim calarray(800,2) 'calibration data for each step#: (0)notused,(1)magpower during cal,(2)phaseofpdm during cal dim PLL1array(800,48) '(0-23)N23thruN0,(24-39)notused,(40)pdf1,(43)LO1freq,(45)ncounter,(46)Fcounter,(47)Acounter,(48)Bcounter. ver111-30a dim PLL3array(800,48) '(0-23)N23thruN0,(24-39)notused,(40)pdf3,(43)LO3freq,(45)ncounter,(46)Fcounter,(47)Acounter,(48)Bcounter. ver111-30a dim DDS1array(800,46) '(0-39)sw0-sw39,(40-44)w0-w4,(45)base,(46)actualdds1output dim DDS3array(800,46) '(0-39)sw0-sw39,(40-44)w0-w4,(45)base,(46)actualdds3output dim cmdallarray(800,39) '(0-15)DDS1+DDS3, (16-39)PLL1+DDS1+PLL3+DDS3 if cb=0 then le1=4:le2=8:le3=16:fqud1=STRB:fqud3=2 'ver111-31b if cb=1 then le1=1:le2=1:le3=4:fqud1=2:fqud3=8 'ver111-31b if cb=2 then le1=1:le2=16:le3=4:fqud1=2:fqud3=8 'ver111-31b if adconv = 8 then pdmlowlim = 51 : pdmhighlim = 205 'establish boundries for 8 bit parallel A to D ver111-36f if adconv = 12 then pdmlowlim = 819 : pdmhighlim = 3277 'establish boundries for 12 bit parallel A to D ver111-36f if adconv = 16 then pdmlowlim = 13107 : pdmhighlim = 52429 'establish boundries for 16 bit serial A to D ver111-36f if adconv = 22 then pdmlowlim = 819 : pdmhighlim = 3277 'establish boundries for 12 bit serial A to D ver111-37a nomainwin 'Index of Routines for Original MSA or Slim MSA '1. Create the Working Window and install the Default Global Variables. Assume 400 sweep steps (#0-#400) '2. Initialize all circuits. Reset the DDS's and initialize the PLL's. Set Filters to path 1 '3. Read the Variables in the Working Window '4. Create the Graph Window, using the Variables from the Working Window '5. Calculate the command information for step #0 through step #400 of the sweep and put in arrays '6. (Start), reset step to "0" and clear computer display buffers '7. (command step), command relevant Control Board and modules sequentially or concurrently '8. (DetermineNextOperation),Determine what to do next '9. [IncrementOneStep] add 1 to thisstep, then goto (Start)or goto (command step) '10.[Halted] wait for operator '1. [SetUpWorkingWindow] Create the Working Window, using global variables gosub [createWorkingWindow] 'create Working Window for MSA using global default values 'Determine speed of computer 'ver111-37c if glitchtime = 0 then gosub [AutoGlitchtime] 'ver111-37c 'return with glitchtime, number approximates 1 millisecond of computer processing speed for Liberty print #main.msgbox,"glitchtime = ";glitchtime 'ver111-37c '2. Initialize circuits in MSA out port, 0 'begin with all data lines low out control, contclear 'begin with all command lines low 'the following are meaningless values to guarantee first time commanding. Used in subroutine, [DetermineModule] lastdds1output = appxdds1:lastdds3output = appxdds3:lastpdmstate = 2 'ver111-28 'Initialize Final Filter path to "0" (path 1 of 4). This is an optional hardware addition to the MSA 'ver111-29: no final filter bank has been released, as of 1-29-08. 'However, assume these are the styles of filters: '4 bank, using A0 and A1, and a latch line A2. To be used with original Control Board or SLIM Control Board '4 bank, using A0 and A1, with no latch line. To be used with SLIM Control Board, only. 'The SLIM Control Board can support an 8 bank, using A0,A1,A2 as control, with no latching capability A1=0 : A0=0 'default Filter Bank to path 0. ver111-29 gosub [CommandFilter]'ver111-29 gosub [CalTablePath1]'ver111-39a '[InitializeTrkGen]'Reset Serial DDS3 and Initialize PLL3, but no frequency command yet if TGtop = 0 then goto [endInitializeTrkGen]' there is no Tracking Generator ver111-22 '(Initialize DDS 3) if cb = 0 and TGtop = 2 then Jcontrol = INIT:swclk = 32:sfqud = 2:gosub [ResetDDS3ser] 'ver111-7 '[ResetDDS3ser]needs:port,control,Jcontrol,swclk,sfqud,contclear ; resets DDS3, serially if cb = 2 then gosub [ResetDDS3serSLIM] 'ver111-29 '(Initialize PLL 3)'CreatePLL3R,CommandPLL3R appxpdf=PLL3phasefreq 'ver111-4 if TGtop = 1 then reference=masterclock 'ver111-4 if TGtop = 2 then reference=appxdds3 'ver111-4 gosub [CreateRcounter]'needs:reference,appxpdf ; creates:rcounter 'ver111-14 rcounter3=rcounter : pdf3=pdf 'ver111-7 'CommandPLL3R and Init Buffers datavalue = 8:levalue = 4 'PLL3 data and le bit values ver111-28 gosub [CommandPLL3R]'needs:PLL3mode,PLL3phasepolarity,INIT,PLL3 ; Initializes and commands PLL3 R Buffer(s) 'ver111-7 [endInitializeTrkGen] '[InitializePLL2]'Initialize and Command frequency 'CreatePLL2R appxpdf=PLL2phasefreq 'ver111-4 reference=masterclock 'ver111-4 gosub [CreateRcounter]'needed:reference,appxpdf ; creates:rcounter,pdf 'ver111-14 rcounter2 = rcounter 'ver111-7 pdf2 = pdf 'actual phase detector frequency of PLL 2 'ver111-7 'CommandPLL2R and Init Buffers datavalue = 16: levalue = 16 'PLL2 data and le bit values ver111-28 gosub [CommandPLL2R]'needs:PLL2phasepolarity,SELT,PLL2 ; Initializes and commands PLL2 R Buffer(s) 'CreatePLL2N appxVCO = appxLO2 : reference = masterclock gosub [CreateIntegerNcounter]'needs:appxVCO,reference,rcounter ; creates:ncounter,fcounter(0) ncounter2 = ncounter:fcounter2 = fcounter gosub [CreatePLL2N]'needs:ncounter,fcounter,PLL2 ; returns with Bcounter,Acounter, and N Bits N0-N23 Bcounter2=Bcounter: Acounter2=Acounter LO2=((Bcounter*preselector)+Acounter+(fcounter/16))*pdf2 'actual LO2 frequency 'CommandPLL2N Jcontrol = SELT : LEPLL = 8 datavalue = 16: levalue = 16 'PLL2 data and le bit values ver111-28 gosub [CommandPLL]'needs:N23-N0,control,Jcontrol,port,contclear,LEPLL ; commands N23-N0,old ControlBoard ver111-5 '[endInitializePLL2] '[InitializeHybridSynthLO1]'Reset Parallel DDS1 and Initialize PLL1, but no frequency command yet '[InitializePLL1]'set PLL1 to proper Rcount and initialize appxpdf=PLL1phasefreq 'ver111-4 reference=appxdds1 'ver111-4 gosub [CreateRcounter]'needed:reference,appxpdf ; creates:rcounter,pdf 'ver111-4 rcounter1 = rcounter 'ver111-4 'CommandPLL1R and Init Buffers datavalue = 2: levalue = 1 'PLL1 data and le bit values ver111-28 gosub [CommandPLL1R]'needs:rcounter1,PLL1mode,PLL1phasepolarity,SELT,PLL1 ; Initializes and commands PLL1 R Buffer(s) '[InitializeDDS1]'reset DDS1. It can power up in a bogus condition. if cb = 0 and dds1parser = 0 then gosub [ResetDDS1par]'(Orig Control)'needs:control,STRBAUTO,contclear ; resets DDS1 on J5, parallel ver111-21 if cb = 0 and dds1parser = 1 then gosub [ResetDDS1ser]'(Orig Control)'needed:control,AUTO,STRB,contclear ; resets DDS1 on J5, into serial mode ver111-21 if cb = 2 then gosub [ResetDDS1serSLIM]'reset serial DDS1 without disturbing Filter Bank or PDM 'ver111-29 '[endInitializePLL1] '3. [GrabWorkingWindowData] 'get info from Working window to create Graph Window and step calculations gosub [calcWindowInfo] '4. [SetUpGraphWindow] 'create the Graph Window, using Working Window data if vna = 0 then gosub [CreateGraphMSA] 'create SA Graph and then return here if vna = 1 then gosub [CreateGraphVNA] 'create VNA Graph and then return here '5. Calculate all the steps and put in arrays 'ver111-5 gosub [CalculateAllStepsForLO1Synth] 'ver111-18 if TGtop > 0 then gosub [CalculateAllStepsForLO3Synth] 'ver111-18 gosub [CreateCmdAllArray] 'ver111-31b '6. (Start) [SweepFromStartFreq]'Begin sweeping from step 0 and clear out computer graphics memory print #handle, "discard" 'clear out pc memory of drawn segments, to prevent computer from running out of RAM thisstep = 0 'reset step number for beginning of sweep if invdeg = 1 then gosub [CalPDMinvdeg] 'special routine for calibrating Phase Detector Module '7. (command step) (150 usec, 0 SW) [CommandNextStep]'needs:thisstep ; commands PLL1,DDS1,PLL3,DDS3,PDM 'ver111-7 'a. first, check to see if any or all the 5 module commands are necessary [DetermineModule] 'b. calculate how much delay is needed for each module[DetermineModule], but use only the largest one[WaitStatement]. 'c. send individual data, clocks, and latch commands that are necessary for[CommandOrigCB] 'or for SLIM, use [CommandAllSlims] for commanding concurrently 'ver111-31c gosub [DetermineModule] 'determine which, if any, module needs commanding. ver111-27 cmdneeded = glitchp1 + glitchd1 + glitchp3 + glitchd3 + glitchpdm 'ver111-38a if cmdneeded > 0 and cb = 0 then gosub [CommandOrigCB]'old Control (150 usec, 0 SW) 'ver111-28ver111-38a 'if cb = 1 then gosub [CommandRevB]'old Control looking like SLIM 'not created yet if cmdneeded > 0 and cb = 2 then gosub [CommandAllSlims]'ver111-38a '8. (DetermineNextOperationAfterCommanding) 'if this is the first step after a HALT, then add extra settling time, then read this step if haltsweep = 0 then haltsweep = 1:glitchhlt = 10:goto [ReadStep] 'ver111-36 'if this is not the first step after a Halt, then process and print the previous step, then read this step gosub [ProcessAndPrintLastStep] [ReadStep] gosub [WaitStatement]'needs:wate,glitch variables,glitchtime ; this slows the program 'ver111-20b magdata = 0 if vna = 1 then gosub [ReadPhase]:phaarray(thisstep,3) = phadata 'ver111-36f 'and return with phadata and put raw data into array 'if magdata is collected during [ReadPhase], skip Read Magnitude ver111-22 if magdata = 0 then gosub [ReadMagnitude]'and return with raw magdata bits 'ver111-22 magarray(thisstep,3) = magdata 'put raw data into array ver111-19 '(DetermineNextOperationAfterReading) if onestep = 1 then goto [Halted] 'we are in one step mode. ver111-26 'if calibrating the VNA, halt on the last step if calfwd = 1 and thisstep = steps then beep:print #main.calibfwd, "Calibrated":goto [Halted] 'ver111-30b scan 'check for any button push and go there. ver111-26 '9. [IncrementOneStep]'entered from [OneStep]or[Continue] via the [FocusKeyBox] thisstep = thisstep + 1 'add 1 to step and continue sweeping if thisstep > steps then goto [SweepFromStartFreq] 'end of sweep, start over goto [CommandNextStep] 'ver111-3 '10. [Halted]'ver111-35 gosub [ProcessAndPrint]'get raw data, process, print to the computer monitor ver111-22 if calfwd = 1 and thisstep < steps then print #main.calibfwd, "Calibrate ?" 'ver111-30b calfwd = 0 'exit vna calibration mode. ver111-30b haltsweep = 0 'this says the sweep has been halted, so don't print the first command of the next sweep step 'ver111-20 gosub [Reprintlines] 'retrace graph lines when sweep is stopped print #main.msgbox,test 'this is used for troubleshooting, will normally print "0" in the message box print #main.stepnobox,thisstep print #main.thisfreqbox,datatable(thisstep,1) 'this is "thisfreq" print #main.thispowerbox,datatable(thisstep,2) 'this is "magpower" if vna = 1 then print #main.thisphasebox,datatable(thisstep,3);" deg" print #main.restart, "Restart" 'ver111-30c leftdownpixelx = x+1 'ver111-36a wait 'wait for operator to: 'Change red parameters in Working Window and then "Restart" 'Change green parameters in Working Window and then "Restart","Continue", or "One Step" 'Click any Button for appropriate action '----SubRoutines------ [ProcessAndPrintLastStep] rememberstep = thisstep 'remember where we were when entering this routine 'ver111-19 'since we are processing and printing the previous step, use raw data in array(thisstep - 1). exception is thisstep 0 thisstep = thisstep - 1 'ver111-26 if thisstep < 0 then thisstep = steps 'ver111-26 gosub [ProcessAndPrint]'get raw data, process, print to the computer monitor ver111-22 thisstep = rememberstep 'ver111-19 return [WaitStatement]'needed:wate,glitch()(p1,d1,p3,d3,pdm,hlt),glitchtime ; this slows the program 'ver111-27 glitch = max(max(max(glitchp1, glitchd1),max(glitchp3, glitchd3)), max(glitchpdm, glitchhlt)) 'ver111-27 'glitchp1=PLL1:glitchd1=DDS1:glitchp3=PLL3:glitchd3=DDS3:glitchpdm=PDM(10):glitchhlt=halted(10),others=(1) waittime = (wate + glitch)*glitchtime 'ver111-27 'in my Toshiba, a waittime count of 80 gives a delay of approx, 1 millisecond 'therefore, each increment of any "glitchXX" or "wate" (Wait Box) should add 1 ms of delay before a "read" timecounter = 0 'ver111-27 [TimeLoop] 'ver111-27 if timecounter < waittime then timecounter = timecounter + 1:goto [TimeLoop] 'ver111-27 glitchp1=0:glitchd1=0:glitchp3=0:glitchd3=0:glitchpdm=0:glitchhlt=0 'reset glitch variables back to 0 'ver111-27 return 'to [ReadStep]or[InvertPDmodule]or[CalPDMinvdeg] [AutoGlitchtime] 'ver111-37c glitchtime = 100000 wate = 1 a = time$("ms") gosub [WaitStatement] b = time$("ms") glitchtime = glitchtime/(b-a) wate = 0 return [ReadMagnitude]'needed: port,status ; creates: magdata (and phadata for serial A/D's) if adconv = 8 then gosub [Read8Bitmag] 'and return here with magdata if adconv = 12 then gosub [Read12Bitmag] 'and return here with magdata if adconv = 16 then gosub [ReadAD16Status]:gosub [Process16Mag] 'combined ver111-34a 'and return here with stat15-stat0 words and magdata 'ver111-33b if adconv = 22 then gosub [ReadAD22Status]:gosub [Process22Mag] 'ver111-37a 'and return here with stat11-stat0 words and magdata 'ver111-37a return 'to [ReadStep] [ReadPhase]'needed: port,status ; creates: phadata (and magdata for serial A/D's) if adconv = 8 then gosub [Read8Bitpha] 'and return here with phadata if adconv = 12 then gosub [Read12Bitpha] 'and return here with phadata if adconv = 16 then gosub [ReadAD16Status]:gosub [Process16MagPha] 'combined ver111-34a if adconv = 22 then gosub [ReadAD22Status]:gosub [Process22MagPha] 'ver111-37a 'and return here with stat15-stat0 words and phadata (and magdata) 'ver111-33b if invdeg = 1 then return 'to [CalPDMinvdeg] 'ver111-29 pdmread = phaarray(thisstep,0) 'PDM state at which this data is taken. ver111-39d phaarray(thisstep,4) = pdmread 'used by Variables Windows. ver111-39d if flip = 1 then flip = 0:return 'to [ReadStep],skip checking for dead zone, just assume data is viable. 'ver111-28 if phadata < pdmlowlim or phadata > pdmhighlim then goto [InvertPDmodule] 'ver111-36f return 'to [ReadStep] [InvertPDmodule] 'ver111-28 'this new version will re-command PDM, and read phase, but not test for dead zone again, just assumes data to be viable if pdmread = 0 then newpdmstate = 1 'ver111-28 if pdmread = 1 then newpdmstate = 0 'ver111-28 for i = thisstep to steps 'ver111-20a phaarray(i,0) = newpdmstate 'inverts pdmcmd for thisstep and supsequent steps to end of sweep. ver111-28 next i 'ver111-20a 'now, go and command the PDM to the new state (Command PDM only!) gosub [CommandPDMonly] 'command just the PDM ver111-28 'now, wait for PDM to settle before going back and reading data again, due to huge glitch created during PDM flip glitchpdm = 10 : gosub [WaitStatement] 'wait 10 milliseconds 'ver111-28 flip = 1 ' shows that the PDM has just been flipped (or inverted from previous state) ver111-28 goto [ReadPhase] 'and re-read the phase but don't test for dead zone ver111-28 [CalPDMinvdeg] 'the VNA must be in "0" sweepwidth, freq close to the transition point. print #main.restart, "Cal PDM" 'ver111-36d beep phaarray(thisstep,0) = 0 'command PDM to Normal 'ver111-29 gosub [CommandPDMonly] 'ver111-29 glitchpdm = 5000 'should equate to 5 seconds of delay 'ver111-29 gosub [WaitStatement] 'ver111-29 gosub [ReadPhase]'but, don't test for dead zone, since invdeg = 1 'ver111-29 'the 16 bit serial has just been "hit" with a conv (D7)in Commanding the Orig PDM. OK to hit it again, now? I think so. phase0 = 360*phadata/maxpdmout 'convert to degrees phaarray(thisstep,0) = 1 'command PDM to Inverted 'ver111-29 gosub [CommandPDMonly] 'ver111-29 glitchpdm = 5000 'should equate to 5 seconds of delay 'ver111-29 gosub [WaitStatement] 'ver111-29 gosub [ReadPhase]'but, don't test for dead zone, since invdeg = 1 'ver111-29 phase1 = 360*phadata/maxpdmout 'convert to degrees invdeg = phase1 - phase0 if invdeg < 0 then invdeg = invdeg + 360 invdeg = val(using("####.##",invdeg)) 'PDM's phase shift when inverted, in .01 degree resolution print #main.restart, "Restart" 'ver111-36d print #main.invdegbox,invdeg beep 'ver111-36d wait [Read8Bitmag]'needed: port,status ; creates: magdata 'This will 8 bit parallel on Original or Slim Control Board. ver111-29 ' if inp(status) < 128 then wait (status bit 7) line is high (D/A 127 then wait line is low (magnitude voltage 63 then ack line is high (phase voltage>ladder) 'the data will always be 1 bit less than crossover region phadata = 0 if cb = 2 then out control, AUTO 'enable P3 on SLIM Control Board. ver111-29 out port, phadata + 128 'set D/A MSB to "1", creates 2.5v out of D/A ladder magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 128 out port, phadata + 64 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 64 out port, phadata + 32 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 32 out port, phadata + 16 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 16 out port, phadata + 8 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 8 out port, phadata + 4 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 4 out port, phadata + 2 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 2 out port, phadata + 1 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 1 out port, 0 'return data to zero if cb = 2 then out control, contclear 'disable P3 on SLIM Control Board. ver111-29 return 'return, with phadata [Read12Bitmag]'needed: port,status ; creates: magdata 'This will read 12 bit parallel, WAIT line, on Original or Slim Control Board. ver111-29 ' if inp(status) < 128 then wait line (status bit 7)is high (D/A 127 then wait line is low (magnitude voltage 63 then ack line is high (phase voltage>ladder) ' if inp(status) < 64 then ack line is low (phase voltage 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 2048: word = word + 8 out port,word +4 +16 +32 ' put 4 into MSB latch, D/A = 1024 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 1024: word = word + 4 out port,word +2 +16 +32 ' put 2 into MSB latch, D/A = 512 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 512: word = word + 2 out port,word +1 +16 +32 ' put 1 into MSB latch, D/A = 256 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 256: word = word + 1 out port,word +16 +32 ' put appxm. into MSB latch, D/A = appx out port,word +16 +32 +64 ' latch MSB with appx word = 0 out port,8 +16 +64 ' put 8 into middle latch, D/A = 128 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 128: word = word + 8 out port,word +4 +16 +64 ' put 4 into middle latch, D/A = 64 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 64: word = word + 4 out port,word +2 +16 +64 ' put 2 into middle latch, D/A = 32 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 32: word = word + 2 out port,word +1 +16 +64 ' put 1 into middle latch, D/A = 16 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 16: word = word + 1 out port,word +16 +64 ' put appxm. into middle latch, D/A = appx out port,word +16 +32 +64 ' latch middle with appx word = 0 out port,8 +32 +64 ' put 8 into LSB latch, D/A = 8 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 8: word = word + 8 out port,word +4 +32 +64 ' put 4 into LSB latch, D/A = 4 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 4: word = word + 4 out port,word +2 +32 +64 ' put 2 into LSB latch, D/A = 2 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 2: word = word + 2 out port,word +1 +32 +64 ' put 1 into LSB latch, D/A = 1 magpha = inp(status) if magpha > 127 then magpha = magpha - 128 if magpha > 63 then phadata = phadata + 1 out port, 0 'return data to zero if cb = 2 then out control, contclear 'disable P3 on SLIM Control Board. ver111-29 return ' return with phadata [ReadAD16Status]'needed: port,status ; creates: 16 status port words (stat15-stat0)mag,(and, pha if two A/D's installed) 'ver111-33a 'reads 16 bit serial on Original or Slim Control Board. ver111-33c 'good for 16 Bit Original AtoD or 16 Bit, SLIM AtoD 'MAG is WAIT, PHASE is ACK, SCLK is BD6, CVNis BD7. if cb = 2 then out control, AUTO 'enable P3 on SLIM Control Board. ver111-29 out port, 128 'take CVN high out port, 64 'CVN low, SCLK=1 stat15 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat14 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat13 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat12 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat11 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat10 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat9 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat8 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat7 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat6 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat5 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat4 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat3 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat2 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat1 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat0 = inp(status) 'read data, statX is 8 bit word out port, 0 'SCLK=0, a/d outputs go high z on 16th SCLK trailing edge if cb = 2 then out control, contclear 'disable P3 on SLIM Control Board. ver111-29 'we have raw a/d status words in stat15-stat0 return 'to [ReadMagnitude]or[ReadPhase]with status words [Process16MagPha]'ver111-33a 'process the stat15-0 for both magnitude and phase.Determines magdata bit (D7) and phadata bit (D6) in each word magdata = 0 phadata = 0 if stat15>127 then stat15=stat15-128:magdata = magdata + 32768 'WAIT is low, MAG is high if stat15<64 then phadata = phadata + 32768 'ACK is low, PHASE is high if stat14>127 then stat14=stat14-128:magdata = magdata + 16384 if stat14<64 then phadata = phadata + 16384 if stat13>127 then stat13=stat13-128:magdata = magdata + 8192 if stat13<64 then phadata = phadata + 8192 if stat12>127 then stat12=stat12-128:magdata = magdata + 4096 if stat12<64 then phadata = phadata + 4096 if stat11>127 then stat11=stat11-128:magdata = magdata + 2048 if stat11<64 then phadata = phadata + 2048 if stat10>127 then stat10=stat10-128:magdata = magdata + 1024 if stat10<64 then phadata = phadata + 1024 if stat9>127 then stat9=stat9-128:magdata = magdata + 512 if stat9<64 then phadata = phadata + 512 if stat8>127 then stat8=stat8-128:magdata = magdata + 256 if stat8<64 then phadata = phadata + 256 if stat7>127 then stat7=stat7-128:magdata = magdata + 128 if stat7<64 then phadata = phadata + 128 if stat6>127 then stat6=stat6-128:magdata = magdata + 64 if stat6<64 then phadata = phadata + 64 if stat5>127 then stat5=stat5-128:magdata = magdata + 32 if stat5<64 then phadata = phadata + 32 if stat4>127 then stat4=stat4-128:magdata = magdata + 16 if stat4<64 then phadata = phadata + 16 if stat3>127 then stat3=stat3-128:magdata = magdata + 8 if stat3<64 then phadata = phadata + 8 if stat2>127 then stat2=stat2-128:magdata = magdata + 4 if stat2<64 then phadata = phadata + 4 if stat1>127 then stat1=stat1-128:magdata = magdata + 2 if stat1<64 then phadata = phadata + 2 if stat0>127 then stat0=stat0-128:magdata = magdata + 1 if stat0<64 then phadata = phadata + 1 return 'to [ReadPhase] with magdata and phadata [Process16Mag]'ver111-33a 'process the stat15-0 for magnitude only. Determines magdata bit (D7) in each word magdata = 0 if stat15>127 then magdata = magdata + 32768 'WAIT is low, MAG is high if stat14>127 then magdata = magdata + 16384 'WAIT is low, MAG is high if stat13>127 then magdata = magdata + 8192 'WAIT is low, MAG is high if stat12>127 then magdata = magdata + 4096 'WAIT is low, MAG is high if stat11>127 then magdata = magdata + 2048 'WAIT is low, MAG is high if stat10>127 then magdata = magdata + 1024 'WAIT is low, MAG is high if stat9>127 then magdata = magdata + 512 'WAIT is low, MAG is high if stat8>127 then magdata = magdata + 256 'WAIT is low, MAG is high if stat7>127 then magdata = magdata + 128 'WAIT is low, MAG is high if stat6>127 then magdata = magdata + 64 'WAIT is low, MAG is high if stat5>127 then magdata = magdata + 32 'WAIT is low, MAG is high if stat4>127 then magdata = magdata + 16 'WAIT is low, MAG is high if stat3>127 then magdata = magdata + 8 'WAIT is low, MAG is high if stat2>127 then magdata = magdata + 4 'WAIT is low, MAG is high if stat1>127 then magdata = magdata + 2 'WAIT is low, MAG is high if stat0>127 then magdata = magdata + 1 'WAIT is low, MAG is high return 'to [ReadMagnitude]with magdata [ReadAD22Status]'needed: port,status ; creates: 12 status port words (stat11-stat0)mag,(and, pha if two A/D's installed) 'ver111-37a 'reads SLIM-ADC-12 from Slim Control Board, only. ver111-37a 'MAG is WAIT, PHASE is ACK, SCLK is BD6, CVN is BD7. out control, AUTO 'enable P3 on SLIM Control Board out port, 128 'take CVN high out port, 64 'CVN low, SCLK=1 out port, 0 'CVN low, SCLK=0 fix error ver111-39c out port, 64 'CVN low, SCLK=1 fix error ver111-39c stat11 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat10 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat9 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat8 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat7 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat6 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat5 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat4 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat3 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat2 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat1 = inp(status) 'read data, statX is 8 bit word out port, 0 'CVN low, SCLK=0 out port, 64 'CVN low, SCLK=1 stat0 = inp(status) 'read data, statX is 8 bit word out port, 0 'SCLK=0, a/d outputs go high z on 16th SCLK trailing edge out control, contclear 'disable P3 on SLIM Control Board. ver111-29 'we have raw a/d status words in stat11-stat0 return 'to [ReadMagnitude]or[ReadPhase]with status words [Process22MagPha]'ver111-37a 'process the stat11-0 for both magnitude and phase.Determines magdata bit (D7) and phadata bit (D6) in each word magdata = 0 phadata = 0 if stat11>127 then stat11=stat11-128:magdata = magdata + 2048 'WAIT is low, MAG is high if stat11<64 then phadata = phadata + 2048 'ACK is low, PHASE is high if stat10>127 then stat10=stat10-128:magdata = magdata + 1024 if stat10<64 then phadata = phadata + 1024 if stat9>127 then stat9=stat9-128:magdata = magdata + 512 if stat9<64 then phadata = phadata + 512 if stat8>127 then stat8=stat8-128:magdata = magdata + 256 if stat8<64 then phadata = phadata + 256 if stat7>127 then stat7=stat7-128:magdata = magdata + 128 if stat7<64 then phadata = phadata + 128 if stat6>127 then stat6=stat6-128:magdata = magdata + 64 if stat6<64 then phadata = phadata + 64 if stat5>127 then stat5=stat5-128:magdata = magdata + 32 if stat5<64 then phadata = phadata + 32 if stat4>127 then stat4=stat4-128:magdata = magdata + 16 if stat4<64 then phadata = phadata + 16 if stat3>127 then stat3=stat3-128:magdata = magdata + 8 if stat3<64 then phadata = phadata + 8 if stat2>127 then stat2=stat2-128:magdata = magdata + 4 if stat2<64 then phadata = phadata + 4 if stat1>127 then stat1=stat1-128:magdata = magdata + 2 if stat1<64 then phadata = phadata + 2 if stat0>127 then stat0=stat0-128:magdata = magdata + 1 if stat0<64 then phadata = phadata + 1 return 'to [ReadPhase] with magdata and phadata [Process22Mag]'ver111-37a 'process the stat11-0 for magnitude only. Determines magdata bit (D7) in each word magdata = 0 if stat11>127 then magdata = magdata + 2048 'WAIT is low, MAG is high if stat10>127 then magdata = magdata + 1024 'WAIT is low, MAG is high if stat9>127 then magdata = magdata + 512 'WAIT is low, MAG is high if stat8>127 then magdata = magdata + 256 'WAIT is low, MAG is high if stat7>127 then magdata = magdata + 128 'WAIT is low, MAG is high if stat6>127 then magdata = magdata + 64 'WAIT is low, MAG is high if stat5>127 then magdata = magdata + 32 'WAIT is low, MAG is high if stat4>127 then magdata = magdata + 16 'WAIT is low, MAG is high if stat3>127 then magdata = magdata + 8 'WAIT is low, MAG is high if stat2>127 then magdata = magdata + 4 'WAIT is low, MAG is high if stat1>127 then magdata = magdata + 2 'WAIT is low, MAG is high if stat0>127 then magdata = magdata + 1 'WAIT is low, MAG is high return 'to [ReadMagnitude]with magdata [ProcessAndPrint]'process and print "thisstep" 'ver111-22 gosub [ConvertMagData] 'convert magdata (bits read) to magpower (dBm) and thispointmag (pixels) if vna = 1 then gosub [ConvertPhadata]'convert phadata (bits read) to phase (degrees) and thispointphase (pixels) 'ver111-19 gosub [PlotDataToScreen] return 'from [ProcessAndPrint] [ConvertPhadata]'needed: phadata,PDM polarity ; creates "phaseofpdm" and "thispointphase", the pixel value 'grab raw phase data bits from array phadata = phaarray(thisstep,3) 'ver111-19 'convert phadata to absolute phase lead, referenced to 0 degrees. maxpdmout/4 = 90 degrees lead,maxpdmout/2 = 180 degrees lead phase = val(using("####.##",(360*phadata/maxpdmout))) 'converts phadata bits to absolute phase and round off to .01 degrees 'the absolute phase will always be between +288 and +72 degrees 'if PDM is inverted, subtract the inverted phase change (norm to inv adds xxx deg) phase = phase - (invdeg * phaarray(thisstep,0)) 'ver111-36g 'now, the absolute phase can be between +288 and appx -108 deg 'if negative make it real by adding 360 deg if phase < 0 then phase = phase + 360 'now, the absolute phase can only be between +360 and 0 deg 'if we are calibrating the line, put absolute phase into calibration array if calfwd = 1 then calarray(thisstep,2)= phase 'if we are calibrating the line, the following will return 0 phase 'if we are normally sweeping, the following can return anything from +360 to -360 deg phase = phase - calarray(thisstep,2) 'this gives the differential phase from calibration 'phase can now be = +360 to -360 deg 'ver111-36g 'convert to standard +180 -180 format if phase < -180 then phase = phase + 360 'ver111-36g if phase > 180 then phase = phase - 360 'ver111-36g 'now, the differential phase can only be between +180 and -180 deg datatable(thisstep,3) = phase 'put current phase measurement into the array, line value= thisstep if topphase > 180 then phase = phase + 360:if phase > 360 then phase = phase - 360 'ver111-36g if botphase < -180 then phase = phase - 360:if phase < -360 then phase = phase + 360 'ver111-36g if phase > topphase then phase = phase - 360:if phase < botphase then phase = phase + 360 'ver111-36g if phase < botphase then phase = phase + 360:if phase > topphase then phase = phase - 360 'ver111-36g thispointphase = maxscale * (phase - botphase)/(topphase - botphase) 'convert phasedisplay to pixels 'ver111-36g if phase > topphase then thispointphase = maxscale 'ver111-36g if phase < botphase then thispointphase = 0 'ver111-36g return 'to [ProcessAndPrint] [ConvertMagData]'convert magnitude data bits to MSA input power(in dBm) and to pixels. ver111-39a 'needed: magdata,calibration table magdata = magarray(thisstep,3) 'this section converts magdata to MSA input power, with frequency correction error if magdata >= calbits0 then power = calpwr0 : goto [ConvertFreqError]'power is at or over it's limit if magdata >= calbits1 then power = calpwr1+((calpwr0-calpwr1)*(magdata-calbits1)/(calbits0-calbits1)) : goto [ConvertFreqError] if magdata >= calbits2 then power = calpwr2+((calpwr1-calpwr2)*(magdata-calbits2)/(calbits1-calbits2)) : goto [ConvertFreqError] if magdata >= calbits3 then power = calpwr3+((calpwr2-calpwr3)*(magdata-calbits3)/(calbits2-calbits3)) : goto [ConvertFreqError] if magdata >= calbits4 then power = calpwr4+((calpwr3-calpwr4)*(magdata-calbits4)/(calbits3-calbits4)) : goto [ConvertFreqError] if magdata >= calbits5 then power = calpwr5+((calpwr4-calpwr5)*(magdata-calbits5)/(calbits4-calbits5)) : goto [ConvertFreqError] if magdata >= calbits6 then power = calpwr6+((calpwr5-calpwr6)*(magdata-calbits6)/(calbits5-calbits6)) : goto [ConvertFreqError] if magdata >= calbits7 then power = calpwr7+((calpwr6-calpwr7)*(magdata-calbits7)/(calbits6-calbits7)) : goto [ConvertFreqError] if magdata >= calbits8 then power = calpwr8+((calpwr7-calpwr8)*(magdata-calbits8)/(calbits7-calbits8)) : goto [ConvertFreqError] if magdata >= calbits9 then power = calpwr9+((calpwr8-calpwr9)*(magdata-calbits9)/(calbits8-calbits9)) : goto [ConvertFreqError] if magdata >= calbits10 then power = calpwr10+((calpwr9-calpwr10)*(magdata-calbits10)/(calbits9-calbits10)) : goto [ConvertFreqError] if magdata >= calbits11 then power = calpwr11+((calpwr10-calpwr11)*(magdata-calbits11)/(calbits10-calbits11)) : goto [ConvertFreqError] if magdata >= calbits12 then power = calpwr12+((calpwr11-calpwr12)*(magdata-calbits12)/(calbits11-calbits12)) : goto [ConvertFreqError] if magdata >= calbits13 then power = calpwr13+((calpwr12-calpwr13)*(magdata-calbits13)/(calbits12-calbits13)) : goto [ConvertFreqError] if magdata >= calbits14 then power = calpwr14+((calpwr13-calpwr14)*(magdata-calbits14)/(calbits13-calbits14)) : goto [ConvertFreqError] if magdata >= calbits15 then power = calpwr15+((calpwr14-calpwr15)*(magdata-calbits15)/(calbits14-calbits15)) : goto [ConvertFreqError] if magdata >= calbits16 then power = calpwr16+((calpwr15-calpwr16)*(magdata-calbits16)/(calbits15-calbits16)) : goto [ConvertFreqError] if magdata >= calbits17 then power = calpwr17+((calpwr16-calpwr17)*(magdata-calbits17)/(calbits16-calbits17)) : goto [ConvertFreqError] if magdata >= calbits18 then power = calpwr18+((calpwr17-calpwr18)*(magdata-calbits18)/(calbits17-calbits18)) : goto [ConvertFreqError] if magdata >= calbits19 then power = calpwr19+((calpwr18-calpwr19)*(magdata-calbits19)/(calbits18-calbits19)) : goto [ConvertFreqError] if magdata >= calbits20 then power = calpwr20+((calpwr19-calpwr20)*(magdata-calbits20)/(calbits19-calbits20)) : goto [ConvertFreqError] [ConvertFreqError]'correct power for frequency error contribution. ver111-39a 'needed: thisfreq, frequency error calibration table; creates average freqerror thisfreq = datatable(thisstep,1) if thisfreq <= calfreq0 then freqerror = pwreratf0 : goto [CalcMagpowerPixel] if thisfreq <= calfreq1 then freqerror = pwreratf0+((pwreratf1-pwreratf0)*(thisfreq-calfreq0)/(calfreq1-calfreq0)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq2 then freqerror = pwreratf1+((pwreratf2-pwreratf1)*(thisfreq-calfreq1)/(calfreq2-calfreq1)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq3 then freqerror = pwreratf2+((pwreratf3-pwreratf2)*(thisfreq-calfreq2)/(calfreq3-calfreq2)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq4 then freqerror = pwreratf3+((pwreratf4-pwreratf3)*(thisfreq-calfreq3)/(calfreq4-calfreq3)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq5 then freqerror = pwreratf4+((pwreratf5-pwreratf4)*(thisfreq-calfreq4)/(calfreq5-calfreq4)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq6 then freqerror = pwreratf5+((pwreratf6-pwreratf5)*(thisfreq-calfreq5)/(calfreq6-calfreq5)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq7 then freqerror = pwreratf6+((pwreratf7-pwreratf6)*(thisfreq-calfreq6)/(calfreq7-calfreq6)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq8 then freqerror = pwreratf7+((pwreratf8-pwreratf7)*(thisfreq-calfreq7)/(calfreq8-calfreq7)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq9 then freqerror = pwreratf8+((pwreratf9-pwreratf8)*(thisfreq-calfreq8)/(calfreq9-calfreq8)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq10 then freqerror = pwreratf9+((pwreratf10-pwreratf9)*(thisfreq-calfreq9)/(calfreq10-calfreq9)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq11 then freqerror = pwreratf10+((pwreratf11-pwreratf10)*(thisfreq-calfreq10)/(calfreq11-calfreq10)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq12 then freqerror = pwreratf11+((pwreratf12-pwreratf11)*(thisfreq-calfreq11)/(calfreq12-calfreq11)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq13 then freqerror = pwreratf12+((pwreratf13-pwreratf12)*(thisfreq-calfreq12)/(calfreq13-calfreq12)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq14 then freqerror = pwreratf13+((pwreratf14-pwreratf13)*(thisfreq-calfreq13)/(calfreq14-calfreq13)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq15 then freqerror = pwreratf14+((pwreratf15-pwreratf14)*(thisfreq-calfreq14)/(calfreq15-calfreq14)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq16 then freqerror = pwreratf15+((pwreratf16-pwreratf15)*(thisfreq-calfreq15)/(calfreq16-calfreq15)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq17 then freqerror = pwreratf16+((pwreratf17-pwreratf16)*(thisfreq-calfreq16)/(calfreq17-calfreq16)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq18 then freqerror = pwreratf17+((pwreratf18-pwreratf17)*(thisfreq-calfreq17)/(calfreq18-calfreq17)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq19 then freqerror = pwreratf18+((pwreratf19-pwreratf18)*(thisfreq-calfreq18)/(calfreq19-calfreq18)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq20 then freqerror = pwreratf19+((pwreratf20-pwreratf19)*(thisfreq-calfreq19)/(calfreq20-calfreq19)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq21 then freqerror = pwreratf20+((pwreratf21-pwreratf20)*(thisfreq-calfreq20)/(calfreq21-calfreq20)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq22 then freqerror = pwreratf21+((pwreratf22-pwreratf21)*(thisfreq-calfreq21)/(calfreq22-calfreq21)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq23 then freqerror = pwreratf22+((pwreratf23-pwreratf22)*(thisfreq-calfreq22)/(calfreq23-calfreq22)) : goto [CalcMagpowerPixel] if thisfreq <= calfreq24 then freqerror = pwreratf23+((pwreratf24-pwreratf23)*(thisfreq-calfreq24)/(calfreq24-calfreq23)) : goto [CalcMagpowerPixel] if thisfreq > calfreq24 then freqerror = pwreratf24 : goto [CalcMagpowerPixel] [CalcMagpowerPixel] power = power + freqerror 'round off MSA input power to .01 dBm, magpower, no matter which AtoD is used magpower = val(using("####.##",power)) if calfwd = 1 then calarray(thisstep,1)= magpower 'this inserts the power into the calarray for magnitude reference if vna = 1 then magpower = magpower - calarray(thisstep,1) 'this gives the differential power from calibration datatable(thisstep,2) = magpower 'put current power measurement into the array, line value= thisstep '[ConvertPowerToPixels]'needed:magpower,topref,botref ; creates thispointmag (pixels) if magpower > topref then thispointmag = maxscale 'normally, maxscale=255 if magpower <= topref and magpower >= botref then thispointmag = maxscale*(magpower-botref)/(topref-botref) if magpower < botref then thispointmag = 0 'thispointmag is in pixels, from 0 to maxscale return 'to [ProcessAndPrint] return [PlotDataToScreen] 'magdisp: 0=magoff, 1=normerase, 2=normstick, 3=histerase, 4=histstick 'phadisp: 0=phaoff, 1=erase, 2=stick thispointx = magarray(thisstep,0) 'calculation is in [CalculateAllStepsForLO1Synth] ver111-25 '(erase) 'if magdisp=3 then erase old histo line by covering old histo line with a vertical white line if magdisp = 3 then print #handle, "color white ; line ";thispointx;" ";y-magarray(thisstep,2);" ";thispointx;" ";y 'ver111-25 'if magdisp=1 then erase old mag segment by covering old mag segment with a white line if magdisp = 1 and thisstep > 0 then print #handle, "color white ; line ";thispointx;" ";y-magarray(thisstep,2);" ";magarray(thisstep-1,0);" ";y-magarray(thisstep-1,1) 'ver111-25 if magdisp = 1 and thisstep = 0 then print #handle, "color white ; line ";thispointx;" ";y-magarray(thisstep,1);" ";thispointx;" ";y-magarray(thisstep,1) 'ver111-25 'if phadisp=1 then erase old pha segment by covering old pha segment with a white line if phadisp = 1 and thisstep > 0 then print #handle, "color white ; line ";thispointx;" ";y-phaarray(thisstep,2);" ";magarray(thisstep-1,0);" ";y-phaarray(thisstep-1,1) 'ver111-25 if phadisp = 1 and thisstep = 0 then print #handle, "color white ; line ";thispointx;" ";y-phaarray(thisstep,2);" ";thispointx;" ";y-phaarray(thisstep,2) 'ver111-25 '(print) 'if magdisp=3or4 then print new histo line in black if magdisp = 3 or magdisp = 4 then print #handle, "color black ;line ";thispointx;" ";y-thispointmag;" ";thispointx;" ";y 'ver111-25 'if magdisp=1or2 then print new mag segment in blue if (magdisp = 1 or magdisp = 2) and thisstep > 0 then print #handle, "color blue ;line ";thispointx;" ";y-thispointmag;" ";magarray(thisstep-1,0);" ";y-magarray(thisstep-1,2) 'ver111-25 if (magdisp = 1 or magdisp = 2) and thisstep = 0 then print #handle, "color blue ;line ";thispointx;" ";y-thispointmag;" ";thispointx;" ";y-thispointmag 'ver111-25 magarray(thisstep,1) = magarray(thisstep,2) 'used for removing in next step magarray(thisstep,2) = thispointmag 'used for writing in next step 'ver111-19 'if phadisp=1or2 then print new pha segment in red if (phadisp = 1 or phadisp = 2) and thisstep > 0 then print #handle, "color red ;line ";thispointx;" ";y-thispointphase;" ";magarray(thisstep-1,0);" ";y-phaarray(thisstep-1,2) 'ver111-25 if (phadisp = 1 or phadisp = 2) and thisstep = 0 then print #handle, "color red ;line ";thispointx;" ";y-thispointphase;" ";thispointx;" ";y-thispointphase 'ver111-25 phaarray(thisstep,1) = phaarray(thisstep,2) 'this is the previous sweep's y-axis pixel value at this step #, used in next step for clearing old trace phaarray(thisstep,2) = thispointphase 'this is the newest y-axis pixel value for this step, used in next step to extend new trace if thisstep = marker1 then gosub [insertMarker]'and return here after inserting marker if thisstep = marker2 then gosub [insertMarker]'and return here after inserting marker if thisstep = marker3 then gosub [insertMarker]'and return here after inserting marker if varwindow = 1 then gosub [updatevar] 'moved here from [ProcessAndPrint] ver111-34a return 'to [ProcessAndPrint] [insertMarker]'needed:thispointx,thispointmag,magdata,magpower,phaseofpdm : display marker info print #handle, "color black ; line ";thispointx;" ";(y-15)-thispointmag;" ";thispointx;" ";(y-2)-thispointmag 'ver111-25 print #handle, "line ";thispointx;" ";y+6;" ";thispointx;" ";y+10 if vna = 0 then print #handle, "\\"; datatable(thisstep,1);" MHz\";magarray(thisstep,3); " = bits\";datatable(thisstep,2);" dBm" if vna = 1 then print #handle, "\\"; datatable(thisstep,1);" MHz\";datatable(thisstep,2);" dB\";datatable(thisstep,3); " deg" return 'return to [PlotDataXX] [CreateRcounter]'needed:reference,appxpdf ; creates:rcounter,pdf 'ver111-4 rcounter = int(reference/appxpdf) 'ver111-4 if (reference/appxpdf) - rcounter >= .5 then rcounter = rcounter + 1 'rounds off rcounter 'ver111-4 pdf = reference/rcounter 'ver111-4 return 'to (Initialize PLL 3),[InitializePLL2],or[InitializePLL1]with rcounter,pdf 'ver111-4 [CommandPLL1R]'needed:rcounter1,PLL1mode,PLL1phasepolarity,SELT,PLL1 rcounter = rcounter1 preselector = 32 : if PLL1mode = 1 then preselector = 16 phasepolarity = PLL1phasepolarity 'inverting op amp is 0, non-inverting loop is 1 fractional = PLL1mode '0 for Integer-N; 1 for Fractional-N Jcontrol = SELT 'for PLL 1, on Control Board J1, the value is "3" LEPLL = 4 'for PLL 1, on Control Board J1, the value is "4" PLL = PLL1 gosub [CommandRBuffer]'needs:rcounter,preselector,phasepolarity,fractional,Jcontrol,LEPLL,PLL if len(errora$)>0 then error$ = "PLL 1, " + errora$:print #main.msgbox,error$:wait 'ver111-37e return [CommandPLL2R]'needed:reference,appxpdf,PLL2phasepolarity,SELT,PLL2 preselector = 32 phasepolarity = PLL2phasepolarity 'inverting op amp is 0, non-inverting loop is 1 fractional = 0 '0 for Integer-N; PLL 2 should not be fractional due to increased noise Jcontrol = SELT 'for PLL 2, on Control Board J2, the value is "3" LEPLL = 8 'for PLL 2, on Control Board J2, the value is "8" PLL = PLL2 gosub [CommandRBuffer]'needs:rcounter,preselector,phasepolarity,fractional,Jcontrol,LEPLL,PLL if len(errora$)>0 then error$ = "PLL 2, " + errora$:print #main.msgbox,error$:wait 'ver111-37e return 'to 'CommandPLL2R and Init Buffers [CommandPLL3R]'needed:PLL3mode,PLL3phasepolarity,INIT,PLL3 preselector = 32 : if PLL3mode = 1 then preselector = 16 phasepolarity = PLL3phasepolarity 'inverting op amp is 0, non-inverting loop is 1 fractional = PLL3mode '0 for Integer-N; 1 for Fractional-N Jcontrol = INIT 'for Tracking Gen PLL, on Control Board J3, the value is "15" LEPLL = 16 'for Tracking Gen PLL, on Control Board J3, the value is "16" PLL = PLL3 gosub [CommandRBuffer]'needs:rcounter,preselector,phasepolarity,fractional,Jcontrol,LEPLL,PLL if len(errora$)>0 then error$ = "PLL 3, " + errora$:print #main.msgbox,error$:wait 'ver111-37e return 'to 'CommandPLL3R and Init Buffers [CommandRBuffer]'needed:rcounter,preselector,phasepolarity,fractional,Jcontrol,LEPLL,PLL if PLL = 2325 then gosub [Command2325R]'needs:rcounter,preselector,Jcontrol,port,LEPLL,contclear ; commands LMX2325 rcounter and registers if PLL = 2326 then gosub [Command2326R]'needs:rcounter,phasepolarity,Jcontrol,port,LEPLL,contclear ; commands LMX2326 rcounter and registers if PLL = 2350 then gosub [Command2350R]'needs:rcounter,phasepolarity,Jcontrol,port,LEPLL,contclear,fractional ; commands LMX2350 rcounter if PLL = 2353 then gosub [Command2353R]'needs:rcounter,phasepolarity,Jcontrol,port,LEPLL,contclear,fractional ; commands LMX2353 rcounter if PLL = 4112 then gosub [Command4112R]'needs:rcounter,preselector,phasepolarity,Jcontrol,port,LEPLL,contclear ; commands AD4112 rcounter return [CreateIntegerNcounter]'needed:appxVCO,reference,rcounter ; creates:ncount,ncounter,fcounter(0),pdf ncount = appxVCO/(reference/rcounter) 'approximates the Ncounter for PLL ncounter = int(ncount) 'approximates the ncounter for PLL if ncount - ncounter >= .5 then ncounter = ncounter + 1 'rounds off ncounter fcounter = 0 pdf = appxVCO/ncounter 'actual phase freq of PLL return 'to 'CreatePLL2N,'[CalculateThisStepPLL1],or '[CalculateThisStepPLL3] with ncount, ncounter and fcounter(=0) [CreateFractionalNcounter]'needed:appxVCO,reference,rcounter ; creates:ncount,ncounter,fcounter,pdf ncount = appxVCO/(reference/rcounter) 'approximates the Ncounter for PLL ncounter = int(ncount) 'actual value for PLL Ncounter fcount = ncount - ncounter fcounter = int(fcount*16) 'ver111 if (fcount*16) - fcounter >= .5 then fcounter = fcounter + 1 'rounds off fcounter ver111 if fcounter = 16 then ncounter = ncounter + 1:fcounter = 0 pdf = appxVCO/(ncounter + (fcounter/16)) 'actual phase freq for PLL 'ver111-10 return 'with ncount,ncounter,fcounter,pdf [AutoSpur]'needed:LO1,LO2,finalfreq,appxdds1,dds1output,rcounter1,finalbw,fcounter,ncounter,spurcheck;changes pdf,dds1output '[AutoSpur] is a continuation of [CreateFractionalNcounter], used only in MSA when PLL 1 is Fractional spur = 0 'reset spur, and determine if there is potential for a spur firstif = LO2 - finalfreq fractionalfreq = dds1output/(rcounter1*16) harnonicb = int(firstif/fractionalfreq) if (firstif/fractionalfreq)-harnonicb >=.5 then harnonicb = harnonicb + 1 'rev108 harnonica = harnonicb - 1 harnonicc = harnonicb + 1 firstiflow = LO2 - (finalfreq + finalbw/1000) firstifhigh = LO2 - (finalfreq - finalbw/1000) if harnonica*fractionalfreq > firstiflow and harnonica*fractionalfreq < firstifhigh then spur = 1 if harnonicb*fractionalfreq > firstiflow and harnonicb*fractionalfreq < firstifhigh then spur = 1 if harnonicc*fractionalfreq > firstiflow and harnonicc*fractionalfreq < firstifhigh then spur = 1 if spur = 1 and (dds1outputappxdds1) then fcounter = fcounter + 1 if fcounter = 16 then ncounter = ncounter + 1:fcounter = 0 'rev108 if fcounter <0 then ncounter = ncounter - 1:fcounter = 15 'rev108 pdf = LO1/(ncounter + (fcounter/16)) dds1output = pdf * rcounter1 'actual output of DDS1(input Ref to PLL1) return 'with possibly new ncounter,fcounter,pdf,dds1output [ManSpur]'needed:spurcheck,dds1output,appxdds1,fcounter,ncounter '[ManSpur] is a continuation of [CreateFractionalNcounter], used only in MSA when PLL 1 is Fractional if spurcheck = 1 and (dds1outputappxdds1) then fcounter = fcounter + 1 'causes -shift in pdf1 if fcounter = 16 then ncounter = ncounter + 1:fcounter = 0 'rev108 if fcounter < 0 then ncounter = ncounter - 1:fcounter = 15 'rev108 pdf = LO1/(ncounter + (fcounter/16)) dds1output = pdf * rcounter1 'actual output of DDS1(input Ref to PLL1) return 'with possibly new:ncounter,fcounter,pdf,dds1output [CreatePLL1N]'needed:ncounter,fcounter,PLL1mode,PLL1 preselector = 32 : if PLL1mode = 1 then preselector = 16 PLL = PLL1 gosub [CreateNBuffer]'needs:ncounter,fcounter,PLL,preselector;creates:Bcounter,Acounter, and N Bits N0-Nx if len(errora$)>0 then error$ = "PLL 1, " + errora$:print #main.msgbox,error$:wait 'ver111-37e Bcounter1=Bcounter: Acounter1=Acounter return 'returns with Bcounter1,Acounter1,N0thruNx [CreatePLL2N]'needed:ncounter,fcounter,PLL2 preselector = 32 PLL = PLL2 gosub [CreateNBuffer]'needs:ncounter,fcounter,PLL,preselector;creates:Bcounter,Acounter, and N Bits N0-Nx if len(errora$)>0 then error$ = "PLL 2, " + errora$:print #main.msgbox,error$:wait 'ver111-37e return 'to 'CreatePLL2N [CreatePLL3N]'needed:ncounter,fcounter,PLL3mode,PLL3 ver111-14 preselector = 32 : if PLL3mode = 1 then preselector = 16 PLL = PLL3 gosub [CreateNBuffer]'needs:ncounter,fcounter,PLL,preselector;creates:Bcounter,Acounter, and N Bits N0-Nx if len(errora$)>0 then error$ = "PLL 3, " + errora$:print #main.msgbox,error$:wait 'ver111-37e Bcounter3=Bcounter: Acounter3=Acounter return 'returns with Bcounter3,Acounter3,N0thruNx [CreateNBuffer]'needed:PLL,ncounter,fcounter,preselector if PLL = 2325 then gosub [Create2325N]'needs:ncounter,preselector; creates LMX2325 N Buffer ver111 if PLL = 2326 then gosub [Create2326N]'needs:ncounter ; creates LMX2326 N Buffer ver111 if PLL = 2350 then gosub [Create2350N]'needs:ncounter,preselector,fcounter; creates LMX2350 RFN Buffer ver111 if PLL = 2353 then gosub [Create2353N]'needs: ncounter,preselector,fcounter; creates LMX2353 N Buffer ver111 if PLL = 4112 then gosub [Create4112N]'needs:ncounter,preselector; creates AD4112 N Buffer ver111 return 'with Bcounter,Acounter, and N Bits N0-N23 [Command2325R]'needed:rcounter,preselector,control,Jcontrol,port,LEPLL,contclear ; commands LMX2325 rcounter and registers if rcounter <3 then beep:errora$ = "2325 Rcounter is < 3":return 'with errora$ ver111-37c if rcounter >16383 then beep:errora$ = "2325 Rcounter is > 16383":return 'with errora$ ver111-37c N0 = 1 'address bit, 0 sets the N Buffer, 1 is for R Buffer rc1 = int(rcounter/2):N1 = rcounter - 2*rc1 'binary conversion from decimal rc2 = int(rc1/2):N2 = rc1 - 2*rc2 rc3 = int(rc2/2):N3 = rc2 - 2*rc3 rc4 = int(rc3/2):N4 = rc3 - 2*rc4 rc5 = int(rc4/2):N5 = rc4 - 2*rc5 rc6 = int(rc5/2):N6 = rc5 - 2*rc6 rc7 = int(rc6/2):N7 = rc6 - 2*rc7 rc8 = int(rc7/2):N8 = rc7 - 2*rc8 rc9 = int(rc8/2):N9 = rc8 - 2*rc9 rc10 = int(rc9/2):N10 = rc9 - 2*rc10 rc11 = int(rc10/2):N11 = rc10 - 2*rc11 rc12 = int(rc11/2):N12 = rc11 - 2*rc12 rc13 = int(rc12/2):N13 = rc12 - 2*rc13 rc14 = int(rc13/2):N14 = rc13 - 2*rc14 N15 = 1: if preselector = 64 then N15 = 0 'sets preselector divide ratio, 1=32, 0=64 gosub [CommandPLL]'needs:N23-N0,control,Jcontrol,port,contclear,LEPLL ; commands N23-N0,old ControlBoard ver111 return [Create2325N]'needed:ncounter,preselector; creates LMX2325 n buffer Bcounter = int(ncounter/preselector) Acounter = ncounter- (Bcounter * preselector) if Bcounter<3 then beep:errora$ = "2325 Bcounter < 3":return 'with errora$ ver111-37c if Bcounter>2047 then beep:errora$ = "2325 Bcounter > 2047":return 'with errora$ ver111-37c if Bcounter16383 then beep:errora$="2326 R counter >16383":return 'with errora$ ver111-37c N0 = 0 'R address bit 0, must be 0 N1 = 0 'R address vit 1, must be 0 ra0 = int(rcounter/2):N2 = rcounter- 2*ra0 'LSB ra1 = int(ra0/2):N3 = ra0- 2*ra1 ra2 = int(ra1/2):N4 = ra1- 2*ra2 ra3 = int(ra2/2):N5 = ra2- 2*ra3 ra4 = int(ra3/2):N6 = ra3- 2*ra4 ra5 = int(ra4/2):N7 = ra4- 2*ra5 ra6 = int(ra5/2):N8 = ra5- 2*ra6 ra7 = int(ra6/2):N9 = ra6- 2*ra7 ra8 = int(ra7/2):N10 = ra7- 2*ra8 ra9 = int(ra8/2):N11 = ra8- 2*ra9 ra10 = int(ra9/2):N12 = ra9- 2*ra10 ra11 = int(ra10/2):N13 = ra10- 2*ra11 ra12 = int(ra11/2):N14 = ra11- 2*ra12 ra13 = int(ra12/2):N15 = ra12- 2*ra13 'MSB N16 = 0 'Test Bit N17 = 0 'Test Bit N18 = 0 'Test Bit N19 = 0 'Test Bit N20 = 0 'Lock Detector Mode, 0=3 refcycles, 1=5 cycles '[Command2326Rbuffer]'need Jcontrol,LEPLL,contclear gosub [CommandPLL]'needs:N23-N0,control,Jcontrol,port,contclear,LEPLL ; commands N23-N0,old ControlBoard ver111 return [Create2326N]'needed:ncounter ; creates LMX2326 n buffer ver111 Bcounter = int(ncounter/32) Acounter = int(ncounter-(Bcounter*32)) if Bcounter < 3 then beep:errora$="2326 Bcounter <3":return 'with errora$ ver111-37c if Bcounter > 8191 then beep:errora$="2326 Bcounter >8191":return 'with errora$ ver111-37c if Bcounter < Acounter then beep:errora$="2326 Bcounter 32767 then beep:errora$="2350 Rcounter >32767":return 'with errora$ ver111-37c N0=0 '2350 RF_R register, 2 bits, must be 0 N1=1 '2350 RF_R register, 2 bits, must be 1 rfra2 = int(rcounter/2):N2 = rcounter- 2*rfra2 rfra3 = int(rfra2/2):N3 = rfra2- 2*rfra3 rfra4 = int(rfra3/2):N4 = rfra3- 2*rfra4 rfra5 = int(rfra4/2):N5 = rfra4- 2*rfra5 rfra6 = int(rfra5/2):N6 = rfra5- 2*rfra6 rfra7 = int(rfra6/2):N7 = rfra6- 2*rfra7 rfra8 = int(rfra7/2):N8 = rfra7- 2*rfra8 rfra9 = int(rfra8/2):N9 = rfra8- 2*rfra9 rfra10 = int(rfra9/2):N10 = rfra9- 2*rfra10 rfra11 = int(rfra10/2):N11 = rfra10- 2*rfra11 rfra12 = int(rfra11/2):N12 = rfra11- 2*rfra12 rfra13 = int(rfra12/2):N13 = rfra12- 2*rfra13 rfra14 = int(rfra13/2):N14 = rfra13- 2*rfra14 rfra15 = int(rfra14/2):N15 = rfra14- 2*rfra15 rfra16 = int(rfra15/2):N16 = rfra15- 2*rfra16 N17 = phasepolarity 'RF phase polarity, 1=positive action, 0=inverted action N18=1 'LSB of RF charge pump sel, 4 Bits, 16 levels, 100ua/level N19=1 'total current = (100ua * bit value)+100ua N20=1 '100ua to 1600ua: ie, 800ua = 0111, 1600ua = 1111 N21=1 'MSB of RF charge pump sel, 4 Bits 100ua/bit N22=0 'V2 enable voltage doubler =1 0=norm Vcc N23 = fractional 'DLL mode, delay line cal, 0=slow 1=fast,fractional mode '[CommandRFRbuffer2350] gosub [CommandPLL]'needs:N23-N0,control,Jcontrol,port,contclear,LEPLL ; commands N23-N0,old ControlBoard ver111 return [Create2350N]'needed: ncounter,preselector,fcounter; creates LMX2350 RFN Buffer Bcounter = int(ncounter/preselector) Acounter = int(ncounter-(Bcounter*preselector)) if Bcounter < 3 then beep:errora$="2350 Bcounter <3":return 'with errora$ ver111-37c if Bcounter > 1023 then beep:errora$="2350 Bcounter >1023":return 'with errora$ ver111-37c if Bcounter < Acounter + 2 then beep:errora$="2350 Bcounter32767 then beep:errora$ = "2353 Rcounter is > 32767":return 'with errora$ ver111-37c N0 = 0 'R address bit 0 N1 = 1 'R address bit 1 ra0 = int(rcounter/2):N2 = rcounter- 2*ra0 'LSB R buffer ra1 = int(ra0/2):N3 = ra0- 2*ra1:ra2 = int(ra1/2):N4 = ra1- 2*ra2 ra3 = int(ra2/2):N5 = ra2- 2*ra3:ra4 = int(ra3/2):N6 = ra3- 2*ra4 ra5 = int(ra4/2):N7 = ra4- 2*ra5:ra6 = int(ra5/2):N8 = ra5- 2*ra6 ra7 = int(ra6/2):N9 = ra6- 2*ra7:ra8 = int(ra7/2):N10 = ra7- 2*ra8 ra9 = int(ra8/2):N11 = ra8- 2*ra9:ra10 = int(ra9/2):N12 = ra9- 2*ra10 ra11 = int(ra10/2):N13 = ra10- 2*ra11:ra12 = int(ra11/2):N14 = ra11- 2*ra12 ra13 = int(ra12/2):N15 = ra12- 2*ra13:ra14 = int(ra13/2):N16 = ra13- 2*ra14 'MSB R buffer N17 = phasepolarity 'phase detector polarity 1=normal,0=reverse for opamp N18 = 1 'LSB of Charge pump control, 100ua x1 +100ua N19 = 1 'Charge pump control, 100ua x2 +100ua N20 = 1 'Charge pump control, 100ua x4 +100ua N21 = 1 'MSB of Charge pump control, 100ua x8 +100ua N22 = 0 'Charge Pump Voltage Doubler Enabled when 1 N23 = fractional 'Delay Line Loop Cal mode, set to 1 for fractional N '[Cmd2353Rbuffer] gosub [CommandPLL]'needs:N23-N0,control,Jcontrol,port,contclear,LEPLL ; commands N23-N0,old ControlBoard ver111 return [Create2353N]'needed: ncounter,preselector,fcounter; creates LMX2353 N Buffer Bcounter = int(ncounter/preselector) Acounter = int(ncounter-(Bcounter*preselector)) if Bcounter < 3 then beep:errora$ = "2353 Bcounter is < 3":return 'with errora$ ver111-37c if Bcounter > 1023 then beep:errora$ = "2353 Bcounter is > 1023":return 'with errora$ ver111-37c if Bcounter < Acounter + 2 then beep:errora$ = "2353 Bcounter < Acounter+2":return 'with errora$ ver111-37c N0 = 1 'n address bit 0 N1 = 1 'n address bit 1 f0 = int(fcounter/2):N2 = fcounter - 2*f0 'fcounter bit 0 f1 = int(f0/2):N3 = f0 - 2*f1 'fcounter bit 1 f2 = int(f1/2):N4 = f1 - 2*f2 'fcounter bit 2 f3 = int(f2/2):N5 = f2 - 2*f3 'fcounter bit 3 (0 to 15) na0 = int(Acounter/2):N6 = Acounter- 2*na0 'Acounter bit 0 LSB na1 = int(na0/2):N7 = na0 - 2*na1 na2 = int(na1/2):N8 = na1 - 2*na2 na3 = int(na2/2):N9 = na2 - 2*na3 na4 = int(na3/2):N10 = na3 - 2*na4 'Acounter bit 4 MSB nb0 = int(Bcounter/2):N11 = Bcounter- 2*nb0 'Bcounter bit 0 LSB nb1 = int(nb0/2):N12 = nb0 - 2*nb1 nb2 = int(nb1/2):N13 = nb1 - 2*nb2 nb3 = int(nb2/2):N14 = nb2 - 2*nb3 nb4 = int(nb3/2):N15 = nb3 - 2*nb4 nb5 = int(nb4/2):N16 = nb4 - 2*nb5 nb6 = int(nb5/2):N17 = nb5 - 2*nb6 nb7 = int(nb6/2):N18 = nb6 - 2*nb7 nb8 = int(nb7/2):N19 = nb7 - 2*nb8 nb9 = int(nb8/2):N20 = nb8 - 2*nb9 'Bcounter bit 9 MSB N21 = 0 :if preselector = 32 then N21 = 1 '0=16/17 1=32/33 N22 = 0 'power down if 1 N23 = 0 'counter reset if 1 return [Command4112R]'needed: rcounter,preselector,phasepolarity,control,Jcontrol,port,LEPLL,contclear ; commands AD4112 rcounter '[Create4112InitBuffer]'needed:preselector,phasepolarity N23=1 'N24,23 prescaler: 0=8, 1=16, 2=32, 3=64 N22=0 'preselector defaulted to 32 if preselector =8 then N23=0:N22=0 if preselector =16 then N23=0:N22=1 if preselector =64 then N23=1:N22=1 N21=0 'Power Down Mode, 0=async, 1=sync use 0 N20=1 'N22,21,20 Phase Current for Set 2 N19=1 'current= min current + min current*bit value N18=1 'use bit value of 7 and 4.7 Kohm for 5.0 ma N17=1 'N18,17,16 Phase Current for Set 1 N16=1 'current= min current + min current*bit value N15=1 'use bit value of 7 and 4.7 Kohm for 5.0 ma N14=0 'N15,14,13,12 Fastlock Timer cycles N13=0 '4 Bits, Cycles= 3 cycles + 4*bit value N12=0 'Fastlock Time out value, use 0 N11=0 'use 4 bit value = 0 N10=0 '0=Fastlock Mode 1 (command), 1=Mode 2 (automatic) N9=0 '1=Fastlock enabled, 0 =Fastlock Disabled N8=0 '1=Tristate the phase det output, use 0 N7 = phasepolarity 'Phase det polarity, 1=pos 0=neg N6=0 'FoLD control(pin14 output), 0= tristate, 1= Digital Lock Detect N5=0 '2= N Divider out, 3= High output, 4= R Divider output N4=0 '5= Open drain lock detect, 6= Serial Data output, 7= Low output N3=0 'PD1, Power Down, 0=normal operation, 1=select power down mode N2=0 '1= Counter Reset Enable, allows reset of R,N counters,use 0 N1=1 'F1 address bit 1, must be 1 N0=1 'F1 address bit 0, must be 1 '[Command4112InitBuffer] gosub [CommandPLL]'needs:N23-N0,control,Jcontrol,port,contclear,LEPLL ; commands N23-N0,old ControlBoard ver111 '[Create4112Rbuffer]'needs:rcounter if rcounter >16383 then beep:errora$="4112 R counter >16383":return 'with errora$ ver111-37c N0 = 0 'R address bit 0, must be 0 N1 = 0 'R address vit 1, must be 0 ra0 = int(rcounter/2):N2 = rcounter- 2*ra0 'LSB R0 ra1 = int(ra0/2):N3 = ra0- 2*ra1 ra2 = int(ra1/2):N4 = ra1- 2*ra2 ra3 = int(ra2/2):N5 = ra2- 2*ra3 ra4 = int(ra3/2):N6 = ra3- 2*ra4 ra5 = int(ra4/2):N7 = ra4- 2*ra5 ra6 = int(ra5/2):N8 = ra5- 2*ra6 ra7 = int(ra6/2):N9 = ra6- 2*ra7 ra8 = int(ra7/2):N10 = ra7- 2*ra8 ra9 = int(ra8/2):N11 = ra8- 2*ra9 ra10 = int(ra9/2):N12 = ra9- 2*ra10 ra11 = int(ra10/2):N13 = ra10- 2*ra11 ra12 = int(ra11/2):N14 = ra11- 2*ra12 ra13 = int(ra12/2):N15 = ra12- 2*ra13 'MSB N16 = 0 'N17,16 Antibacklash width N17 = 0 '0=3ns, 1=1.5ns, 2=6ns, 3=3ns N18 = 0 'Test Bit, use 0 N19 = 0 'Test Bit, use 0 N20 = 0 'Lock Detector Mode, 0=3 refcycles, 1=5 cycles N21 = 0 'resyncronization enable 0=normal, 1=resync prescaler N22 = 1 '0=resync with nondelayed rf input, 1=resync with delayed rf N23 = 0 'reserved, use 0 '[Command4112Rbuffer] gosub [CommandPLL]'needs:N23-N0,control,Jcontrol,port,contclear,LEPLL ; commands N23-N0,old ControlBoard ver111 return '[endCommand4112R] [Create4112N]'needed: ncounter,preselector; creates AD4112 N Buffer Bcounter = int(ncounter/preselector) Acounter = int(ncounter-(Bcounter*preselector)) if Bcounter < 3 then beep:errora$="4112 N counter <3":return 'with errora$ ver111-37c if Bcounter > 8191 then beep:errora$="4112 N counter >8191":return 'with errora$ ver111-37c if Bcounter < Acounter then beep:errora$="4112 B counter= .5 then base = base + 1 'round off to whole number 'now, the actual ddsoutput can be determined by: ddsoutput = base*ddsclock/2^32 'Create Parallel Words 'needed:base w0= 0 'a "1" here will activate the x4 internal multiplier, but not recommended w1= int(base/2^24) 'w1 thru w4 converts decimal base code to 4 words, each are 8 bit binary w2= int((base-(w1*2^24))/2^16) w3= int((base-(w1*2^24)-(w2*2^16))/2^8) w4= int(base-(w1*2^24)-(w2*2^16)-(w3*2^8)) 'Create Serial Bits'needed:base ; creates serial word bits; sw0 thru sw39 b0 = int(base/2):sw0 = base - 2*b0 'LSB, Freq-b0. sw is serial word bit b1 = int(b0/2):sw1 = b0 - 2*b1:b2 = int(b1/2):sw2 = b1 - 2*b2 b3 = int(b2/2):sw3 = b2 - 2*b3:b4 = int(b3/2):sw4 = b3 - 2*b4 b5 = int(b4/2):sw5 = b4 - 2*b5:b6 = int(b5/2):sw6 = b5 - 2*b6 b7 = int(b6/2):sw7 = b6 - 2*b7:b8 = int(b7/2):sw8 = b7 - 2*b8 b9 = int(b8/2):sw9 = b8 - 2*b9:b10 = int(b9/2):sw10 = b9 - 2*b10 b11 = int(b10/2):sw11 = b10 - 2*b11:b12 = int(b11/2):sw12 = b11 - 2*b12 b13 = int(b12/2):sw13 = b12 - 2*b13:b14 = int(b13/2):sw14 = b13 - 2*b14 b15 = int(b14/2):sw15 = b14 - 2*b15:b16 = int(b15/2):sw16 = b15 - 2*b16 b17 = int(b16/2):sw17 = b16 - 2*b17:b18 = int(b17/2):sw18 = b17 - 2*b18 b19 = int(b18/2):sw19 = b18 - 2*b19:b20 = int(b19/2):sw20 = b19 - 2*b20 b21 = int(b20/2):sw21 = b20 - 2*b21:b22 = int(b21/2):sw22 = b21 - 2*b22 b23 = int(b22/2):sw23 = b22 - 2*b23:b24 = int(b23/2):sw24 = b23 - 2*b24 b25 = int(b24/2):sw25 = b24 - 2*b25:b26 = int(b25/2):sw26 = b25 - 2*b26 b27 = int(b26/2):sw27 = b26 - 2*b27:b28 = int(b27/2):sw28 = b27 - 2*b28 b29 = int(b28/2):sw29 = b28 - 2*b29:b30 = int(b29/2):sw30 = b29 - 2*b30 b31 = int(b30/2):sw31 = b30 - 2*b31 'MSB, Freq-b31 sw32 = 0 'x4 multiplier, 1=enable, but not recommended sw33 = 0 'control bit sw34 = 0 'power down bit sw35 = 0 'phase data sw36 = 0 'phase data sw37 = 0 'phase data sw38 = 0 'phase data sw39 = 0 'phase data return '[endCreateBaseForDDSarray] [ResetDDS1par]'needed:control,STRBAUTO,contclear ; resets DDS1 on J5(OrigControlBd), into parallel mode out control, STRBAUTO 'wclk and fqud lines high, causing DDS "Reset" line to go high out control, contclear 'wclk and fqud lines low (all control lines low) return [ResetDDS1ser]'(old Control)'needed:control,AUTO,STRB,contclear ; resets DDS1 on J5, into serial mode ver111-21 'it must be understood that DDS (AD9850) pin 2(D2) is low and pins 3,4 are high(D0,D1), other data pins are don't care. out port, 3 'set DDSpins 3 and 4 high out control, STRB:out control, contclear ' DDSpin8, FQUD up, FQUD down. DDS register pointer will reset out control, AUTO:out control, contclear ' DDSpin9, WCLK up, DDS WCLK down out control, STRB:out control, contclear ' DDSpin8, FQUD up, FQUD down. DDS will go to 0 Hz. out port, 0 'data lines low return [ResetDDS1serSLIM]'reset serial DDS1 without disturbing Filter Bank or PDM. ver111-29 'must have DDS (AD9850) pin 2(D2) low, and pins 3,4 high(D0,D1), other data pins are don't care. pdmcmd = phaarray(thisstep,0) 'ver111-39d out port, pdmcmd*64 + 2 'apply last known pdmcmd and D1 to buffer. ver111-39d out control, INIT 'DDSpin8, FQUD up. DDS register pointer will reset out port, pdmcmd*64 'DDSpin8, FQUD down. ver111-29 out control, contclear 'disable buffer out port, filtbank + 1 'apply last known filter path and D0 to buffer out control, SELT 'DDSpin9, WCLK up out port, filtbank 'DDSpin9, WCLK down out control, contclear 'disable buffer out port, pdmcmd*64 + 2 'apply last known pdmcmd and D1 to buffer. ver111-29 out control, INIT 'DDSpin8, FQUD up. DDS will go to 0 Hz. out port, pdmcmd*64 'DDSpin8, FQUD down. ver111-29 out control, contclear 'disable buffer return 'to '[InitializeDDS1] [ResetDDS3ser]'needed:port,control,Jcontrol,swclk,sfqud,contclear ; resets DDS, serially 'it must be understood that DDS (AD9850) pin 2(D2) is low and pins 3,4 are high(D0,D1), other data pins are don't care. out control, Jcontrol 'enable Control Board J connector out port, sfqud:out port, 0 ' DDSpin8, FQUD up, FQUD down. DDS register pointer will reset out port, swclk:out port, 0 ' DDSpin9, WCLK up, DDS WCLK down out port, sfqud:out port, 0 ' DDSpin8, FQUD up, FQUD down. DDS will go to 0 Hz. out control, contclear 'disable Control Board J connector return [ResetDDS3serSLIM]'reset serial DDS3 without disturbing Filter Bank or PDM. ver111-29 'must have DDS (AD9850) pin 2(D2) low, and pins 3,4 high(D0,D1), other data pins are don't care. pdmcmd = phaarray(thisstep,0) 'ver111-39d out port, pdmcmd*64 + 8 'apply last known pdmcmd and D3 to buffer ver111-29.ver111-39d out control, INIT 'DDSpin8, FQUD up. DDS register pointer will reset out port, pdmcmd*64 'DDSpin8, FQUD down.ver111-39d out control, contclear 'disable buffer out port, filtbank + 1 'apply last known filter path and D0 to buffer out control, SELT 'DDSpin9, WCLK up out port, filtbank 'DDSpin9, WCLK down out control, contclear 'disable buffer out port, pdmcmd*64 + 8 'apply last known pdmcmd and D3 to buffer ver111-29.ver111-39d out control, INIT 'DDSpin8, FQUD up. DDS will go to 0 Hz. out port, pdmcmd*64 'DDSpin8, FQUD down.ver111-39d out control, contclear 'disable buffer return 'to '(InitializeDDS 3) [CreateGraphMSA] 'for Spectrum Analyzer WindowWidth = windowwide WindowHeight = graphhigh UpperLeftX = 1 'the Graph window upper left corner is 1 pixel right.. UpperLeftY = 1 '...and 1 pixel down from the upper left of the screen open "Graph Window for MSA/VNA, Spectrum Analyzer Mode - version 111" for graphics_nsb as #handle print #handle, "when leftButtonDown [LeftButDown]" print #handle, "when rightButtonDown [RightButDown]" print #handle, "trapclose [finished]" 'goto [finished] if xit is clicked print #handle, "down" 'ready to draw print #handle, "line ";0;" ";y;" ";x;" ";y 'draw baseline print #handle, "line ";" ";x/2;" ";y;" ";x/2;" ";y+10 'draw center tickmark ticks = abs(steps/10) for tick = 0 to ticks print #handle, "line ";" ";x*tick/ticks;" ";y;" ";x*tick/ticks;" ";y+5 next tick 'this will draw a tickmark every 10 steps print #handle, "line ";0;" ";y-maxscale;" ";x;" ";y-maxscale 'draw a reference line for top power print #handle, "\";topref;" dBm" 'print reference pwr level print #handle, "line ";0;" ";y-.9*maxscale;" ";x;" ";y-.9*maxscale print #handle, "\";topref - .1*(topref - botref);" dBm" print #handle, "line ";0;" ";y-.8*maxscale;" ";x;" ";y-.8*maxscale print #handle, "\";topref - .2*(topref - botref);" dBm" print #handle, "line ";0;" ";y-.7*maxscale;" ";x;" ";y-.7*maxscale print #handle, "\";topref - .3*(topref - botref);" dBm" print #handle, "line ";0;" ";y-.6*maxscale;" ";x;" ";y-.6*maxscale print #handle, "\";topref - .4*(topref - botref);" dBm" print #handle, "line ";0;" ";y-.5*maxscale;" ";x;" ";y-.5*maxscale print #handle, "\";topref - .5*(topref - botref);" dBm" print #handle, "line ";0;" ";y-.4*maxscale;" ";x;" ";y-.4*maxscale print #handle, "\";topref - .6*(topref - botref);" dBm" print #handle, "line ";0;" ";y-.3*maxscale;" ";x;" ";y-.3*maxscale print #handle, "\";topref - .7*(topref - botref);" dBm" print #handle, "line ";0;" ";y-.2*maxscale;" ";x;" ";y-.2*maxscale print #handle, "\";topref - .8*(topref - botref);" dBm" print #handle, "line ";0;" ";y-.1*maxscale;" ";x;" ";y-.1*maxscale print #handle, "\";topref - .9*(topref - botref);" dBm" print #handle, "line ";0;" ";y;" ";x;" ";y print #handle, "\";botref;" dBm" print #handle, "place 205 380" print #handle, "\ Center Frequency is: "; centfreq; " MHz Sweep Width is: ";sweepwidth;" MHz" print #handle, "flush" 'make the graph lines stick return [CreateGraphVNA] 'for Vector Network Analyzer WindowWidth = windowwide WindowHeight = graphhigh UpperLeftX = 1 'the Graph window upper left corner is 1 pixel right.. UpperLeftY = 1 '...and 1 pixel down from the upper left of the screen open "Graph Window for MSA/VNA, Vector Network Analyzer Mode - version 111" for graphics_nsb as #handle print #handle, "when leftButtonDown [LeftButDown]" print #handle, "when rightButtonDown [RightButDown]" print #handle, "trapclose [finished]" 'goto [finished] if xit is clicked print #handle, "down" 'ready to draw print #handle, "line ";0;" ";y;" ";x;" ";y 'draw baseline print #handle, "line ";" ";x/2;" ";y;" ";x/2;" ";y+10 'draw center tickmark ticks = abs(steps/10) for tick = 0 to ticks print #handle, "line ";" ";x*tick/ticks;" ";y;" ";x*tick/ticks;" ";y+5 next tick 'this will draw a tickmark every 10 steps print #handle, "line ";0;" ";y-maxscale;" ";x;" ";y-maxscale 'draw a reference line for top power print #handle, "\";topref;" dB" 'print reference pwr level print #handle, "line ";0;" ";y-.9*maxscale;" ";x;" ";y-.9*maxscale print #handle, "\";topref - .1*(topref - botref);" dB" print #handle, "line ";0;" ";y-.8*maxscale;" ";x;" ";y-.8*maxscale print #handle, "\";topref - .2*(topref - botref);" dB" print #handle, "line ";0;" ";y-.7*maxscale;" ";x;" ";y-.7*maxscale print #handle, "\";topref - .3*(topref - botref);" dB" print #handle, "line ";0;" ";y-.6*maxscale;" ";x;" ";y-.6*maxscale print #handle, "\";topref - .4*(topref - botref);" dB" print #handle, "line ";0;" ";y-.5*maxscale;" ";x;" ";y-.5*maxscale print #handle, "\";topref - .5*(topref - botref);" dB" print #handle, "line ";0;" ";y-.4*maxscale;" ";x;" ";y-.4*maxscale print #handle, "\";topref - .6*(topref - botref);" dB" print #handle, "line ";0;" ";y-.3*maxscale;" ";x;" ";y-.3*maxscale print #handle, "\";topref - .7*(topref - botref);" dB" print #handle, "line ";0;" ";y-.2*maxscale;" ";x;" ";y-.2*maxscale print #handle, "\";topref - .8*(topref - botref);" dB" print #handle, "line ";0;" ";y-.1*maxscale;" ";x;" ";y-.1*maxscale print #handle, "\";topref - .9*(topref - botref);" dB" print #handle, "line ";0;" ";y;" ";x;" ";y print #handle, "\";botref;" dB" print #handle, "place 205 380" print #handle, "\ Center Frequency is: "; centfreq; " MHz Sweep Width is: ";sweepwidth;" MHz" print #handle, "place 2 40" print #handle, "color red" print #handle, "\";topphase;" Deg." print #handle, "place 2 320" print #handle, "\";botphase;" Deg." print #handle, "color black" print #handle, "flush" 'make the graph lines stick return [Reprintlines] print #handle, "color black" 'ver111-25 print #handle, "line ";0;" ";y-maxscale;" ";x;" ";y-maxscale 'draw a reference line for top power print #handle, "line ";0;" ";y-.9*maxscale;" ";x;" ";y-.9*maxscale print #handle, "line ";0;" ";y-.8*maxscale;" ";x;" ";y-.8*maxscale print #handle, "line ";0;" ";y-.7*maxscale;" ";x;" ";y-.7*maxscale print #handle, "line ";0;" ";y-.6*maxscale;" ";x;" ";y-.6*maxscale print #handle, "line ";0;" ";y-.5*maxscale;" ";x;" ";y-.5*maxscale print #handle, "line ";0;" ";y-.4*maxscale;" ";x;" ";y-.4*maxscale print #handle, "line ";0;" ";y-.3*maxscale;" ";x;" ";y-.3*maxscale print #handle, "line ";0;" ";y-.2*maxscale;" ";x;" ";y-.2*maxscale print #handle, "line ";0;" ";y-.1*maxscale;" ";x;" ";y-.1*maxscale print #handle, "line ";0;" ";y;" ";x;" ";y print #handle, "flush" 'make the graph lines stick return [createWorkingWindow]'from [SetUpWorkingWindow] WindowWidth = windowwide 'the Working window is 800 pixels wide WindowHeight = windowhigh 'the Working window is 180 pixels in height UpperLeftX = 1 'the Working window upper left corner is 1 pixels right.. UpperLeftY = 415 '...and 415 pixels down from the upper left corner of the monitor screen BackgroundColor$ = "darkblue" ForegroundColor$ = "white" statictext #main.message, "Message:", 5, 5, 50, 15 statictext #main.finalif, "Final I.F.", 5, 65, 40, 12 statictext #main.centerfreq, "Center Frequency", 323, 1, 120, 12 statictext #main.centerfreq2, "MHz", 408, 18, 30, 12 statictext #main.placemarkers, "Place Markers at Steps:", 598, 1, 120, 12 statictext #main.topref, "Top Ref Line", 725, 1, 70, 12 statictext #main.topref2, "dBm", 765, 18, 30, 12 statictext #main.filter, "Select Final Filter Path:", 5, 25, 130, 12 statictext #main.sweepwidth, "Sweep Width:", 320, 40, 80, 12 statictext #main.sweepwidth2, "MHz", 383, 59, 30, 12 statictext #main.stepspersweep, "Steps/Sweep", 415, 40, 80, 12 statictext #main.stepspersweep2, "1-720", 460, 59, 40, 12 statictext #main.mhzperstep, "MHz/Step:", 530, 40, 80, 12 statictext #main.waittime, "Wait (ms)", 635, 40, 60, 12 'ver111-27 statictext #main.botref, "Bot Ref Line", 725, 40, 70, 12 statictext #main.botref2, "dBm", 765, 59, 30, 12 statictext #main.resolutionbw, "Res. B.W.", 5, 88, 50, 12 statictext #main.thisstep, "Step", 235, 90, 50, 15 statictext #main.thisfreq, "This Freq", 283, 90, 50, 15 statictext #main.thispower, "Power (dBm)", 385, 90, 60, 15 statictext #main.leftclick, "LeftClick", 170, 110, 50, 12 statictext #main.rightclick, "RightClick", 170, 133, 50, 15 TextboxColor$ = "red" 'the following textboxes will be red textbox #main.centerfreqbox, 325, 15, 80, 20 ' create Center Freq box textbox #main.marker1box, 600, 15, 30, 20 'create Marker box 1 textbox #main.marker2box, 640, 15, 30, 20 'create Marker box 2 textbox #main.marker3box, 680, 15, 30, 20 'create Marker box 3 textbox #main.toprefbox, 725, 15, 35, 20 'create top reference line box textbox #main.sweepwidthbox, 325, 55, 55, 20 'create Sweep Width box textbox #main.stepspersweepbox, 420, 55, 35, 20 'create Steps per Sweep box textbox #main.botrefbox, 725, 55, 35, 20 'create bottom reference linebox TextboxColor$ = "brown" 'the following textboxes will be brown ver111-22 textbox #main.waitbox, 640, 55, 35, 20 ' create Wait box TextboxColor$ = "blue" 'the following textboxes will be blue textbox #main.msgbox, 65, 3, 165, 20 ' create Message box textbox #main.finalifbox, 65, 62, 65, 20 ' create Final IF box textbox #main.resolutionbox, 65, 86, 65, 20 ' create Resolution BW box textbox #main.mhzperstepbox, 522, 55, 80, 20 'create MHz per step box textbox #main.stepnobox, 230, 106, 35, 20 'create step box textbox #main.thisfreqbox, 270, 106, 75, 20 'create This Freq box textbox #main.thispowerbox, 385, 106, 65, 20 'create Power box textbox #main.stepnobox2, 230, 130, 35, 20 'create step box textbox #main.thisfreqbox2, 270, 130, 75, 20 'create This Freq box textbox #main.thispowerbox2, 385, 130, 65, 20 'create Power box button #main.f1button, "F1", [button1], UL, 5, 38, 25, 20 button #main.f2button, "F2", [button2], UL, 35, 38, 25, 20 button #main.f3button, "F3", [button3], UL, 65, 38, 25, 20 button #main.f4button, "F4", [button4], UL, 95, 38, 25, 20 button #main.centerbutton, "Cent", [centerbutton], UL, 350, 106, 30, 20 button #main.onestep, "One Step", [OneStep], UL, 720, 80, 65, 20 'moved ver111-24 button #main.continue, "Continue", [Continue], UL, 720, 105, 65, 20 button #main.restart, "Running", [Restart], UL, 720, 130, 65, 20 'changed to "Running" ver111-30c button #main.showvar, "Show Variables", [Showvar], UL, 150, 38, 80, 20 button #main.spurbutton, "Spur Test is OFF", [Spurtest], UL, 522, 80, 95, 20 'ver111-17 if TGtop > 0 then button #main.govna, "Go-VNA Mode", [GoVNAmode], UL, 150, 63, 80, 20 if TGtop = 2 then gosub [CreateButtonsNewTG] 'ver111-17 if TGtop = 1 then gosub [CreateButtonsOldTG] 'ver111-17 button #main.magdisp, "Histo Erase", [ChangeMagDisplayMSA], UL, 640, 80, 65, 20 'ver111-24 button #main.special, "Special Tests", [SpecialTests], UL, 5, 113, 75, 20 'ver111-36b magdisp = 3 'ver111-24 phadisp = 0 'ver111-24 open "Working Window for MSA/VNA, Spectrum Analyzer Mode - version 111" for dialog as #main print #main, "trapclose [finished]" 'goto [finished] if xit is clicked print #main.finalifbox, "";finalfreq;" MHz" 'default final I.F. freq print #main.resolutionbox, "";finalbw;" KHz" 'default resolution BW print #main.centerfreqbox, "";centfreq 'default center freq print #main.sweepwidthbox, "";sweepwidth 'default sweep width print #main.stepspersweepbox, "";steps 'default steps per sweep print #main.marker1box, "";marker1 'insert marker1 default in Marker1 box print #main.marker2box, "";marker2 'insert marker2 default in Marker2 box print #main.marker3box, "";marker3 'insert marker3 default in Marker3 box print #main.waitbox, "";wate 'insert wate default, or last "wate" into wait box print #main.toprefbox, "";topref 'insert default top reference line print #main.botrefbox, "";botref 'insert default bottom reference line if TGtop = 2 then print #main.freqoffbox, "";sgpreset 'ver111-18 if TGtop = 1 then print #main.freqoffbox, "";offset 'ver111-18 return [CreateButtonsNewTG] 'ver111-17 gentrk = 0 'when 0, in Signal Generator Mode, ie. LO3 remains fixed frequency at a default frequency normrev = 0 'make sure LO3 doesn't reverse during start-up button #main.sigenbutton, "Signal Generator", [SignalGeneratorbutton], UL, 460, 106, 100, 20 'ver111-17 button #main.presetbutton, "Preset", [Presetbutton], UL, 570, 106, 48, 20 'ver111-18 statictext #main.enterfreqtxt, "Enter Freq", 460, 133, 68, 15 'ver111-26 TextboxColor$ = "red" 'the following textboxes will be red textbox #main.freqoffbox, 538, 130, 72, 20 'create box for Sig Gen freq or Trk Gen offset freq'ver111-17 statictext #main.freqenter, "MHz", 615, 133, 24, 15 'ver111-17 return [CreateButtonsOldTG] 'ver111-17 gentrk = 1 'may not be needed normrev = 0 'may not be needed statictext #main.sigenbutton, "Tracking Generator", 460, 106, 100, 20 'ver111-17 statictext #main.presetbutton, "Offset", 570, 106, 48, 20 'ver111-17 statictext #main.enterfreqtxt, "Enter Offset", 460, 133, 68, 15 'ver111-26 TextboxColor$ = "red" 'the following textboxes will be red textbox #main.freqoffbox, 538, 130, 72, 20 'create Offset Freq box 'ver111-17 statictext #main.freqenter, "MHz", 615, 133, 24, 15 'ver111-17 return [SignalGeneratorbutton]'selects either "Signal Generator" or "Tracking Generator" 'ver111-17 if haltsweep = 1 then goto [Halted] 'ver111-26 'this button does not exist in old TG topology. Only in new TG topology. if gentrk = 0 then print #main.sigenbutton, "Tracking Generator" if gentrk = 0 then print #main.presetbutton, "Normal":normrev = 0 if gentrk = 0 then print #main.enterfreqtxt, "Enter Offset" 'ver111-26 if gentrk = 0 then print #main.freqoffbox, "";offset if gentrk = 0 then gentrk = 1:wait if gentrk = 1 then print #main.sigenbutton, "Signal Generator" if gentrk = 1 then print #main.presetbutton, "Preset" if gentrk = 1 then print #main.enterfreqtxt, "Enter Freq" 'ver111-26 if gentrk = 1 then print #main.freqoffbox, "";sgpreset if gentrk = 1 then gentrk = 0:wait [Presetbutton]'when in Sig Gen mode, enters the SGpreset into freqoffbox 'ver111-17 if haltsweep = 1 then goto [Halted] 'ver111-26 'this button does not exist in old TG topology. Only in new TG topology. if gentrk = 1 then goto [NormRevbutton] 'if in Tracking Generator Mode, go there 'if gentrk = 1, we are in Tracking Mode. The button is labeled "Normal" or "Reverse" 'if gentrk = 0, we are in Sig Gen Mode. The button is labeled "Preset" print #main.presetbutton, "Preset":print #main.freqoffbox, "";sgpreset:wait 'this puts "sgpreset" value into freqoffbox [NormRevbutton]'when in Tracking Mode, selects either Normal or Reverse tracking 'ver111-17 'this button does not exist in old TG topology. Only in new TG topology. if normrev = 0 then print #main.presetbutton, "Reverse":normrev = 1:wait if normrev = 1 then print #main.presetbutton, "Normal":normrev = 0:wait [ChangeMagDisplayMSA] 'ver111-24 if haltsweep = 1 then goto [Halted] 'ver111-26 magdisp = magdisp + 1 if magdisp > 4 then magdisp = 0 if magdisp = 0 then print #main.magdisp, "Trace Off" if magdisp = 1 then print #main.magdisp, "Norm Erase" if magdisp = 2 then print #main.magdisp, "Norm Stick" if magdisp = 3 then print #main.magdisp, "Histo Erase" if magdisp = 4 then print #main.magdisp, "Histo Stick" wait [createWorkingWindowforVNA] WindowWidth = windowwide 'the Working window is 800 pixels wide WindowHeight = windowhigh 'the Working window is 180 pixels in height UpperLeftX = 1 'the Working window upper left corner is 1 pixels right.. UpperLeftY = 415 '...and 415 pixels down from the upper left corner of the monitor screen BackgroundColor$ = "darkred" ForegroundColor$ = "white" statictext #main.message, "Message:", 5, 5, 50, 15 statictext #main.finalif, "Final I.F.", 5, 65, 40, 12 statictext #main.centerfreq, "Center Frequency", 323, 1, 120, 12 statictext #main.phasetop, "Phase Top", 245, 1, 60, 12 statictext #main.phasetop2, "Deg.", 290, 18, 30, 15 statictext #main.phasebot, "Phase Bot", 245, 40, 60, 12 statictext #main.phasebot2, "Deg.", 290, 59, 30, 15 statictext #main.centerfreq2, "MHz", 408, 18, 30, 12 statictext #main.pdminvert, "PDM Inversion", 450,18,80,15 statictext #main.placemarkers, "Place Markers at Steps:", 598, 1, 120, 12 statictext #main.topref, "Top Ref Line", 725, 1, 70, 12 statictext #main.topref2, "dBc", 765, 18, 30, 12 statictext #main.filter, "Select Final Filter Path:", 5, 25, 130, 12 statictext #main.sweepwidth, "Sweep Width:", 320, 40, 80, 12 statictext #main.sweepwidth2, "MHz", 383, 59, 30, 12 statictext #main.stepspersweep, "Steps/Sweep", 415, 40, 80, 12 statictext #main.stepspersweep2, "1-720", 460, 59, 40, 12 statictext #main.mhzperstep, "MHz/Step:", 530, 40, 80, 12 statictext #main.waittime, "Wait (ms)", 635, 40, 60, 12 'ver111-27 statictext #main.botref, "Bot Ref Line", 725, 40, 70, 12 statictext #main.botref2, "dBc", 765, 59, 30, 12 statictext #main.resolutionbw, "Res. B.W.", 5, 88, 50, 12 statictext #main.thisstep, "Step", 235, 90, 50, 15 statictext #main.thisfreq, "This Freq", 283, 90, 50, 15 statictext #main.thispower, "Power (dBc)", 385, 90, 60, 15 statictext #main.thisphase, "Phase", 460, 90, 50, 12 statictext #main.leftclick, "LeftClick", 170, 110, 50, 12 statictext #main.rightclick, "RightClick", 170, 133, 50, 15 TextboxColor$ = "red" 'the following textboxes will be red textbox #main.phasetopbox, 255, 15, 35, 20 ' create Phase top line reference box textbox #main.phasebotbox, 255, 55, 35, 20 ' create Phase bottom line reference box textbox #main.centerfreqbox, 325, 15, 80, 20 ' create Center Freq box textbox #main.invdegbox, 530, 15, 50, 20 textbox #main.marker1box, 600, 15, 30, 20 'create Marker box 1 textbox #main.marker2box, 640, 15, 30, 20 'create Marker box 2 textbox #main.marker3box, 680, 15, 30, 20 'create Marker box 3 textbox #main.toprefbox, 725, 15, 35, 20 'create top reference line box textbox #main.sweepwidthbox, 325, 55, 55, 20 'create Sweep Width box textbox #main.stepspersweepbox, 420, 55, 35, 20 'create Steps per Sweep box textbox #main.botrefbox, 725, 55, 35, 20 'create bottom reference linebox TextboxColor$ = "brown" 'the following textboxes will be brown ver111-22 textbox #main.waitbox, 640, 55, 35, 20 ' create Wait box TextboxColor$ = "blue" 'the following textboxes will be blue textbox #main.msgbox, 65, 3, 165, 20 ' create Message box textbox #main.finalifbox, 65, 62, 65, 20 ' create Final IF box textbox #main.resolutionbox, 65, 86, 65, 20 ' create Resolution BW box textbox #main.mhzperstepbox, 522, 55, 80, 20 'create MHz per step box textbox #main.stepnobox, 230, 106, 35, 20 'create step box textbox #main.thisfreqbox, 270, 106, 75, 20 'create This Freq box textbox #main.thispowerbox, 385, 106, 65, 20 'create Power box textbox #main.thisphasebox, 455, 106, 60, 20 'create Phase box textbox #main.thisphasebox2, 455, 130, 60, 20 'create Phase box textbox #main.stepnobox2, 230, 130, 35, 20 'create step box textbox #main.thisfreqbox2, 270, 130, 75, 20 'create This Freq box textbox #main.thispowerbox2, 385, 130, 65, 20 'create Power box button #main.f1button, "F1", [button1], UL, 5, 38, 25, 20 button #main.f2button, "F2", [button2], UL, 35, 38, 25, 20 button #main.f3button, "F3", [button3], UL, 65, 38, 25, 20 button #main.f4button, "F4", [button4], UL, 95, 38, 25, 20 button #main.centerbutton, "Cent", [centerbutton], UL, 350, 106, 30, 20 gentrk = 1:normrev = 0:offset = 0 'turn on tracking generator, normal, zero offset 'ver111-17 button #main.magdisp, "Mag Erase", [ChangeMagDisplayVNA], UL, 640, 80, 65, 20 'ver111-24 magdisp = 1 'begin with mag erasing before printing ver111-24 button #main.phadisp, "Pha Erase", [ChangePhaDisplayVNA], UL, 640, 105, 65, 20 'ver111-24 phadisp = 1 'begin with phase erasing before printing ver111-24 button #main.onestep, "One Step", [OneStep], UL, 720, 80, 65, 20 'moved ver111-24 button #main.continue, "Continue", [Continue], UL, 720, 105, 65, 20 button #main.restart, "Running", [Restart], UL, 720, 130, 65, 20 'changed to "Running" ver111-30c button #main.showvar, "Show Variables", [Showvar], UL, 150, 38, 80, 20 button #main.gomsa, "Go-MSA Mode", [GoMSAmode], UL, 150, 63, 80, 20 button #main.calibfwd, "Calibrate ?", [Calfwd], UL, 150, 86, 65, 20 open "Working Window for MSA/VNA, Vector Network Analyzer Mode - version 111" for dialog as #main print #main, "trapclose [finished]" 'goto [finished] if xit is clicked print #main.finalifbox, "";finalfreq;" MHz" 'default final I.F. freq print #main.resolutionbox, "";finalbw;" KHz" 'default resolution BW print #main.centerfreqbox, "";centfreq 'default center freq print #main.sweepwidthbox, "";sweepwidth 'default sweep width print #main.stepspersweepbox, "";steps 'default steps per sweep print #main.invdegbox,invdeg print #main.marker1box, "";marker1 'insert marker1 default in Marker1 box print #main.marker2box, "";marker2 'insert marker2 default in Marker2 box print #main.marker3box, "";marker3 'insert marker3 default in Marker3 box print #main.waitbox, "";wate 'insert wate default, or last "wate" into wait box print #main.toprefbox, "";topref 'insert default top reference line print #main.botrefbox, "";botref 'insert default bottom reference line print #main.phasetopbox,180 print #main.phasebotbox,-180 return [ChangeMagDisplayVNA] 'ver111-24 if haltsweep = 1 then goto [Halted] 'ver111-26 magdisp = magdisp + 1 if magdisp > 2 then magdisp = 0 if magdisp = 0 then print #main.magdisp, "Mag Off" if magdisp = 1 then print #main.magdisp, "Mag Erase" if magdisp = 2 then print #main.magdisp, "Mag Stick" wait [ChangePhaDisplayVNA] 'ver111-24 if haltsweep = 1 then goto [Halted] 'ver111-26 phadisp = phadisp + 1 if phadisp > 2 then phadisp = 0 if phadisp = 0 then print #main.phadisp, "Pha Off" if phadisp = 1 then print #main.phadisp, "Pha Erase" if phadisp = 2 then print #main.phadisp, "Pha Stick" wait [GoMSAmode] if haltsweep = 1 then goto [Halted] 'ver111-26 vna = 0 redim calarray(800,2) 'clear out the calibration array when changing to MSA mode close #main 'close out working window for VNA close #handle 'close out Graph window for VNA gosub [CreateGraphMSA] gosub [createWorkingWindow] goto [Restart] [GoVNAmode] if haltsweep = 1 then goto [Halted] 'ver111-26 if spurcheck = 1 and PLL1mode = 0 then rcounter1=rcounter1-1:gosub [CommandPLL1R]:spurcheck = 0 'ver111-24 vna = 1 redim calarray(800,2) 'clear out the calibration array when changing to VNA mode close #main 'close out working window for SA close #handle 'close out Graph window for SA gosub [CreateGraphVNA] gosub [createWorkingWindowforVNA] goto [Restart] [calcWindowInfo] 'from [GrabWorkingWindowData] print #main.centerfreqbox, "!contents? centfreq$"; 'Center Freq box centfreq = val(centfreq$) 'change global to what user entered print #main.sweepwidthbox, "!contents? sweepwidth$"; 'Sweep Width box sweepwidth = val(sweepwidth$) 'change global to what user entered print #main.stepspersweepbox, "!contents? steps$"; 'Steps per Sweep box steps = val(steps$) 'change global to what user entered startfreq = centfreq - sweepwidth/2 'start frequency of sweep stepfreq = sweepwidth/steps 'delta step frequency print #main.mhzperstepbox, stepfreq 'MHz per step box print #main.marker1box, "!contents? mark1$"; 'Marker1 box marker1 = val(mark1$) 'change global to what user entered print #main.marker2box, "!contents? mark2$"; 'Marker2 box marker2 = val(mark2$) 'change global to what user entered print #main.marker3box, "!contents? mark3$"; 'Marker3 box marker3 = val(mark3$) 'change global to what user entered print #main.waitbox, "!contents? wate$"; 'Wait box wate = val(wate$) 'change global to what user entered print #main.toprefbox, "!contents? topref$"; 'Top reference box topref = val(topref$) 'Log Det power, in dBm print #main.botrefbox, "!contents? botref$"; 'Bottom reference box botref = val(botref$) 'Log Det power, in dBm if botref>=topref then botref = topref-10:print #main.botrefbox, "";topref-10 if vna = 0 and TGtop > 0 then print #main.freqoffbox, "!contents? freqoff$"; 'Sig Gen Freq or TG offset box data ver111-18 if vna = 0 and TGtop = 2 and gentrk = 0 then sgout = val(freqoff$) 'ver111-18 if vna = 0 and TGtop > 0 and gentrk = 1 then offset = val(freqoff$) 'ver111-18 if vna = 1 then print #main.invdegbox, "!contents? invdeg$"; if vna = 1 then invdeg = val(invdeg$) if vna = 1 then print #main.phasetopbox, "!contents? topphasescale$"; 'Top reference line from Phase Top box if vna = 1 then print #main.phasebotbox, "!contents? botphasescale$"; 'Bot reference line from Phase Bot box if vna = 1 then topphase = val(topphasescale$) 'this is the phase of the top scale ref line if vna = 1 then botphase = val(botphasescale$) 'this is the phase of the bottom scale ref line if vna = 1 and botphase>=topphase then botphase = topphase-10:print #main.phasebotbox, "";botphase if vna = 1 then centphase = (topphase+botphase)/2 'this is the phase of the center scale ref line return 'goto [endGrabWorkingWindowData] [LeftButDown] 'when left mouse button is pressed, do the following if haltsweep = 1 then goto [Halted] 'ver111-26 leftdownpixelx = MouseX if leftdownpixelx > x then leftdownpixelx=x leftstep = int(steps*leftdownpixelx/x) if (steps*leftdownpixelx/x) - leftstep >= .5 then leftstep = leftstep + 1 'rounds off 'ver111-37d print #main.stepnobox,datatable(leftstep,0) 'display "thisstep" number from most current data print #main.thisfreqbox,datatable(leftstep,1) 'display "thisfreq" from most current data print #main.thispowerbox,datatable(leftstep,2) 'display "magpower" from most current data if vna = 1 then print #main.thisphasebox,datatable(leftstep,3);" deg" 'display phase measurement from most current data if varwindow = 1 then gosub [preupdatevar] 'ver111-36h will update variables window as Mouse is clicked wait [preupdatevar] 'ver111-36h remember = thisstep thisstep = datatable(leftstep,0) gosub [updatevar] thisstep = remember return [RightButDown] 'when right mouse button is pressed, do the following if haltsweep = 1 then goto [Halted] 'ver111-26 rightdownpixelx = MouseX if rightdownpixelx > x then rightdownpixelx=x rightstep = int(steps*rightdownpixelx/x) if (steps*rightdownpixelx/x) - rightstep >= .5 then rightstep = rightstep + 1 'rounds off 'ver111-37d print #main.stepnobox2,datatable(rightstep,0) 'display "thisstep" number from most current data print #main.thisfreqbox2,datatable(rightstep,1) 'display "thisfreq" from most current data print #main.thispowerbox2,datatable(rightstep,2) 'display "magpower" from most current data if vna = 1 then print #main.thisphasebox2,datatable(rightstep,3);" deg" 'display phase measurement from most current data if leftdownpixelx = x+1 then wait 'ver111-36a lowerfreq = datatable(leftstep,1) upperfreq = datatable(rightstep,1) if lowerfreq>upperfreq then lowerfreq=datatable(rightstep,1):upperfreq=datatable(leftstep,1) newsweepwidth = upperfreq-lowerfreq newcenterfreq = lowerfreq + newsweepwidth/2 print #main.centerfreqbox, "";newcenterfreq print #main.sweepwidthbox, "";newsweepwidth wait [centerbutton]'this will take the contents of the "This Freq" box and put it in the "Center Frequency" box if haltsweep = 1 then goto [Halted] 'ver111-26 print #main.thisfreqbox, "!contents? newcentfreq$" print #main.centerfreqbox, "";newcentfreq$ wait [button1] 'command filter bank to path "1" if haltsweep = 1 then goto [Halted] 'ver111-26 finalfreq = finalfreq1 finalbw = finalbw1 A1=0 : A0=0 'ver111-29 gosub [CommandFilter] 'ver111-29 gosub [CalTablePath1] 'ver111-39a print #main.finalifbox, "";finalfreq;" MHz" print #main.resolutionbox, "";finalbw;" KHz" 'default resolution BW wait [button2] 'command filter bank to path "2" if haltsweep = 1 then goto [Halted] 'ver111-26 finalfreq = finalfreq2 finalbw = finalbw2 A1=0 : A0=1 'ver111-29 gosub [CommandFilter] 'ver111-29 gosub [CalTablePath2] 'ver111-39a print #main.finalifbox, "";finalfreq;" MHz" print #main.resolutionbox, "";finalbw;" KHz" 'default resolution BW wait [button3] 'command filter bank to path "3" if haltsweep = 1 then goto [Halted] 'ver111-26 finalfreq = finalfreq3 finalbw = finalbw3 A1=1 : A0=0 'ver111-29 gosub [CommandFilter] 'ver111-29 gosub [CalTablePath3] 'ver111-39a print #main.finalifbox, "";finalfreq;" MHz" print #main.resolutionbox, "";finalbw;" KHz" 'default resolution BW wait [button4] 'command filter bank to path "4" if haltsweep = 1 then goto [Halted] 'ver111-26 finalfreq = finalfreq4 finalbw = finalbw4 A1=1 : A0=1 'ver111-29 gosub [CommandFilter] 'ver111-29 gosub [CalTablePath4] 'ver111-39a print #main.finalifbox, "";finalfreq;" MHz" print #main.resolutionbox, "";finalbw;" KHz" 'default resolution BW wait [CommandFilter] 'ver111-29 if cb = 0 then filtbank = A1*8 + A0*4 : gosub [CommandFilterOrigCB] if cb = 2 then filtbank = A1*64 + A0*32 : gosub [CommandFilterSlimCB] return 'to 'Initialize Final Filter or [Button1]thru[Button4] [CommandFilterOrigCB]'command 1 of 4 and latch it ver111-29 out port, filtbank 'presents A0 and A1 to control buffer out control, INIT 'presents A0 and A1 to Filter Bank out port, filtbank + 1 'latches A0 and A1 into Filter Bank using latch signal out port, filtbank 'leaves A0 and A1 on Filter Bank, removing latch signal out control, contclear 'removes A0 and A1 from Filter Bank out port, 0 'removes A0 and A1 from control buffer return 'to [CommandFilter] [CommandFilterSlimCB] 'ver111-29 out port, filtbank 'presents A0 and A1 to control buffer out control, SELT 'presents A0 and A1 to Filter Bank out port, filtbank + 128 'latches A0 and A1 into Filter Bank using latch signal out port, filtbank 'leaves A0 and A1 on Filter Bank, removing latch signal out control, contclear 'removes A0 and A1 from Filter Bank out port, 0 'removes A0 and A1 from control buffer return 'to [CommandFilter] [OneStep] if haltsweep = 1 then goto [Halted] 'ver111-26 onestep = 1 'ver111-26 goto [FocusKeyBox] [Continue] if haltsweep = 1 then goto [Halted] 'ver111-26 onestep = 0 'ver111-26 [FocusKeyBox] print #main.waitbox, "!contents? wate$"; 'Wait box ver111-22 wate = val(wate$) 'change global to what user entered ver111-22 print #main.restart, "Running" 'ver111-30c goto [IncrementOneStep] [Restart] if haltsweep = 1 then goto [Halted] 'ver111-26 close #handle 'close out graph window when restarting onestep = 0 'ver111-26 print #main.restart, "Running" 'ver111-30c goto [GrabWorkingWindowData] [Spurtest]'move the PDF of PLL1 to see if a signal is a self generated spur if haltsweep = 1 then goto [Halted] 'ver111-26 if spurcheck = 0 and PLL1mode = 0 then rcounter1=rcounter1+1:gosub [CommandPLL1R] if spurcheck = 0 then print #main.spurbutton, "Spur Test is ON":spurcheck=1:gosub [CalculateAllStepsForLO1Synth]:gosub [CreateCmdAllArray]:wait if spurcheck = 1 and PLL1mode = 0 then rcounter1=rcounter1-1:gosub [CommandPLL1R] if spurcheck = 1 then print #main.spurbutton, "Spur Test is OFF":spurcheck=0:gosub [CalculateAllStepsForLO1Synth]:gosub [CreateCmdAllArray]:wait [Showvar] if haltsweep = 1 then goto [Halted] 'ver111-26 if varwindow=1 then goto [Closevarwin] WindowWidth = 200 WindowHeight = 450 'ver111-26 UpperLeftX = 590 UpperLeftY = 5 BackgroundColor$ = "darkblue" ForegroundColor$ = "white" statictext #varwin.variable1, "this step = ";thisstep, 5, 5, 180, 15 'ver111-35 statictext #varwin.variable2, "dds1output = ";DDS1array(thisstep,46);" MHz", 5, 20, 180, 15 statictext #varwin.variable3, "LO 1 = ";PLL1array(thisstep,43);" MHz", 5, 35, 180, 15 statictext #varwin.variable4, "pdf1 = ";PLL1array(thisstep,40);" MHz", 5, 50, 180, 15 statictext #varwin.variable5, "ncounter1 = ";PLL1array(thisstep,45), 5, 65, 180, 15 statictext #varwin.variable6, "Bcounter1 = ";PLL1array(thisstep,48), 5, 80, 180, 15 statictext #varwin.variable7, "Acounter1 = ";PLL1array(thisstep,47), 5, 95, 180, 15 statictext #varwin.variable8, "fcounter1 = ";PLL1array(thisstep,46), 5, 110, 180, 15 statictext #varwin.variable9, "rcounter1 = ";rcounter1, 5, 125, 180, 15 statictext #varwin.variable10, "LO2 = ";LO2;" MHz", 5, 140, 180, 15 statictext #varwin.variable11, "pdf2 = ";pdf2;" MHz", 5, 155, 180, 15 statictext #varwin.variable12, "ncounter2 = ";ncounter2, 5, 170, 180, 15 statictext #varwin.variable13, "Bcounter2 = ";Bcounter2, 5, 185, 180, 15 statictext #varwin.variable14, "Acounter2 = ";Acounter2, 5, 200, 180, 15 statictext #varwin.variable15, "rcounter2 = ";rcounter2, 5, 215, 180, 15 statictext #varwin.variable16, "LO3 = ";PLL3array(thisstep,43);" MHz", 5, 230, 180, 15 statictext #varwin.variable17, "pdf3 = ";PLL3array(thisstep,40);" MHz", 5, 245, 180, 15 statictext #varwin.variable18, "ncounter3 = ";PLL3array(thisstep,45), 5, 260, 180, 15 statictext #varwin.variable19, "Bcounter3 = ";PLL3array(thisstep,48), 5, 275, 180, 15 statictext #varwin.variable20, "Acounter3 = ";PLL3array(thisstep,47), 5, 290, 180, 15 statictext #varwin.variable21, "fcounter3 = ";PLL3array(thisstep,46), 5, 305, 180, 15 statictext #varwin.variable22, "rcounter3 = ";rcounter3, 5, 320, 180, 15 statictext #varwin.variable23, "dds3output = ";DDS3array(thisstep,46), 5, 335, 180, 15 statictext #varwin.variable24, "Magdata = ";magarray(thisstep,3);" magpower= ";datatable(thisstep,2), 5, 350, 195, 15 'raw magdata bits, MSA input power(massaged) 'ver111-39b statictext #varwin.variable25, "Phadata = ";phaarray(thisstep,3);" PDM = ";phaarray(thisstep,4), 5, 365, 180, 15 'ver111-39d open "Variables" for dialog as #varwin:varwindow = 1 print #varwin, "trapclose [Closevarwin]" 'goto [Closevarwin] if xit is clicked print #main.showvar, "Close Variables" wait [updatevar] print #varwin.variable1, "this step = ";thisstep 'ver111-35 print #varwin.variable2, "dds1output = ";DDS1array(thisstep,46);" MHz" print #varwin.variable3, "LO 1 = ";PLL1array(thisstep,43);" MHz" print #varwin.variable4, "pdf1 = ";PLL1array(thisstep,40);" MHz" print #varwin.variable5, "ncounter1 = ";PLL1array(thisstep,45) print #varwin.variable6, "Bcounter1 = ";PLL1array(thisstep,48) print #varwin.variable7, "Acounter1 = ";PLL1array(thisstep,47) print #varwin.variable8, "fcounter1 = ";PLL1array(thisstep,46) print #varwin.variable9, "rcounter1 = ";rcounter1 print #varwin.variable10, "LO2 = ";LO2;" MHz" print #varwin.variable11, "pdf2 = ";pdf2;" MHz" print #varwin.variable12, "ncounter2 = ";ncounter2 print #varwin.variable13, "Bcounter2 = ";Bcounter2 print #varwin.variable14, "Acounter2 = ";Acounter2 print #varwin.variable15, "rcounter2 = ";rcounter2 print #varwin.variable16, "LO3 = ";PLL3array(thisstep,43);" MHz" print #varwin.variable17, "pdf3 = ";PLL3array(thisstep,40);" MHz" print #varwin.variable18, "ncounter3 = ";PLL3array(thisstep,45) print #varwin.variable19, "Bcounter3 = ";PLL3array(thisstep,48) print #varwin.variable20, "Acounter3 = ";PLL3array(thisstep,47) print #varwin.variable21, "fcounter3 = ";PLL3array(thisstep,46) print #varwin.variable22, "rcounter3 = ";rcounter3 print #varwin.variable23, "dds3output = ";DDS3array(thisstep,46) print #varwin.variable24, "Magdata = ";magarray(thisstep,3);" magpower= ";datatable(thisstep,2)'raw magdata bits, MSA input power(massaged) 'ver111-39b print #varwin.variable25, "Phadata = ";phaarray(thisstep,3);" PDM = ";phaarray(thisstep,4) 'ver111-39d return [Closevarwin] close #varwin:varwindow = 0 'close out variables window print #main.showvar, "Show Variables" wait [Calfwd] if haltsweep = 1 then goto [Halted] 'ver111-26 calfwd = 1 print #main.calibfwd, "Calibrating" goto [Restart] [CalculateAllStepsForLO1Synth] haltstep = thisstep 'remember where we were in the sweep when halted for thisstep = 0 to steps magarray(thisstep,0) = thisstep * x/steps 'establishes "thispointx" (on x-axis of graph) (0 to 720)ver111-25 thisfreq = startfreq + (stepfreq * thisstep) 'calculates input freq. at this new step LO1 = thisfreq + LO2 - finalfreq 'calculates the actual LO1 frequency:thisfreq,LO2,finalfreq are actuals datatable(thisstep,0) = thisstep 'put current step number into the array, row value= thisstep 'moved ver111-18 datatable(thisstep,1) = thisfreq 'put current frequency into the array, row value= thisstep 'moved ver111-18 '[CalculateThisStepPLL1] appxVCO=LO1 : reference=appxdds1 : rcounter=rcounter1 if PLL1mode = 0 then gosub [CreateIntegerNcounter]'needed:appxVCO,reference,rcounter ; creates:ncount,ncounter,fcounter(0) 'returns with ncount,ncounter,fcounter(0),pdf if PLL1mode = 1 then gosub [CreateFractionalNcounter]'needed:appxVCO,reference,rcounter ; creates:ncount,ncounter,fcounter,pdf 'returns with ncount,ncounter,fcounter,pdf dds1output = pdf * rcounter 'actual output of DDS1(input Ref to PLL1) if PLL1mode = 1 then gosub [AutoSpur]'needed:LO2,finalfreq,dds1output,rcounter1,finalbw,appxdds1,fcounter,ncounter ver111-8 '[AutoSpur] is a continuation of [CreateFractionalNcounter], used only in MSA when PLL 1 is Fractional 'returns with possibly new: ncounter,fcounter,pdf,dds1output if PLL1mode = 1 then gosub [ManSpur]'ver111-10 '[ManSpur] is a continuation of [CreateFractionalNcounter], used only in MSA when PLL 1 is Fractional 'if Spur Test Button On, will return with new ncounter,fcounter,pdf,dds1output gosub [CreatePLL1N]'needs:ncounter,fcounter,PLL1mode,PLL1 ; creates PLL NBuffer N0-Nx gosub [FillPLL1array]'need:N0-Nx,pdf,dds1output,LO1,ncount,ncounter,Fcounter,Acounter,Bcounter;creates samePLL1 '[endCalculateThisStepPLL1] '[CalculateThisStepDDS1]'need:dds1output,masterclock,appxdds1,dds1filbw ddsoutput = dds1output : ddsclock = masterclock if dds1output-appxdds1>dds1filbw/2 then beep:error$="DDS1output too high for filter":print #main.msgbox,error$:wait 'ver111-37e if appxdds1-dds1output>dds1filbw/2 then beep:error$="DDS1output too low for filter":print #main.msgbox,error$:wait 'ver111-37e gosub [CreateBaseForDDSarray]'needed:ddsoutput,ddsclock ; creates: base,sw0thrusw39,w0thruw4 gosub [FillDDS1array]'need thisstep,sw0-sw39,w0-w4,base,ddsclock '[endCalculateThisStepDDS1] next thisstep thisstep = haltstep 'return to the step in the sweep, where we halted, if needed return '[endCalculateAllStepsForLO1Synth] [CalculateAllStepsForLO3Synth]'for hybrid, and orig (fixed freq) TG 'if TGtop = 0 then skip all this (return), actually we should not have even entered this subroutine. haltstep = thisstep 'remember where we were in the sweep when halted for thisstep = 0 to steps 'ver111-17 thisfreq = startfreq + (stepfreq * thisstep) 'calculates input freq. at this new step if TGtop = 1 then LO3 = LO2 - finalfreq - offset 'for orig, fixed freq TG ver111-15a 'or LO3 = LO1 - thisfreq - offset if TGtop = 2 and gentrk = 1 and normrev = 0 then LO3 = LO2 + thisfreq + offset 'for new TG, Trk Gen mode, normal ver111-18 if TGtop = 2 and gentrk = 1 and normrev = 1 then LO3 = LO2 + (centfreq - (stepfreq * (thisstep - (steps/2))) + offset) if TGtop = 2 and gentrk = 0 then LO3 = LO2 + sgout 'for new TG, Sig Gen mode ver111-18 '[CalculateThisStepPLL3] appxVCO=LO3 : reference=appxdds3 : rcounter=rcounter3 if appxdds3 = 0 then reference=masterclock 'for orig, fixed freq TG with no DDS3 steering. ver111-17 if PLL3mode = 0 then gosub [CreateIntegerNcounter]'needed:appxVCO,reference,rcounter ; creates:ncount,ncounter,fcounter(0) 'returns with ncount,ncounter,fcounter(0),pdf if PLL3mode = 1 then gosub [CreateFractionalNcounter]'needed:appxVCO,reference,rcounter ; creates:ncount,ncounter,fcounter,pdf 'returns with ncount,ncounter,fcounter,pdf dds3output = pdf * rcounter 'actual output of DDS3(input Ref to PLL3) gosub [CreatePLL3N]'needs:ncounter,fcounter,PLL3mode,PLL3 ; creates PLL NBuffer N0-Nx gosub [FillPLL3array]'need thisstep,N0thruN23,pdf3(40),dds3output(41),samePLL3(42)see dim PLL3array for slot info 'ver111-14 '[endCalculateThisStepPLL3] '[CalculateThisStepDDS3]'need:dds3output,masterclock,appxdds3,dds3filbw if appxdds3 = 0 then goto [endCalculateThisStepDDS3] 'there is no DDS, skip this section ver111-17 ddsoutput = dds3output : ddsclock = masterclock if dds3output-appxdds3>dds3filbw/2 then beep:error$="DDS3output too high for filter":print #main.msgbox,error$:wait 'ver111-37e if appxdds3-dds3output>dds3filbw/2 then beep:error$="DDS3output too low for filter":print #main.msgbox,error$:wait 'ver111-37e gosub [CreateBaseForDDSarray]'needed:ddsoutput,ddsclock ; creates: base,sw0thrusw39,w0thruw4 gosub [FillDDS3array]'need thisstep,sw0-sw39,w0-w4,base,ddsclock ver111-15 [endCalculateThisStepDDS3] next thisstep thisstep = haltstep 'return to the step in the sweep, where we halted, if needed return '[endCalculateAllStepsForLO3Synth] [FillPLL1array]'need thisstep,N0thruN23,pdf1(40),dds1output(41),samePLL1(42)see dim PLL1array for slot info 'ver111-1 'reversed sequence for N23 to be first. ver111-31a PLL1array(thisstep,23) = N0:PLL1array(thisstep,22) = N1 PLL1array(thisstep,21) = N2:PLL1array(thisstep,20) = N3 PLL1array(thisstep,19) = N4:PLL1array(thisstep,18) = N5 PLL1array(thisstep,17) = N6:PLL1array(thisstep,16) = N7 PLL1array(thisstep,15) = N8:PLL1array(thisstep,14) = N9 PLL1array(thisstep,13) = N10:PLL1array(thisstep,12) = N11 PLL1array(thisstep,11) = N12:PLL1array(thisstep,10) = N13 PLL1array(thisstep,9) = N14:PLL1array(thisstep,8) = N15 PLL1array(thisstep,7) = N16:PLL1array(thisstep,6) = N17 PLL1array(thisstep,5) = N18:PLL1array(thisstep,4) = N19 PLL1array(thisstep,3) = N20:PLL1array(thisstep,2) = N21 PLL1array(thisstep,1) = N22:PLL1array(thisstep,0) = N23 PLL1array(thisstep,40) = pdf PLL1array(thisstep,43) = LO1 PLL1array(thisstep,45) = ncounter PLL1array(thisstep,46) = fcounter PLL1array(thisstep,47) = Acounter PLL1array(thisstep,48) = Bcounter return [FillPLL3array]'need thisstep,N0thruN23,pdf3(40),dds3output(41),samePLL3(42)see dim PLL3array for slot info 'ver111-14 'reversed sequence for N23 to be first. ver111-31a PLL3array(thisstep,23) = N0:PLL3array(thisstep,22) = N1 PLL3array(thisstep,21) = N2:PLL3array(thisstep,20) = N3 PLL3array(thisstep,19) = N4:PLL3array(thisstep,18) = N5 PLL3array(thisstep,17) = N6:PLL3array(thisstep,16) = N7 PLL3array(thisstep,15) = N8:PLL3array(thisstep,14) = N9 PLL3array(thisstep,13) = N10:PLL3array(thisstep,12) = N11 PLL3array(thisstep,11) = N12:PLL3array(thisstep,10) = N13 PLL3array(thisstep,9) = N14:PLL3array(thisstep,8) = N15 PLL3array(thisstep,7) = N16:PLL3array(thisstep,6) = N17 PLL3array(thisstep,5) = N18:PLL3array(thisstep,4) = N19 PLL3array(thisstep,3) = N20:PLL3array(thisstep,2) = N21 PLL3array(thisstep,1) = N22:PLL3array(thisstep,0) = N23 PLL3array(thisstep,40) = pdf PLL3array(thisstep,43) = LO3 PLL3array(thisstep,45) = ncounter PLL3array(thisstep,46) = fcounter PLL3array(thisstep,47) = Acounter PLL3array(thisstep,48) = Bcounter return [FillDDS1array]'need thisstep,sw0-sw39,w0-w4,base,ddsclock 'ver111-12 DDS1array(thisstep,0) = sw0:DDS1array(thisstep,1) = sw1 DDS1array(thisstep,2) = sw2:DDS1array(thisstep,3) = sw3 DDS1array(thisstep,4) = sw4:DDS1array(thisstep,5) = sw5 DDS1array(thisstep,6) = sw6:DDS1array(thisstep,7) = sw7 DDS1array(thisstep,8) = sw8:DDS1array(thisstep,9) = sw9 DDS1array(thisstep,10) = sw10:DDS1array(thisstep,11) = sw11 DDS1array(thisstep,12) = sw12:DDS1array(thisstep,13) = sw13 DDS1array(thisstep,14) = sw14:DDS1array(thisstep,15) = sw15 DDS1array(thisstep,16) = sw16:DDS1array(thisstep,17) = sw17 DDS1array(thisstep,18) = sw18:DDS1array(thisstep,19) = sw19 DDS1array(thisstep,20) = sw20:DDS1array(thisstep,21) = sw21 DDS1array(thisstep,22) = sw22:DDS1array(thisstep,23) = sw23 DDS1array(thisstep,24) = sw24:DDS1array(thisstep,25) = sw25 DDS1array(thisstep,26) = sw26:DDS1array(thisstep,27) = sw27 DDS1array(thisstep,28) = sw28:DDS1array(thisstep,29) = sw29 DDS1array(thisstep,30) = sw30:DDS1array(thisstep,31) = sw31 DDS1array(thisstep,32) = sw32:DDS1array(thisstep,33) = sw33 DDS1array(thisstep,34) = sw34:DDS1array(thisstep,35) = sw35 DDS1array(thisstep,36) = sw36:DDS1array(thisstep,37) = sw37 DDS1array(thisstep,38) = sw38:DDS1array(thisstep,39) = sw39 DDS1array(thisstep,40) = w0 DDS1array(thisstep,41) = w1 DDS1array(thisstep,42) = w2 DDS1array(thisstep,43) = w3 DDS1array(thisstep,44) = w4 DDS1array(thisstep,45) = base 'base is decimal command DDS1array(thisstep,46) = base*ddsclock/2^32 'actual dds 1 output freq return [FillDDS3array]'need thisstep,sw0-sw39,w0-w4,base,ddsclock 'ver111-15 DDS3array(thisstep,0) = sw0:DDS3array(thisstep,1) = sw1 DDS3array(thisstep,2) = sw2:DDS3array(thisstep,3) = sw3 DDS3array(thisstep,4) = sw4:DDS3array(thisstep,5) = sw5 DDS3array(thisstep,6) = sw6:DDS3array(thisstep,7) = sw7 DDS3array(thisstep,8) = sw8:DDS3array(thisstep,9) = sw9 DDS3array(thisstep,10) = sw10:DDS3array(thisstep,11) = sw11 DDS3array(thisstep,12) = sw12:DDS3array(thisstep,13) = sw13 DDS3array(thisstep,14) = sw14:DDS3array(thisstep,15) = sw15 DDS3array(thisstep,16) = sw16:DDS3array(thisstep,17) = sw17 DDS3array(thisstep,18) = sw18:DDS3array(thisstep,19) = sw19 DDS3array(thisstep,20) = sw20:DDS3array(thisstep,21) = sw21 DDS3array(thisstep,22) = sw22:DDS3array(thisstep,23) = sw23 DDS3array(thisstep,24) = sw24:DDS3array(thisstep,25) = sw25 DDS3array(thisstep,26) = sw26:DDS3array(thisstep,27) = sw27 DDS3array(thisstep,28) = sw28:DDS3array(thisstep,29) = sw29 DDS3array(thisstep,30) = sw30:DDS3array(thisstep,31) = sw31 DDS3array(thisstep,32) = sw32 'x4 multiplier DDS3array(thisstep,33) = sw33 'control bit DDS3array(thisstep,34) = sw34 'power down bit DDS3array(thisstep,35) = sw35 '35-39 are Phase DDS3array(thisstep,36) = sw36:DDS3array(thisstep,37) = sw37 DDS3array(thisstep,38) = sw38:DDS3array(thisstep,39) = sw39 DDS3array(thisstep,40) = w0 'word 0, 8 bits, mult, control and phase DDS3array(thisstep,41) = w1 'word 1, 8 bits DDS3array(thisstep,42) = w2 'word 2, 8 bits DDS3array(thisstep,43) = w3 'word 3, 8 bits DDS3array(thisstep,44) = w4 'word 4, 8 bits DDS3array(thisstep,45) = base 'base is decimal command DDS3array(thisstep,46) = base*ddsclock/2^32 'actual dds 3 output freq return [CreateCmdAllArray] 'for SLIM CB only 'ver-31b 'a DDS serial command, will begin with LSB (W0), thru MSB (W31), ending with Phase bit 4 (W39) 'a PLL serial command, will begin with MSB (N23), thru LSB (N0, the address bit) rememberthisstep = thisstep 'remember where we were when entering this subroutine for thisstep = 0 to steps for clmn = 0 to 15 cmdallarray(thisstep,clmn) = DDS1array(thisstep,clmn)*4 + DDS3array(thisstep,clmn)*16 next clmn for clmn = 16 to 39 cmdallarray(thisstep,clmn) = PLL1array(thisstep,clmn-16)*2 + DDS1array(thisstep,clmn)*4 + PLL3array(thisstep,clmn-16)*8 + DDS3array(thisstep,clmn)*16 next clmn next thisstep thisstep = rememberthisstep return [CommandPLL]' comes here during PLL R Initializations and PLL 2 N command ver111-28 if cb = 0 then gosub [CommandPLLorig] 'ver111-28 if cb = 2 then gosub [CommandPLLslim] 'ver111-28 return 'to [InitializePLL2]or[CommandXPllRbuffer] [CommandPLLorig]'needs:N23-N0,control,Jcontrol,port,contclear,LEPLL ; commands N23-N0,old ControlBoard ver111-28 'used during initialization of PLL1, PLL2, and PLL3. PDM will get set to "0". 'when PLL1 or PLL2 then Jcontrol=SELT. when PLL3 the Jcontrol=INIT out control, Jcontrol 'enable Control Board J connector out port, N23:out port, N23 + 2 out port, N22:out port, N22 + 2:out port, N21:out port, N21 + 2 out port, N20:out port, N20 + 2:out port, N19:out port, N19 + 2 out port, N18:out port, N18 + 2:out port, N17:out port, N17 + 2 out port, N16:out port, N16 + 2:out port, N15:out port, N15 + 2 out port, N14:out port, N14 + 2:out port, N13:out port, N13 + 2 out port, N12:out port, N12 + 2:out port, N11:out port, N11 + 2 out port, N10:out port, N10 + 2:out port, N9:out port, N9 + 2 out port, N8:out port, N8 + 2:out port, N7:out port, N7 + 2 out port, N6:out port, N6 + 2:out port, N5:out port, N5 + 2 out port, N4:out port, N4 + 2:out port, N3:out port, N3 + 2 out port, N2:out port, N2 + 2:out port, N1:out port, N1 + 2 out port, N0:out port, N0 + 2:out port, LEPLL:out port, 0 'Latch buffer out control, contclear 'Disable the Control Board J connector return 'to [CommandPLL] [CommandPLLslim]'needs:datavalue,levalue,N23-N0,control,Jcontrol,port,contclear,LEPLL ; commands N23-N0,SLIM ControlBoard ver111-28 'used during initialization of PLL1, PLL2, and PLL3. PDM will get set to "0" during Initializations 'selt word = 1 common clock, 4 datas, plus 3 (filtbank). entering this sub, selt word should = filtbank only 'init word = 5 latch lines plus 2 pdm commands. entering this sub, init word should = pdmcmd + pdmclk only.ver111-39d 'two steps to do: command data and clock without disturbing Filter Bank, then send LE without disturbing PDM 'step 1 out port, filtbank + N23*datavalue 'datavalues: PLL1=2, PLL2=16, PLL3=8 out control, SELT out port, filtbank + N23*datavalue + 1 out port, filtbank + N22*datavalue:out port, filtbank + N22*datavalue + 1 out port, filtbank + N21*datavalue:out port, filtbank + N21*datavalue + 1 out port, filtbank + N20*datavalue:out port, filtbank + N20*datavalue + 1 out port, filtbank + N19*datavalue:out port, filtbank + N19*datavalue + 1 out port, filtbank + N18*datavalue:out port, filtbank + N18*datavalue + 1 out port, filtbank + N17*datavalue:out port, filtbank + N17*datavalue + 1 out port, filtbank + N16*datavalue:out port, filtbank + N16*datavalue + 1 out port, filtbank + N15*datavalue:out port, filtbank + N15*datavalue + 1 out port, filtbank + N14*datavalue:out port, filtbank + N14*datavalue + 1 out port, filtbank + N13*datavalue:out port, filtbank + N13*datavalue + 1 out port, filtbank + N12*datavalue:out port, filtbank + N12*datavalue + 1 out port, filtbank + N11*datavalue:out port, filtbank + N11*datavalue + 1 out port, filtbank + N10*datavalue:out port, filtbank + N10*datavalue + 1 out port, filtbank + N9*datavalue:out port, filtbank + N9*datavalue + 1 out port, filtbank + N8*datavalue:out port, filtbank + N8*datavalue + 1 out port, filtbank + N7*datavalue:out port, filtbank + N7*datavalue + 1 out port, filtbank + N6*datavalue:out port, filtbank + N6*datavalue + 1 out port, filtbank + N5*datavalue:out port, filtbank + N5*datavalue + 1 out port, filtbank + N4*datavalue:out port, filtbank + N4*datavalue + 1 out port, filtbank + N3*datavalue:out port, filtbank + N3*datavalue + 1 out port, filtbank + N2*datavalue:out port, filtbank + N2*datavalue + 1 out port, filtbank + N1*datavalue:out port, filtbank + N1*datavalue + 1 out port, filtbank + N0*datavalue:out port, filtbank + N0*datavalue + 1 out port, filtbank out control, contclear out port, 0 'step 2 pdmcommand = phaarray(thisstep,0)*64 'do not disturb PDM state, this may be used during Spur Test out port, pdmcommand + levalue 'levalues: PLL1=1, PLL2=16, PLL3=4 out control, INIT out port, pdmcommand out control, contclear out port, 0 return 'to [CommandPLL] [DetermineModule] 'ver111-28 'All "glitchXX's" are "0" when entering this subroutine. Either from "fresh RUN" or [WaitStatement] 'if a module is not present, or if it doesn't need commanding, return with it's "glitchXX = 0" '[DDS1] dds1output = DDS1array(thisstep,46) 'ver111-16 if dds1output = lastdds1output then goto [PLL1] 'dds 1 is same, don't waste time commanding 'ver111-28 glitchd1 = 1 'ver111-36h lastdds1output = dds1output [PLL1] ncounter1=PLL1array(thisstep,45):fcounter1=PLL1array(thisstep,46) 'ver111-16 if ncounter1=lastncounter1 and fcounter1=lastfcounter1 then goto [PLL3] 'don't waste time commanding 'ver111-28 glitchp1 = 1 'add 1 msec delay. ver111-28 lastncounter1=ncounter1:lastfcounter1=fcounter1 'ver111-16 [PLL3] if TGtop = 0 then return 'there is no PLL 3, no DDS 3,and no PDM for VNA ncounter3=PLL3array(thisstep,45):fcounter3=PLL3array(thisstep,46) if ncounter3=lastncounter3 and fcounter3=lastfcounter3 then goto [DDS3] 'don't waste time commanding 'ver111-28 glitchp3 = 1 'add 1 msec delay. ver111-28 lastncounter3=ncounter3:lastfcounter3=fcounter3 [DDS3] if appxdds3 = 0 then goto [PDM] 'if 0, there is no DDS3, but, there can be VNA ver111-28 dds3output = DDS3array(thisstep,46) if dds3output = lastdds3output then goto [PDM] 'dds 3 is same, don't waste time commanding 'ver111-29 glitchd3 = 1 'ver111-36h lastdds3output = dds3output [PDM] if vna = 0 then return ' not in VNA mode, skip the PDM 'ver111h pdmcmd = phaarray(thisstep,0) 'ver111-39d if pdmcmd = lastpdmstate then return 'don't waste time commanding glitchpdm = 10 'ver111-36h lastpdmstate = pdmcmd 'ver111-39d return 'to [CommandNextStep] [CommandOrigCB]' correct modules have been determined in [DetermineModule] 'Command necessary modules, independently, from Original Control Board if glitchd1 > 0 then gosub [CommandDDS1OrigCB] if glitchp1 > 0 then gosub [CommandPLL1OrigCB] if glitchd3 > 0 and TGtop > 0 then gosub [CommandDDS3OrigCB] if glitchp3 > 0 and TGtop > 0 then gosub [CommandPLL3OrigCB] if glitchpdm > 0 and vna = 1 then gosub [CommandPDMOrigCB] return 'to [CommandNextStep] [CommandDDS1OrigCB] 'needed:DDS1array 'ver111-21 if dds1parser = 1 then goto [CommandDDS1OrigCBserial] 'ver111-21 '(CommandDDS1OrigCBparallel)'needed:DDS1array(w0-w4),port,control,AUTO,STRB,contclear ; commands DDS1 on J5, parallel. ver111-21 'note, a DDS commanded parallel, will begin with Control Word (W0), then MSB Word (W1), ending with LSB Word (W4) 'set word 0 'set 8 bit word, W0 (0), phase info out port,DDS1array(thisstep,40) ' a "1" here would activate the x4 internal multiplier, but not recommended out control, AUTO 'wclk line goes high out control, contclear 'wclk line goes low 'set word 1 out port,DDS1array(thisstep,41) 'set 8 bit word, W1, MSB freq out control,AUTO:out control, contclear 'set word 2 out port,DDS1array(thisstep,42) 'W2 out control,AUTO:out control, contclear 'set word 3 out port,DDS1array(thisstep,43) 'W3 out control,AUTO:out control, contclear 'set word 4 out port,DDS1array(thisstep,44) 'set 8 bit word, W4, LSB freq out control,AUTO:out control, contclear out port, 0 'return the output port data lines to 0 'send fqud out control, STRB 'set fqud to 1, freq changes now out control, contclear 'set fqud to 0 and all others to 0 return 'to [CommandOrigCB] [CommandDDS1OrigCBserial]'needed:DDS1array(sw0-sw39),control,AUTO,STRB,contclear ; commands DDS1 on J5, serially ver111-21 'note: once the DDS1 has been reset into serial mode, the D0 thru D6 data lines are "don't care". 'note, a DDS serial command, will begin with LSB (W0), thru MSB (W31), ending with Phase bit 4 (W39) for clmn = 0 to 39 'ver111-21 out port, DDS1array(thisstep,clmn)*128 'apply data bit to DDS1pin25, D7 data line out control, AUTO:out control, contclear 'retain data bit while wclk up, then down next clmn 'next bit in 40 bit serial data transfer out port, 0 out control, STRB:out control, contclear 'fqud up, fqud down return 'to [CommandOrigCB] '[endCommandDDS1OldRevA] [CommandPLL1OrigCB]'needed:PLL1array(N23-N0),SELT,lastncounter1,lastfcounter1 'ver111-21 'ver111-28a makes the SELT buffer "see" the pdm state before commanding PLL1, to prevent orig PDM from changing states. Jcontrol = SELT : LEPLL = 4 'ver111-21 'Command PLL1,oldControl using N23-N0,control,Jcontrol,port,contclear,LEPLL ver111-21 'note, a PLL will serially command beginning with N23 and end with N0 (address bit) pdmcmd = phaarray(thisstep,0) 'ver111-39d out port, pdmcmd*128 'ver111-28a out control, Jcontrol 'enable Control Board J connector for clmn = 0 to 23 'reversed order 'ver111-31a out port, pdmcmd*128 + PLL1array(thisstep,clmn):out port, pdmcmd*128 + PLL1array(thisstep,clmn) + 2 'ver111-21 'ver111-28a next clmn 'ver111-21 out port, pdmcmd*128 + LEPLL:out port, pdmcmd*128 'Latch buffer 'ver111-28a out control, contclear 'Disable the Control Board J connector out port, 0 'ver111-28a return 'to [CommandOrigCB] [CommandDDS3OrigCB]'needed:DDS3array,lastdds3output,INIT 'ver111-18 Jcontrol = INIT:swclk = 32:sfqud = 2 'for Orig Control Bd,J4,DDS3 ver111-16 'Command DDS3,serially,oldControl using sw0-sw39,swclk,sfqud,control,Jcontrol,port,contclear,LEPLL ver111-21 'note, a DDS commanded serially, will begin with LSB, continue to MSB, and end with Control Word MSB Phase Bit 'present filter bank data while commanding DDS3, so as not to change filter bank ver111-29 out port, filtbank 'ver111-29 out control, Jcontrol 'enable Control Board J connector for clmn = 0 to 39 'ver111-21 out port, filtbank + DDS3array(thisstep,clmn) 'apply data bit to DDS, and also filter lines 'ver111-29 out port, filtbank + DDS3array(thisstep,clmn) + swclk 'apply data bit and wclk 'ver111-29 next clmn out port, filtbank:out port, filtbank + sfqud:out port, filtbank 'last sw down and swclk down, sfqud up, sfqud down 'ver111-29 out control, contclear 'disable J connector out port, 0 'ver111-29 return 'to [CommandOrigCB] [CommandPLL3OrigCB]'needed:PLL3array(N23-N0),INIT,lastncounter3,lastfcounter3 ver111-18 Jcontrol = INIT : LEPLL = 16 'ver111-21 'Command PLL3,Orig Control using N23-N0,control,Jcontrol,port,contclear,LEPLL ver111-21 'note, a PLL will serially command beginning with N23 and end with N0 (address bit) 'present filter bank data while commanding PLL3, so as not to change filter bank ver111-29 out port, filtbank 'ver111-29 out control, Jcontrol 'enable Control Board J connector for clmn = 0 to 23 'reversed order 'ver111-31a out port, filtbank + PLL3array(thisstep,clmn) 'ver111-29 out port, filtbank + PLL3array(thisstep,clmn) + 2 'ver111-21 'ver111-29 next clmn 'ver111-21 out port, filtbank + LEPLL:out port, filtbank 'Latch buffer 'ver111-29 out control, contclear 'Disable the Control Board J connector out port, 0 'ver111-29 return 'to [CommandOrigCB] [CommandPDMonly] 'ver111-28 if cb = 0 then goto [CommandPDMOrigCB] 'ver111-28 if cb = 2 then goto [CommandPDMSlimCB] 'ver111-28 return 'to [InvertPDmodule] [CommandPDMOrigCB]'Set original PDM phase for last known mode, since a PLL1 or PLL2 command will reset the PDM to Norm. out port, phaarray(thisstep,0)*128: out control, SELT: out control, contclear: out port, 0 'pdmcmd is determined in [InvertPDmodule] 'ver111-20 return 'to [CommandOrigCB]or[CommandPDMonly] [CommandPDMSlimCB]'also sending a "latch signal", used by orig PDM module out port, phaarray(thisstep,0)*64 out control, INIT out port, phaarray(thisstep,0)*64 + 32 out port, phaarray(thisstep,0)*64 out control, contclear out port, 0 return 'to [CommandPDMonly] [CommandPLL1SlimCB]'independently.(not used) without disturbing filter bank or PDM 'ver111-32b 'note, a PLL will serially command beginning with N23 and end with N0 (address bit) out port, filtbank out control, SELT for clmn = 0 to 23 'reversed order 'ver111-31a a= PLL1array(thisstep,clmn)*2 + filtbank out port, a : out port, a + 1 : out port, a next clmn 'next bit in 24 bit serial data transfer out port, filtbank out control, contclear 'send latch enable (le1) without disturbing PDM p = phaarray(thisstep,0)*64 out port, p out control, INIT out port, p + le1 : out port, p ' PDM data remains static out control, contclear out port, 0 return [CommandPLL3SlimCB]'independently.(not used) without disturbing filter bank or PDM 'ver111-32b 'note, a PLL will serially command beginning with N23 and end with N0 (address bit) out port, filtbank out control, SELT for clmn = 0 to 23 'reversed order 'ver111-31a a= PLL3array(thisstep,clmn)*8 + filtbank out port, a : out port, a + 1 : out port, a next clmn 'next bit in 24 bit serial data transfer out port, filtbank out control, contclear 'send latch enable (le3) without disturbing PDM p = phaarray(thisstep,0)*64 out port, p out control, INIT out port, p + le3 : out port, p ' PDM data remains static out control, contclear out port, 0 return [CommandDDS1SlimCB]'independently, without disturbing filter bank or PDM 'ver111-32b 'note, a DDS serial command, will begin with LSB (W0), thru MSB (W31), ending with Phase bit 4 (W39) out port, filtbank out control, SELT for clmn = 0 to 39 a = filtbank + DDS1array(thisstep,clmn)*4 'apply data bit to DDS1pin25, D7 data line out port, a : out port, a + 1 : out port, a next clmn 'next bit in 40 bit serial data transfer out port, filtbank out control, contclear 'send fqud (fqud1) without disturbing PDM p = phaarray(thisstep,0)*64 out port, p out control, INIT out port, p + fqud1 : out port, p ' PDM data remains static out control, contclear out port, 0 return [CommandDDS3SlimCB]'independently, without disturbing filter bank or PDM 'ver111-32b 'note, a DDS serial command, will begin with LSB (W0), thru MSB (W31), ending with Phase bit 4 (W39) out port, filtbank out control, SELT for clmn = 0 to 39 a = filtbank + DDS3array(thisstep,clmn)*16 'apply data bit to DDS1pin25, D7 data line out port, a : out port, a + 1 : out port, a next clmn 'next bit in 40 bit serial data transfer out port, filtbank out control, contclear 'send fqud (fqud3) without disturbing PDM p = phaarray(thisstep,0)*64 out port, p out control, INIT out port, p + fqud3 : out port, p ' PDM data remains static out control, contclear out port, 0 return [CommandAllSlims]'for SLIM Control and SLIM modules. Old PDM and old Filt Bank can be used 'ver111-31c '(send data and clocks without changing Filter Bank) 'set up filter bank data before enabling buffer out port, filtbank 'enable P1 connector (SELT buffer). This moves the filtbank data to the filter bank with common clock still low out control, SELT 'enable P1 connector (SELT buffer) '0-15 is DDS1bit*4 + DDS3bit*16, data = 0 to PLL 1 and PLL 3. see[CreateCmdAllArray]. 'present data, add clock, remove clock. repeat. (40 data bits and 40 clocks for each module) 'this format guarantees that the common clock will not transition with a data transition, preventing crosstalk in LPT cable. ver111-32c a= cmdallarray(thisstep,0)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,1)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,2)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,3)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,4)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,5)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,6)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,7)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,8)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,9)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,10)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,11)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,12)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,13)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,14)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,15)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,16)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,17)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,18)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,19)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,20)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,21)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,22)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,23)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,24)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,25)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,26)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,27)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,28)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,29)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,30)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,31)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,32)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,33)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,34)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,35)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,36)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,37)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,38)+ filtbank: out port, a: out port, a+1:out port, a a= cmdallarray(thisstep,39)+ filtbank: out port, a: out port, a+1:out port, a 'after the last data and clock, bring all data lines low, except for what filtbank needs to remain at out port, filtbank 'remove enable from SLIM Control, P1 connector. filtbank signals will remain out control, contclear '(send latch bits and command PDM) 'begin by setting up init word=LE's and Fquds + PDM state for thisstep pdmcmd = phaarray(thisstep,0)*64 'ver111-39d out port, le1 + fqud1 + le3 + fqud3 + pdmcmd 'ver111-39d 'enable P2 connector (INIT buffer). This moves the signals to the modules out control, INIT 'PLLs and DDSs get latched, PDM has static data 'remove LEs and Fquds, leaving PDM data. Add a latch signal P2D5. For old PDM if used. out port, pdmcmd + 32 'ver111-39d 'remove the latch command from PDM, leaving PDM's static data out port, pdmcmd 'ver111-39d 'remove enable from P2 connector (INIT buffer). PDM data remains static out control, contclear out port, 0 return 'to [CommandNextStep] [finished] close #main 'close out working window close #handle 'close out graph window if varwindow = 1 then close #varwin 'close out variable window if special = 1 then close #special 'ver111-36b end '------------ ' The following are error messages and are not compiled: '"PLL 1" '"PLL 2" '"PLL 3" ' and: ' "2325 Rcounter is < 3" ' "2325 Rcounter is > 16383" ' "2325 Bcounter < 3" ' "2325 Bcounter > 2047" ' "2325 Bcounter16383" ' "2326 Bcounter <3" ' "2326 Bcounter >8191" ' "2326 Bcounter32767" ' "2350 Bcounter <3" ' "2350 Bcounter >1023" ' "2350 Bcounter 32767" ' "2353 Bcounter is < 3" ' "2353 Bcounter is > 1023" ' "2353 Bcounter < Acounter+2" ' "4112 R counter >16383" ' "4112 N counter <3" ' "4112 N counter >8191" ' "4112 B counter