Importing a bunch of pages from old websites.
[website_subgeniuskitty.com] / data / development / test_equipment / hp_3586_gpib_spectrum_analyzer.files / hp3586_specan.pl
CommitLineData
f6e94cb2
AT
1# Quick script to use HP 3586C SLM
2# as a rudimentary spectrum analyzer.
3
4use Device::SerialPort;
5
6# Set up the serial port
7# 19200, 81N on the USB ftdi driver
8my $port = Device::SerialPort->new("/dev/ttyUSB0");
9$port->databits(8);
10$port->baudrate(19200);
11$port->parity("none");
12$port->stopbits(1);
13
14# Initialize Prologix USB-GPIB Controller
15$port->write("++mode 1\n");
16$port->write("++auto 1\n");
17$port->write("++addr 16\n");
18
19# Initialize HP 3586C
20$port->write("Remote\n");
21$port->write("B3\n"); # Set BW Filter
22$port->write("T1\n"); # Terminate in 50 ohms
23$port->write("A1\n"); # Average: On
24
25# Frequency Sweep Definition
26$freq_start = 9250;
27$freq_end = 10250;
28$freq_increment = 1;
29$freq_index = $freq_start;
30while ($freq_index <= $freq_end) {
31 push (@frequency, $freq_index);
32 $freq_index = $freq_index + $freq_increment;
33}
34
35$scan_rep = 70;
36$scan_index = 1;
37print "#(kHz) (UNIXtime) (dBm)\n";
38print "Freq Time Amplitude\n";
39while ($scan_index <= $scan_rep) {
40 print "# Starting Repetition: $scan_index\n";
41 # Gather and print the measurements
42 # If you want to sweep faster, adjust the two sleep() statements.
43 # Check manual for minimum settling times for your configuration of
44 # BW filter, averaging, etc.
45 foreach $freq (@frequency) {
46 $port->write("FR,$freq,KZ\n");
47 sleep(6);
48 $port->write("TR\n");
49 sleep(2);
50 my $char = $port->lookfor();
51 $char =~ s/N//g;
52 $char =~ s/\r//g; # To match the newlines from the HP 3586C
53 chomp $char;
54 $time = time;
55 print "$freq $time $char \n";
56 }
57
58 $scan_index = $scan_index + 1;
59}