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 |
|
3743 |
kaklik |
10 |
req_freq = 286.0788 # required local oscillator frequency in MHz. |
3489 |
kaklik |
11 |
|
|
|
12 |
#### Sensor Configuration ########################################### |
|
|
13 |
|
|
|
14 |
cfg = config.Config( |
3630 |
kaklik |
15 |
i2c = { |
3743 |
kaklik |
16 |
"port": 1, |
3630 |
kaklik |
17 |
}, |
3489 |
kaklik |
18 |
bus = [ |
3503 |
kaklik |
19 |
{ |
|
|
20 |
"type": "i2chub", |
3504 |
kaklik |
21 |
"address": 0x70, |
3503 |
kaklik |
22 |
"children": [ |
|
|
23 |
{ "name":"counter", "type":"acount02", "channel": 2, }, |
|
|
24 |
{ "name":"clkgen", "type":"clkgen01", "channel": 5, }, |
|
|
25 |
], |
|
|
26 |
}, |
3489 |
kaklik |
27 |
], |
|
|
28 |
) |
|
|
29 |
cfg.initialize() |
|
|
30 |
|
3630 |
kaklik |
31 |
print "RMDS Station frequency management test software \r\n" |
3489 |
kaklik |
32 |
fcount = cfg.get_device("counter") |
3498 |
kakl |
33 |
fgen = cfg.get_device("clkgen") |
3489 |
kaklik |
34 |
time.sleep(0.5) |
3492 |
kaklik |
35 |
frequency = fcount.get_freq() |
3498 |
kakl |
36 |
rfreq = fgen.get_rfreq() |
|
|
37 |
hsdiv = fgen.get_hs_div() |
|
|
38 |
n1 = fgen.get_n1_div() |
3489 |
kaklik |
39 |
|
3736 |
kakl |
40 |
''' |
|
|
41 |
# sample GPS configuration |
|
|
42 |
fcount.conf_GPS(0,5) # length of the GPS configurtion sentence |
|
|
43 |
fcount.conf_GPS(1,ord('a')) # the first byte of GPS configuration sentence |
|
|
44 |
fcount.conf_GPS(2,ord('b')) # the second byte of GPS configyration sentence |
|
|
45 |
fcount.conf_GPS(3,ord('c')) |
|
|
46 |
fcount.conf_GPS(4,ord('d')) |
|
|
47 |
fcount.conf_GPS(5,ord('e')) |
|
|
48 |
''' |
|
|
49 |
fcount.set_GPS() # set GPS configuration |
3498 |
kakl |
50 |
|
3489 |
kaklik |
51 |
#### Data Logging ################################################### |
|
|
52 |
|
|
|
53 |
try: |
3502 |
kakl |
54 |
with open("frequency.log", "a") as f: |
3492 |
kaklik |
55 |
while True: |
|
|
56 |
now = datetime.datetime.now() |
|
|
57 |
if (now.second == 15) or (now.second == 35) or (now.second == 55): |
|
|
58 |
frequency = fcount.get_freq() |
3502 |
kakl |
59 |
if (len(sys.argv) == 3): |
3743 |
kaklik |
60 |
regs = fgen.set_freq(frequency/1e6, float(req_freq)) |
3492 |
kaklik |
61 |
now = datetime.datetime.now() |
3489 |
kaklik |
62 |
|
3498 |
kakl |
63 |
rfreq = fgen.get_rfreq() |
|
|
64 |
hsdiv = fgen.get_hs_div() |
|
|
65 |
n1 = fgen.get_n1_div() |
3502 |
kakl |
66 |
fdco = (frequency/1e6) * hsdiv * n1 |
3498 |
kakl |
67 |
fxtal = fdco / rfreq |
|
|
68 |
|
|
|
69 |
sys.stdout.write("frequency: " + str(frequency) + " Hz Time: " + str(now.second)) |
|
|
70 |
sys.stdout.write(" RFREQ: " + str(rfreq) + " HSDIV: " + str(hsdiv) + " N1: " + str(n1)) |
3502 |
kakl |
71 |
sys.stdout.write(" fdco: " + str(fdco) + " fxtal: " + str(fxtal) + "\r") |
3492 |
kaklik |
72 |
f.write("%d\t%s\t%.3f\n" % (time.time(), datetime.datetime.now().isoformat(), frequency)) |
3489 |
kaklik |
73 |
|
3492 |
kaklik |
74 |
sys.stdout.flush() |
3502 |
kakl |
75 |
time.sleep(0.9) |
3489 |
kaklik |
76 |
except KeyboardInterrupt: |
3492 |
kaklik |
77 |
sys.stdout.write("\r\n") |
3489 |
kaklik |
78 |
sys.exit(0) |
3492 |
kaklik |
79 |
f.close() |