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