forked from M-Labs/artiq
1
0
Fork 0

novogorny: simplify and fix coefficient

This commit is contained in:
Robert Jördens 2018-02-22 23:08:50 +01:00
parent b4ba71c7a4
commit cff85ee13b
1 changed files with 8 additions and 9 deletions

View File

@ -47,20 +47,19 @@ def adc_value(data, v_ref=5.):
"""Convert a ADC result packet to SI units (Volt)"""
softspan = adc_softspan(data)
data = adc_data(data)
g = 625
if softspan & 4:
g3 = 2
else:
g3 = 1
g *= 2
if softspan & 2:
g2 = 1 << 15
h = 1 << 15
else:
g2 = 1 << 16
h = 1 << 16
data = -(data & h) + (data & ~h)
if softspan & 1:
g1 = 1000
h *= 500
else:
g1 = 1023
data = -(data & g2) + (data & ~g2)
v_per_lsb = v_ref*(1250*g3)/(g1*g2)
h *= 512
v_per_lsb = v_ref*g/h
return data*v_per_lsb