Program MTS2000; { Program for testing the serial interface to the Verticom MTS-2000 frequency synthesizers Revision Date : 11 Feb 1999 Written by : R. Hayward } uses crt, DOS, async; const COM1 : byte = 1; COM2 : byte = 2; BELL : char = ^G; var Mode : char; ComStatus : boolean; I,J,K : integer; COM : word; Freq : real; New_Freq : real; Lo_Freq : real; Hi_Freq : real; Width : real; Width_Change : Integer; Step : real; Harmonic : integer; IPause : integer; NStep : integer; IF_Freq : real; Offset : integer; Address : byte; Data1 : byte; Data2 : byte; Data3 : byte; Data4 : byte; KHz : byte; AckReq : byte; SndAdr : byte; Procedure Char_Loop (var New_Input : char); var Ch : char; begin Ch := readkey; if ORD(Ch) = 0 {ie: Control Code for Arrow Keys} then begin Ch := readkey; if Ch = 'H' then Ch := ^U else if Ch = 'P' then Ch := ^D else if Ch = 'M' then Ch := ^R else if Ch = 'K' then Ch := ^L; end; New_Input := Ch; end; Procedure Input_Real(Old_Val : real; var Value : real); var I,J,K : integer; New_Val : real; Ch : char; Ch_Strg : string[11]; Code : integer; CursorX : integer; CursorY : integer; begin Ch_Strg := '00000000000'; I := 1; repeat Ch := readkey; if ((Ch <> 'X') and (Ch <> 'x') and (ORD(Ch) <> $0D) and (I <> 9)) then begin { if not Quit or CR or 8 chracters input } if (ORD(Ch) = $08) then { check for Backspace } if I <> 1 then begin I := I - 1; CursorX := WhereX; CursorY := WhereY; GotoXY(CursorX-1,CursorY); write(' '); GotoXY(CursorX-1,CursorY); Ch_Strg[I] := '0'; end; case Ch of '0','1','2','3','4','5','6','7','8','9' : { if a number character } begin write(Ch); Ch_Strg[I] := Ch; I := I + 1; if (I = 4) and (Ch_Strg[1] < '8') or (I = 5) then begin Ch := '.'; write(Ch); Ch_Strg[I] := Ch; I := I + 1; end; end; end; end else begin if (ORD(Ch) = $0D) then begin if I = 1 then begin if Harmonic <> 1 then New_Val := Old_Val * Harmonic / 1000.0 else New_Val := Old_Val; end else begin if (ORD(Ch) = $0D) or (I = 9) then { if CR or 8 characters input } begin I := I - 1; K := 11 - I; for J := I downto 1 do Ch_Strg[J+K] := Ch_Strg[J]; for J := 1 to K do Ch_Strg[J] := '0'; VAL(Ch_Strg, New_Val, Code); Ch_Strg:='00000000000'; I := 1; write(' '); Ch := CHR($0D); end; end; end; end; until (ORD(Ch)=$0D) or (Ch='X') or (Ch='x'); if ORD(Ch) = $0D then begin Value := New_Val; end; end; Procedure Input_Integer(var Value : integer); var I,J,K : integer; New_Val : integer; Ch : char; Ch_Strg : string[11]; Code : integer; CursorX : integer; CursorY : integer; begin Ch_Strg := '00000000000'; I := 1; repeat Ch := readkey; if ((Ch <> 'X') and (Ch <> 'x') and (ORD(Ch) <> $0D) and (I <> 6)) then begin { if not Quit or CR or 5 chracters input } if (ORD(Ch) = $08) then { check for Backspace } if I <> 1 then begin I := I - 1; CursorX := WhereX; CursorY := WhereY; GotoXY(CursorX-1,CursorY); write(' '); GotoXY(CursorX-1,CursorY); Ch_Strg[I] := '0'; end; case Ch of '0','1','2','3','4','5','6','7','8','9' : { if a number character } begin write(Ch); Ch_Strg[I] := Ch; I := I + 1; end; end; end else begin if (ORD(Ch) = $0D) then begin if I = 1 then begin New_Val := Value; end else begin if (ORD(Ch) = $0D) or (I = 6) then { if CR or 5 characters input } begin I := I - 1; K := 11 - I; for J := I downto 1 do Ch_Strg[J+K] := Ch_Strg[J]; for J := 1 to K do Ch_Strg[J] := '0'; VAL(Ch_Strg, New_Val,Code); Ch_Strg:='00000000000'; I := 1; write(' '); Ch := CHR($0D); end; end; end; end; until (ORD(Ch)=$0D) or (Ch='X') or (Ch='x'); if ORD(Ch) = $0D then begin Value := New_Val; end; end; Procedure What_Harmonic (var Value : real; var Harmonic : integer); begin if Value <= 500.0 then begin Harmonic := round(Value / 8.5); Value := (Value / Harmonic) * 1000.0; end else Harmonic := 1; end; Procedure Use_Harmonic (var Value : real); begin if Value <= 500.0 then begin Value := (Value / Harmonic) * 1000.0; end; if Value < 8000.0 then Value := 8000.0; if Value > 9000.0 then Value := 9000.0; end; Procedure Send_MTS; begin ComWriteCh(COM,chr(Address)); ComWriteCh(COM,chr(Data1)); ComWriteCh(COM,chr(Data2)); ComWriteCh(COM,chr(Data3)); ComWriteCh(COM,chr(Data4)); ComWriteCh(COM,chr(KHz)); { ComWriteCh(COM,chr(AckReq)); ComWriteCh(COM,chr(SndAdr)); } end; Procedure New_Freq_BCD(Value : real); var Part : real; Dummy : byte; begin Part := Value * 1000.0; Dummy := Trunc(Part / 1000000.0); writeln; Data4 := Dummy OR $40; Part := Part - (1000000.0 * Dummy); Dummy := Trunc(Part / 100000.0); Data3 := Dummy; Data3 := Data3 * 16; Part := Part - (100000.0 * Dummy); Dummy := Trunc(Part / 10000.0); Data3 := Data3 OR Dummy; Part := Part - (10000.0 * Dummy); Dummy := Trunc(Part / 1000.0); Data2 := Dummy; Data2 := Data2 * 16; Part := Part - (1000.0 * Dummy); Dummy := Trunc(Part / 100.0); Data2 := Data2 OR Dummy; Part := Part - (100.0 * Dummy); Dummy := Trunc(Part / 10.0); Data1 := Dummy; Data1 := Data1 * 16; Part := Part - (10.0 * Dummy); Dummy := Round(Part); Data1 := Data1 OR Dummy; end; Procedure Pause; var I,J : integer; begin for I := 1 to IPause do begin for J := 1 to 10000 do begin J := J; end; end; end; begin ClrScr; writeln('Which serial port is the MTS-2000 connected to?'); write('Type 1 (for COM1) or 2 (for COM2) -->'); Mode := readkey; if Mode = '2' then COM := COM2 else COM := COM1; ComStatus := OpenCom(COM,16,16); writeln('ComStatus=', ComStatus); ComParams(COM,2400,8,'N',2); ClearCom(COM,'O'); Freq := 8500.0; Lo_Freq := 8000.0; Hi_Freq := 9000.0; Width := 1000.0; Harmonic:= 1; IPause := 100; NStep := 25; Width_Change := 0; Offset := 100; IF_Freq := 1500.0; Address := $41; Data1 := $00; Data2 := $00; Data3 := $50; Data4 := $48; KHz := $4B; Send_MTS; Mode := ' '; while (Mode <> 'X') and (Mode <> 'x') do begin ClrScr; writeln('* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *'); writeln('* *'); writeln('* General Purpose Serial Interface Program for the VertiCom MTS-2000 *'); writeln('* *'); writeln('* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *'); writeln; writeln; writeln('Current MTS-2000 Frequency = ', Freq:7:3, ' MHz x ',Harmonic:2,' = ', (Harmonic*Freq /1000.0):11:6,' GHz'); writeln(' Low Freq = ', Lo_Freq:7:3,' MHz x ',Harmonic:2,' = ', (Harmonic*Lo_Freq/1000.0):11:6,' GHz'); writeln(' High Freq = ', Hi_Freq:7:3,' MHz x ',Harmonic:2,' = ', (Harmonic*Hi_Freq/1000.0):11:6,' GHz'); writeln; writeln('EXECUTIVE MENU : F = New Frequency W = Lo/Hi Width'); writeln(' L = Low Frequency H = High Frequency'); writeln(' T = Toggle Freq Mode P = Pause Interval'); writeln(' S = Sweep Mode N = Number of Steps'); writeln(' B = Side-Band Mode I = IF Frequency'); writeln(' R = Re-send Last Freq X = Exit Program'); writeln; writeln('<< Use R/L Arrow for +/-1 KHz and U/D Arrow for +/-1 MHz on Synth value>>'); writeln; write('Input Selection -->'); Char_Loop(Mode); case Mode of ^L,^R,^D,^U : { if Left, Right, Down or Up Arrow } begin case Mode of ^L : New_Freq := Freq - 0.001; ^R : New_Freq := Freq + 0.001; ^D : New_Freq := Freq - 1.0; ^U : New_Freq := Freq + 1.0; end; if New_Freq < 8000.0 then New_Freq := 8000.0; if New_Freq > 9000.0 then New_Freq := 9000.0; Freq := New_Freq; New_Freq_BCD(Freq); Send_MTS; end; end; if (Mode = 'F') OR (Mode = 'f') then begin writeln; if Harmonic = 1 then begin writeln('Type in New Frequency value between 8000 - 9000 MHz (or 100 - 500 GHz)'); writeln('Current = ', Freq:8:3,' MHz'); end else begin writeln('Type in New Frequency value between 100 - 500 GHz (or 8000 - 9000 MHz)'); writeln('Current = ', (Freq*Harmonic/1000.0):5:3,' GHz'); end; write ('New ----> '); Input_Real(Freq, New_Freq); Width_Change := 0; if (New_Freq >= 8000.0) and (Harmonic <> 1) then Width_Change := -1; if (New_Freq < 8000.0) and (Harmonic = 1) then Width_Change := +1; What_Harmonic(New_Freq, Harmonic); Freq := New_Freq; New_Freq_BCD(Freq); Send_MTS; end; if (Mode = 'W') or (Mode = 'w') then begin writeln; case Width_Change of 0 : begin if Harmonic = 1 then begin writeln('Type in Lo/Hi Frequency Width between 1 and 1000 MHz'); writeln('Current = ', Width:8:3,' MHz'); end else begin writeln('Type in Lo/Hi Frequency Width between 0.001 - 6.0 GHz'); writeln('Current = ', (Width*Harmonic/1000.0):5:3,' GHz'); end; end; -1 : begin writeln('Type in Lo/Hi Frequency Width between 1 and 1000 MHz'); writeln('Current = ', (Width):8:3,' MHz'); end; +1 : begin writeln('Type in Lo/Hi Frequency Width between 0.001 - 6.0 GHz'); writeln('Current = ', (Width*Harmonic/1000):5:3,' GHz'); end; end; Width_Change := 0; write('New ----> '); read(Width); if Harmonic = 1 then begin if Width < 1.0 then Width := 1.0; if Width > 1000.0 then Width := 1000.0; end else begin if Width < 0.001 then Width := 0.001; if Width > 6.0 then Width := 6.0; Width := Width * 1000.0 / Harmonic; end; Lo_Freq := Freq - (Width / 2.0); Hi_Freq := Freq + (Width / 2.0); end; if (Mode = 'L') OR (Mode = 'l') then begin writeln; if Harmonic = 1 then begin writeln('Type in Low Frequency value between 8000 - 9000 MHz'); writeln('Current = ', Lo_Freq:8:3,' MHz'); end else begin writeln('Type in Low Frequency value between 100 - 500 GHz'); writeln('Current = ', (Lo_Freq*Harmonic/1000.0):5:3,' GHz'); end; write('New ----> '); Input_Real(Lo_Freq, New_Freq); Use_Harmonic(New_Freq); Lo_Freq := New_Freq; Width := Hi_Freq - Lo_Freq; New_Freq_BCD(Lo_Freq); Send_MTS; end; if (Mode = 'H') OR (Mode = 'h') then begin writeln; if Harmonic = 1 then begin writeln('Type in High Frequency value between 8000 - 9000 MHz'); writeln('Current = ', Hi_Freq:8:3,' MHz'); end else begin writeln('Type in High Frequency value between 100 - 500 GHz'); writeln('Current = ', (Hi_Freq*Harmonic/1000.0):5:3,' GHz'); end; write('New ----> '); Input_Real(Hi_Freq, New_Freq); Use_Harmonic(New_Freq); Hi_Freq := New_Freq; Width := Hi_Freq - Lo_Freq; New_Freq_BCD(Hi_Freq); Send_MTS; end; if (Mode = 'T') or (Mode = 't') then begin repeat if not keypressed then begin ClrScr; writeln('Frequency Toggle Mode - Type Q to Quit'); writeln; write('Low Toggle Frequency = ', Lo_Freq:8:3,' MHz'); if Harmonic <> 1 then writeln(' * ',Harmonic:2,' = ',(Lo_Freq*Harmonic/1000.0):5:3,' GHz'); New_Freq_BCD(Lo_Freq); Send_MTS; Pause; end; if not keypressed then begin ClrScr; writeln('Frequency Toggle Mode - Type Q to Quit'); writeln; write('High Toggle Frequency = ', Hi_Freq:8:3,' MHz'); if Harmonic <> 1 then writeln(' * ',Harmonic:2,' = ',(Hi_Freq*Harmonic/1000.0):5:3,' GHz'); New_Freq_BCD(Hi_Freq); Send_MTS; Pause; end; if keypressed then Mode := readkey; until (Mode = 'Q') or (Mode = 'q'); end; if (Mode = 'P') OR (Mode = 'p') then begin writeln; writeln('Type in New Pause Interval value between 1 - 10000'); writeln('Current = ', IPause:5); write ('New ----> '); Input_Integer(IPause); if IPause < 1 then IPause := 1; if IPause > 10000 then IPause := 10000; end; if (Mode = 'S') or (Mode = 's') then begin Step := (Hi_Freq - Lo_Freq) / NStep; repeat I := 0; repeat New_Freq := Lo_Freq + (I * Step); ClrScr; writeln('Frequency Sweep Mode - Type Q to Quit'); writeln; write('Sweep Frequency = ', New_Freq:8:3,' MHz'); if Harmonic <> 1 then write(' * ',Harmonic:2,' = ',(New_Freq*harmonic/1000.0):5:3,' GHz'); writeln(' : Step ',I:4,' out of ',NStep:4); New_Freq_BCD(New_Freq); Send_MTS; Pause; I := I + 1; if keypressed then Mode := readkey; until (I = NStep + 1) or (Mode = 'Q') or (Mode = 'q'); until (Mode = 'Q') or (Mode = 'q'); end; if (Mode = 'N') OR (Mode = 'n') then begin writeln; writeln('Type in New Number of Frequency Steps between 1 - 1000'); writeln('Current = ', NStep:4); write ('New ----> '); Input_Integer(NStep); if NStep < 1 then NStep := 1; if NStep > 1000 then NStep := 1000; end; if (Mode = 'B') or (Mode = 'b') then if Harmonic <> 1 then begin writeln; writeln('Is Frequency Value (',(Harmonic*Freq/1000.0):11:6,' GHz) Lower or Upper Sideband?'); write('Type L or U -->'); repeat Mode := ReadKey; until (Mode = 'L') or (Mode = 'l') or (Mode = 'U') or (Mode = 'u'); writeln; write('Type in LSB - USB offset between 1 - 1000 MHz'); writeln(' (Current = ', Offset:4,' MHz)'); write('New ----> '); Input_Integer(Offset); if Offset < 1 then Offset := 1; if Offset > 1000 then Offset := 1000; if (Mode = 'L') or (Mode = 'l') then begin Lo_Freq := Freq + Offset/2.0 / Harmonic; Hi_Freq := Freq + (2*IF_Freq + Offset/2.0) / Harmonic; end; if (Mode = 'U') or (Mode = 'u') then begin Lo_Freq := Freq - (2*IF_Freq - Offset/2.0) / Harmonic; Hi_Freq := Freq + Offset/2.0 / Harmonic; end; repeat if not keypressed then begin ClrScr; writeln('LSB / USB Toggle Mode (IF Freq = ',IF_Freq:4:0,' MHz) - Type Q to Quit'); writeln; write('LSB Frequency = ', Lo_Freq:8:3,' MHz'); writeln(' * ',Harmonic:2,' = ',(Lo_Freq*Harmonic/1000.0):5:3,' GHz'); New_Freq_BCD(Lo_Freq); Send_MTS; Pause; end; if not keypressed then begin ClrScr; writeln('LSB / USB Toggle Mode (IF Freq = ',IF_Freq:4:0,' MHz) - Type Q to Quit'); writeln; write('USB Frequency = ', Hi_Freq:8:3,' MHz'); writeln(' * ',Harmonic:2,' = ',(Hi_Freq*Harmonic/1000.0):5:3,' GHz'); New_Freq_BCD(Hi_Freq); Send_MTS; Pause; end; if keypressed then Mode := readkey; until (Mode = 'Q') or (Mode = 'q'); end; if (Mode = 'I') or (Mode = 'i') then begin writeln('Type in IF Frequency between 1000 - 8000 MHz'); writeln('Current = ', IF_Freq:8:3,' MHz'); write('New ----> '); read(Offset); end; if (Mode = 'R') OR (Mode = 'r') then begin Send_MTS; end; end; writeln; writeln('Time for a beer!'); writeln; CloseCom(COM); end.