/Designs/Measuring_instruments/RMDS01C/SW/Host_controller/frequency_log.py
1,4 → 1,6
#!/usr/bin/python
#
# Sample of measiring and correct frequency with ACOUNTER02A
 
import time
import datetime
7,9 → 9,9
 
#### Script Arguments ###############################################
 
if len(sys.argv) != 2:
if (len(sys.argv) > 3) or (len(sys.argv) < 2):
sys.stderr.write("Invalid number of arguments.\n")
sys.stderr.write("Usage: %s PORT ADDRESS\n" % (sys.argv[0], ))
sys.stderr.write("Usage: %s PORT_ADDRESS [REQUIERED_MHz]\n" % (sys.argv[0], ))
sys.exit(1)
 
port = eval(sys.argv[1])
34,34 → 36,34
n1 = fgen.get_n1_div()
fdco = 0
fxtal = 0
regs = [0, 0, 0]
 
fgen.set_rfreq(0x2D1E127AD)
fgen.set_hs_div(4)
fgen.set_n1_div(8)
 
#### Data Logging ###################################################
 
try:
with open("temperature.log", "a") as f:
with open("frequency.log", "a") as f:
while True:
now = datetime.datetime.now()
if (now.second == 15) or (now.second == 35) or (now.second == 55):
frequency = fcount.get_freq()
if (len(sys.argv) == 3):
regs = fgen.set_freq(frequency/1e6, float(eval(sys.argv[2])))
now = datetime.datetime.now()
 
rfreq = fgen.get_rfreq()
hsdiv = fgen.get_hs_div()
n1 = fgen.get_n1_div()
fdco = (frequency/1000000) * hsdiv * n1
fdco = (frequency/1e6) * hsdiv * n1
fxtal = fdco / rfreq
 
sys.stdout.write("frequency: " + str(frequency) + " Hz Time: " + str(now.second))
sys.stdout.write(" RFREQ: " + str(rfreq) + " HSDIV: " + str(hsdiv) + " N1: " + str(n1))
sys.stdout.write(" fdco: " + str(fdco) + " fxtal: " + str(fxtal) + "\r\n")
sys.stdout.write(" fdco: " + str(fdco) + " fxtal: " + str(fxtal) + "\r")
f.write("%d\t%s\t%.3f\n" % (time.time(), datetime.datetime.now().isoformat(), frequency))
 
sys.stdout.flush()
time.sleep(1)
time.sleep(0.9)
except KeyboardInterrupt:
sys.stdout.write("\r\n")
sys.exit(0)