1 |
#!/usr/bin/python |
1 |
#!/usr/bin/python |
2 |
# |
2 |
# |
3 |
# Utility for setting frequency of Si570 |
3 |
# Utility for setting frequency of Si570 without a frequency measurement. |
- |
|
4 |
# The factory calibration is used for changing the frequency. |
- |
|
5 |
# This utility reset the Si570 to factory default 10 MHz first and than set a new frequency. |
- |
|
6 |
# |
- |
|
7 |
# This utility use an USBI2C01A module. |
- |
|
8 |
# (c) MLAB 2014 |
4 |
|
9 |
|
5 |
import time |
10 |
import time |
6 |
import datetime |
11 |
import datetime |
7 |
import sys |
12 |
import sys |
8 |
from pymlab import config |
13 |
from pymlab import config |
9 |
|
14 |
|
10 |
#### Script Arguments ############################################### |
15 |
#### Script Arguments ############################################### |
11 |
|
16 |
|
12 |
if (len(sys.argv) != 3): |
17 |
if (len(sys.argv) != 3): |
13 |
sys.stderr.write("Invalid number of arguments.\n") |
18 |
sys.stderr.write("Invalid number of arguments.\n") |
14 |
sys.stderr.write("Usage: %s PORT_ADDRESS/0 REQUIERED_MHz\n" % (sys.argv[0], )) |
19 |
sys.stderr.write("Usage: %s PORT_ADDRESS/0 REQUIERED_MHz\n" % (sys.argv[0], )) |
15 |
sys.exit(1) |
20 |
sys.exit(1) |
16 |
|
21 |
|
17 |
port = eval(sys.argv[1]) |
22 |
port = eval(sys.argv[1]) |
18 |
#### Sensor Configuration ########################################### |
23 |
#### Sensor Configuration ########################################### |
19 |
|
24 |
|
20 |
cfg = config.Config( |
25 |
cfg = config.Config( |
21 |
port = port, |
26 |
port = port, |
22 |
bus = [ |
27 |
bus = [ |
23 |
{ |
28 |
{ |
24 |
"type": "i2chub", |
29 |
"type": "i2chub", |
25 |
"address": 0x70, |
30 |
"address": 0x70, |
26 |
"children": [ |
31 |
"children": [ |
27 |
{ "name":"clkgen", "type":"clkgen01", "channel": 5, }, |
32 |
{ "name":"clkgen", "type":"clkgen01", "channel": 5, }, |
28 |
], |
33 |
], |
29 |
}, |
34 |
}, |
30 |
], |
35 |
], |
31 |
) |
36 |
) |
32 |
cfg.initialize() |
37 |
cfg.initialize() |
33 |
|
38 |
|
34 |
fgen = cfg.get_device("clkgen") |
39 |
fgen = cfg.get_device("clkgen") |
35 |
sys.stdout.write("Frequency will be set to " + sys.argv[2] + " MHz.\r\n") |
40 |
sys.stdout.write("Frequency will be set to " + sys.argv[2] + " MHz.\r\n") |
36 |
fgen.reset() |
41 |
fgen.reset() # Reset Si570 to 10 MHz |
37 |
time.sleep(3) |
42 |
time.sleep(3) |
38 |
fgen = cfg.get_device("clkgen") |
43 |
fgen = cfg.get_device("clkgen") # Reopen CP2112 |
39 |
fgen.set_freq(10., float(eval(sys.argv[2]))) |
44 |
fgen.set_freq(10., float(eval(sys.argv[2]))) # Set frequency |
40 |
sys.stdout.write("Done.\r\n") |
45 |
sys.stdout.write("Done.\r\n") |
41 |
sys.stdout.flush() |
46 |
sys.stdout.flush() |
42 |
sys.exit(0) |
47 |
sys.exit(0) |
43 |
|
48 |
|