Rev Author Line No. Line
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  
3629 kaklik 15 import logging
16 logging.basicConfig(level=logging.DEBUG)
17  
18  
3585 kakl 19 #### Script Arguments ###############################################
20  
21 if (len(sys.argv) != 3):
22 sys.stderr.write("Invalid number of arguments.\n")
23 sys.stderr.write("Usage: %s PORT_ADDRESS/0 REQUIERED_MHz\n" % (sys.argv[0], ))
24 sys.exit(1)
25  
26 port = eval(sys.argv[1])
27 #### Sensor Configuration ###########################################
28  
29 cfg = config.Config(
3629 kaklik 30 i2c = {
31 "port": port,
32 },
3585 kakl 33 bus = [
34 {
35 "type": "i2chub",
3629 kaklik 36 "address": 0x72,
3585 kakl 37 "children": [
3629 kaklik 38 { "name":"clkgen", "type":"clkgen01", "channel": 7, },
3585 kakl 39 ],
40 },
41 ],
42 )
43 cfg.initialize()
44  
3586 kakl 45 fgen = cfg.get_device("clkgen")
3585 kakl 46 sys.stdout.write("Frequency will be set to " + sys.argv[2] + " MHz.\r\n")
3629 kaklik 47  
48 time.sleep(3)
49 fgen.route()
3586 kakl 50 fgen.reset() # Reset Si570 to 10 MHz
3585 kakl 51 time.sleep(3)
3586 kakl 52 fgen = cfg.get_device("clkgen") # Reopen CP2112
53 fgen.set_freq(10., float(eval(sys.argv[2]))) # Set frequency
3585 kakl 54 sys.stdout.write("Done.\r\n")
55 sys.stdout.flush()
56 sys.exit(0)
57