-
Notifications
You must be signed in to change notification settings - Fork 4
/
calibrate.py
48 lines (41 loc) · 1.55 KB
/
calibrate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from tests import *
import tests
import pickle
def calibrate():
# Set up test system.
setup()
# Have user disconnect TARGET-C cable so we can power it without a load.
# Using TARGET-C because it won't power up the EUT if they get it wrong.
request("disconnect TARGET-C cable from EUT")
connect_boost_supply_to('TARGET-C')
# Power TARGET-C at 5V and calibrate lower range.
with group("Calibrating low range"):
set_boost_supply(5.0, 0.1)
# Boost converter needs a moment to stabilise on first startup.
sleep(0.1)
scale_low = 5.0 / test_vbus('TARGET-C', Range(4.9, 5.1))
item(f"Calibration factor: {info(scale_low)}")
with group("Calibrating current offset"):
current_offset = test_boost_current(Range(0, 0.15))
item(f"Offset: {info(current_offset)}")
# Increase voltage to 15V and repeat.
with group("Calibrating high range"):
set_boost_supply(15.0, 0.1)
scale_high = 15.0 / test_vbus('TARGET-C', Range(14.5, 15.5))
item(f"Calibration factor: {info(scale_high)}")
# Write out calibration.
calibration = dict(
greatfet_serial=state.gf.serial_number(),
voltage_scale_lower=scale_low,
voltage_scale_upper=scale_high,
current_offset=current_offset,
)
pickle.dump(calibration, open('calibration.dat', 'wb'))
if __name__ == "__main__":
try:
with error_conversion():
calibrate()
ok("Calibration complete")
except CynthionTestError as error:
fail(error)
reset()