Skip to content

Instantly share code, notes, and snippets.

@NT7S
Last active August 29, 2015 14:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NT7S/eb3a07344c96424543d4 to your computer and use it in GitHub Desktop.
Save NT7S/eb3a07344c96424543d4 to your computer and use it in GitHub Desktop.
#include "si5351.h"
#include "Wire.h"
Si5351 si5351;
long a;
int inData;
void setup()
{
// Start serial and initialize the Si5351
Serial.begin(57600);
si5351.init(SI5351_CRYSTAL_LOAD_8PF);
si5351.set_correction(8);
}
void loop()
{
while (Serial.available() > 0) // see if incoming serial data:
{
inData = Serial.read(); // read oldest byte in serial buffer:
// Serial.println("Test of serial");
if (inData == 'A')
{
a = Serial.parseInt();
Serial.println(a);
// Set CLK0
si5351.set_freq(a * 100ULL, 0, SI5351_CLK0);
}
}
}
import usbtmc
import serial
import time
import sys
import math
lower_freq = 500000
upper_freq = 160050000
freq_step = 500000
# Arduino serial dev paramaters
DEVICE = '/dev/ttyACM0'
BAUD = 57600
# Open the DSA815 and config for reading frequency
sa = usbtmc.Instrument(0x1ab1, 0x0960)
# Open serial port
try:
ser = serial.Serial(port=DEVICE, baudrate=BAUD, timeout=2)
except:
print 'Cannot open serial port'
sys.exit(0)
# Preset
sa.write(":SYST:PRES")
time.sleep(2)
sa.write(":FREQuency:SPAN 100000")
time.sleep(1)
file = open('sweep.csv', 'wt')
file.write('Frequency (Hz),Amplitude (dBm)\n')
# Main control loop
for freq in range(lower_freq, upper_freq, freq_step):
# Set the Si5351A
ser.write('A' + str(freq))
time.sleep(5)
# Peak Search
sa.write(":FREQuency:CENTER " + str(freq))
time.sleep(1)
sa.write(":CALCulate:MARKer1:MAXimum:MAX")
time.sleep(1)
# Get the amplitude
amplitude = sa.ask(":CALCulate:MARKer1:Y?")
# Print it out in comma delimeted format
output = '{},{}'.format(freq, amplitude)
print output
file.write(output + '\n')
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment