Rev Author Line No. Line
3489 kaklik 1 #!/usr/bin/python
3502 kakl 2 #
3630 kaklik 3 # Sample of measuring and frequency correction with ACOUNTER02A
3489 kaklik 4  
5 import time
6 import datetime
7 import sys
8 from pymlab import config
9  
10 #### Script Arguments ###############################################
11  
3502 kakl 12 if (len(sys.argv) > 3) or (len(sys.argv) < 2):
3489 kaklik 13 sys.stderr.write("Invalid number of arguments.\n")
3502 kakl 14 sys.stderr.write("Usage: %s PORT_ADDRESS [REQUIERED_MHz]\n" % (sys.argv[0], ))
3489 kaklik 15 sys.exit(1)
16  
17 port = eval(sys.argv[1])
18 #### Sensor Configuration ###########################################
19  
20 cfg = config.Config(
3630 kaklik 21 i2c = {
22 "port": port,
23 },
3489 kaklik 24 bus = [
3503 kaklik 25 {
26 "type": "i2chub",
3504 kaklik 27 "address": 0x70,
3503 kaklik 28 "children": [
29 { "name":"counter", "type":"acount02", "channel": 2, },
30 { "name":"clkgen", "type":"clkgen01", "channel": 5, },
31 ],
32 },
3489 kaklik 33 ],
34 )
35 cfg.initialize()
36  
3630 kaklik 37 print "RMDS Station frequency management test software \r\n"
3489 kaklik 38 fcount = cfg.get_device("counter")
3498 kakl 39 fgen = cfg.get_device("clkgen")
3489 kaklik 40 time.sleep(0.5)
3492 kaklik 41 frequency = fcount.get_freq()
3498 kakl 42 rfreq = fgen.get_rfreq()
43 hsdiv = fgen.get_hs_div()
44 n1 = fgen.get_n1_div()
3630 kaklik 45 #fdco = 0
46 #fxtal = 0
47 #regs = [0, 0, 0]
3489 kaklik 48  
3498 kakl 49  
3489 kaklik 50 #### Data Logging ###################################################
51  
52 try:
3502 kakl 53 with open("frequency.log", "a") as f:
3492 kaklik 54 while True:
55 now = datetime.datetime.now()
56 if (now.second == 15) or (now.second == 35) or (now.second == 55):
57 frequency = fcount.get_freq()
3502 kakl 58 if (len(sys.argv) == 3):
59 regs = fgen.set_freq(frequency/1e6, float(eval(sys.argv[2])))
3492 kaklik 60 now = datetime.datetime.now()
3489 kaklik 61  
3498 kakl 62 rfreq = fgen.get_rfreq()
63 hsdiv = fgen.get_hs_div()
64 n1 = fgen.get_n1_div()
3502 kakl 65 fdco = (frequency/1e6) * hsdiv * n1
3498 kakl 66 fxtal = fdco / rfreq
67  
68 sys.stdout.write("frequency: " + str(frequency) + " Hz Time: " + str(now.second))
69 sys.stdout.write(" RFREQ: " + str(rfreq) + " HSDIV: " + str(hsdiv) + " N1: " + str(n1))
3502 kakl 70 sys.stdout.write(" fdco: " + str(fdco) + " fxtal: " + str(fxtal) + "\r")
3492 kaklik 71 f.write("%d\t%s\t%.3f\n" % (time.time(), datetime.datetime.now().isoformat(), frequency))
3489 kaklik 72  
3492 kaklik 73 sys.stdout.flush()
3502 kakl 74 time.sleep(0.9)
3489 kaklik 75 except KeyboardInterrupt:
3492 kaklik 76 sys.stdout.write("\r\n")
3489 kaklik 77 sys.exit(0)
3492 kaklik 78 f.close()