3585 |
kakl |
1 |
#!/usr/bin/python |
|
|
2 |
# |
3586 |
kakl |
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 |
3585 |
kakl |
9 |
|
|
|
10 |
import time |
|
|
11 |
import datetime |
|
|
12 |
import sys |
|
|
13 |
from pymlab import config |
|
|
14 |
|
|
|
15 |
#### Script Arguments ############################################### |
|
|
16 |
|
|
|
17 |
if (len(sys.argv) != 3): |
|
|
18 |
sys.stderr.write("Invalid number of arguments.\n") |
|
|
19 |
sys.stderr.write("Usage: %s PORT_ADDRESS/0 REQUIERED_MHz\n" % (sys.argv[0], )) |
|
|
20 |
sys.exit(1) |
|
|
21 |
|
|
|
22 |
port = eval(sys.argv[1]) |
|
|
23 |
#### Sensor Configuration ########################################### |
|
|
24 |
|
|
|
25 |
cfg = config.Config( |
|
|
26 |
port = port, |
|
|
27 |
bus = [ |
|
|
28 |
{ |
|
|
29 |
"type": "i2chub", |
|
|
30 |
"address": 0x70, |
|
|
31 |
"children": [ |
|
|
32 |
{ "name":"clkgen", "type":"clkgen01", "channel": 5, }, |
|
|
33 |
], |
|
|
34 |
}, |
|
|
35 |
], |
|
|
36 |
) |
|
|
37 |
cfg.initialize() |
|
|
38 |
|
3586 |
kakl |
39 |
fgen = cfg.get_device("clkgen") |
3585 |
kakl |
40 |
sys.stdout.write("Frequency will be set to " + sys.argv[2] + " MHz.\r\n") |
3586 |
kakl |
41 |
fgen.reset() # Reset Si570 to 10 MHz |
3585 |
kakl |
42 |
time.sleep(3) |
3586 |
kakl |
43 |
fgen = cfg.get_device("clkgen") # Reopen CP2112 |
|
|
44 |
fgen.set_freq(10., float(eval(sys.argv[2]))) # Set frequency |
3585 |
kakl |
45 |
sys.stdout.write("Done.\r\n") |
|
|
46 |
sys.stdout.flush() |
|
|
47 |
sys.exit(0) |
|
|
48 |
|