Skip to content

Instantly share code, notes, and snippets.

@NT7S
Created October 6, 2015 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NT7S/f4e51e2f1be628292374 to your computer and use it in GitHub Desktop.
Save NT7S/f4e51e2f1be628292374 to your computer and use it in GitHub Desktop.
Si5351A Breakout Board test script
import socket
import serial
import time
import sys
import math
import phant
from datetime import datetime
import calendar
# ANSI escape codes for pretty printing
class termcolors:
FG_BLUE = '\033[94m'
FG_YELLOW = '\033[93m'
FG_GREEN = '\033[92m'
FG_RED = '\033[91m'
FG_WHITE = '\033[97m'
FG_BLACK = '\033[30m'
BG_GREEN = '\033[42m'
BG_RED = '\033[41m'
BG_BLACK = '\033[40m'
BOLD = '\033[1m'
NORMAL = '\033[0m'
UNDERLINE = '\033[4m'
ENDC = '\033[0m'
# The list of frequencies to check for each CLK output
freq = [140000000, 20000000, 11111000]
# Data store variables
data = []
test_pass = []
# Test boundaries
AMP_UPPER = 15.0
AMP_LOWER = -5.0
VOLT_UPPER = 3.4
VOLT_LOWER = 3.2
# File for local data logging
filename = 'si5351abb_test_log.txt'
try:
file = open(filename, 'a')
except:
print('Cannot open logfile')
sys.exit(0)
# Setup phant for logging data
p = phant.Phant('wYaxdONNpeSk1QQAmBayfdXEXq0', 'serial_number', 'clk', 'frequency', 'amplitude', 'pass', private_key='OdLqwOZZEVSvPZZX5ELaSOXgXjm', base_url='http://data.recursiv.com:8080')
# Constants for the LXI interfaces to the instruments
rigol_port = 5555
dsa815_addr = '192.168.1.60'
ds1052z_addr = '192.168.1.61'
# Create socket objects for the LXI interfaces
dsa815 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#ds1052z = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
dsa815.connect((dsa815_addr, rigol_port))
except:
print('Cannot open DSA815 LXI connection')
sys.exit(0)
#ds1052z.connect((ds1052z_addr, rigol_port))
# Say hi
print('\nSi5351A Breakout Board Test')
print('===========================')
sku = raw_input('Enter SKU: ')
# Arduino serial dev paramaters
DEVICE = '/dev/ttyACM0'
BAUD = 9600
# Open serial port
try:
ser = serial.Serial(port=DEVICE, baudrate=BAUD, timeout=2)
except:
print('Cannot open serial port')
sys.exit(0)
# The main loop
keep_going = True
while keep_going:
print('')
sn = raw_input('Enter board serial number: ')
i = raw_input('Place board on jig and press [Enter] to start: ')
# Init the Si5351A
ser.write('I')
# Preset
dsa815.send(":SYST:PRES\n")
time.sleep(2)
# Set span to 100 kHz
dsa815.send(":FREQuency:SPAN 100000\n")
time.sleep(1)
# Set ampitude ref to 20 dBm
dsa815.send(":DISP:WIN:TRAC:Y:SCAL:RLEV 20\n")
time.sleep(1)
#ser.flush()
# Check that all of the outputs are working
for clk in range(0, 3):
ser.write('C' + str(clk))
time.sleep(0.2)
ser.write('T' + str(freq[clk]))
time.sleep(1)
dsa815.send(':FREQuency:CENTER ' + str(freq[clk]) + '\n')
time.sleep(1)
dsa815.send(':CALCulate:MARKer1:MAXimum:MAX\n')
time.sleep(1)
dsa815.send(':CALCulate:MARKer1:Y?\n')
amplitude = dsa815.recv(1024)
data.append(amplitude.rstrip())
if(float(amplitude) < AMP_UPPER and float(amplitude) > AMP_LOWER):
alert_color_fg = termcolors.FG_GREEN
alert_color_bg = termcolors.BG_GREEN
condition = 'PASS' + termcolors.NORMAL
test_pass.append('PASS')
else:
alert_color_fg = termcolors.FG_RED
alert_color_bg = termcolors.BG_RED
condition = 'FAIL' + termcolors.NORMAL
test_pass.append('FAIL')
print('{}{} CLK{:1}: {}{}{:+6.2f} dBm {}{}{}{}{}'.format(termcolors.BOLD, termcolors.FG_WHITE, str(clk), termcolors.NORMAL, alert_color_fg, float(amplitude), termcolors.NORMAL, termcolors.FG_BLACK, alert_color_bg, condition, termcolors.NORMAL))
# Get the 3.3V rail
ser.write('V')
adc_val = ser.readline()
#print('{}'.format(adc_val))
if(adc_val != ''):
rail_3v3 = (int(adc_val) * 5.0) / 1024.0
else:
rail_3v3 = 0.0
if(rail_3v3 < VOLT_UPPER and rail_3v3 > VOLT_LOWER):
alert_color_fg = termcolors.FG_GREEN
alert_color_bg = termcolors.BG_GREEN + termcolors.FG_BLACK
condition = 'PASS' + termcolors.NORMAL
else:
alert_color_fg = termcolors.FG_RED
alert_color_bg = termcolors.BG_RED + termcolors.FG_BLACK
condition = 'FAIL' + termcolors.NORMAL
print('{}{}3.3V Rail: {}{}{:.2f}V {}{}{}'.format(termcolors.BOLD, termcolors.FG_WHITE, termcolors.NORMAL, alert_color_fg, rail_3v3, termcolors.NORMAL, alert_color_bg, condition))
print('------------------------------')
# Post data to phant and log to file
for i in range(0, 3):
temp_clk = 'CLK' + str(i)
#try:
# p.log(sn, temp_clk, str(freq[i]), str(data[i]), test_pass[i])
#except:
# print('Could not log data to data.recursiv.com')
output = '{},{},{},{},{},{},{}'.format(str(datetime.utcnow()), sku, sn, temp_clk, str(freq[i]), str(data[i]), test_pass[i])
try:
file.write(output + '\n')
except:
print('Could not write data to logfile')
# Clear the data stores
del data[:]
del test_pass[:]
# Give option to continue
while True:
i = raw_input('[Enter] to continue or [q] to quit: ')
if(i == 'q'):
keep_going = False
# Close the LXI interfaces
dsa815.close
#ds1052z.close
break
else:
keep_going = True;
ser.flushInput()
ser.flushOutput()
ser.write('I')
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment