Commit 828365b8 authored by Matthieu Cattin's avatar Matthieu Cattin

test19: Fix bug, reset correction registers before calibration.

Add FMC temperature in the calibration data to be stored in the EEPROM.
Write measurement values to a file (for validation in another test).
parent 71e432d9
......@@ -67,14 +67,17 @@ RANGES = ['10V', '1V', '100mV']
# Number of repeatition of the measurement, then the results are averaged
REPEAT = 2
# ADC LSB values for each input range
ADC_LSB = {'10V':10.0/2**14, '1V':1.0/2**14, '100mV':0.1/2**14}
# Disconnect inputs of all channels
def disconnect_channels(fmc):
for i in range(1,NB_CHANNELS+1):
fmc.set_ssr(i, 0x00)
time.sleep(SSR_SET_SLEEP)
# Initialise acquisition
def fmc_adc_init(spec, fmc):
print('Initialise FMC board\n')
# Reset offset DACs
......@@ -83,6 +86,9 @@ def fmc_adc_init(spec, fmc):
disconnect_channels(fmc)
# Reset offset DACs
fmc.dc_offset_reset()
# Set ADC offset correction to 0 and gain correction to 1
for ch in range(1, NB_CHANNELS+1):
fmc.set_adc_gain_offset_corr(ch, 0x8000, 0x0)
# Set trigger
fmc.set_soft_trig()
# Set acquisition
......@@ -130,6 +136,7 @@ def volt2digital_without_offset(value, full_scale, nb_bit):
#print('volt2digital: %2.9f > %2.9f')%(value,digital)
return int(digital)
# Make an acquisition of a channel
def acq_channel(carrier, fmc, ch, adc_fs, adc_nbits=16, pause=0.01):
# Make sure no acquisition is running
fmc.stop_acq()
......@@ -161,6 +168,7 @@ def acq_channel(carrier, fmc, ch, adc_fs, adc_nbits=16, pause=0.01):
channel_data = channels_data[ch-1::4]
return mean(channel_data)
# Plot data from all channels
def plot_all(data, mean, ylimit):
sample = arange(len(data)/4)
clf()
......@@ -179,6 +187,7 @@ def plot_all(data, mean, ylimit):
show()
return 0
# Set channel offset with the DAC
def set_offset_dac(fmc, channel, offset_volt, dac_fs=10.0, dac_nbits=16, dac_corr_flag=False):
dac_v = offset_volt
dac_d = volt2digital(dac_v,dac_fs,dac_nbits)
......@@ -189,6 +198,7 @@ def set_offset_dac(fmc, channel, offset_volt, dac_fs=10.0, dac_nbits=16, dac_cor
fmc.set_dc_offset(channel,dac_d)
time.sleep(DAC_SET_SLEEP)
# Make a measurement, where the input and offset DAC values are set to a known value
def make_meas(carrier, fmc, box, dac_value, in_value, in_range, adc_fs, repeat):
ch_meas = []
ch_diff = []
......@@ -257,6 +267,8 @@ def main (default_directory = '.'):
AWG_BAUD = 57600
CALIBR_FILENAME = "calibration_data.txt"
RAW_CALIBR_FILENAME = "calibration_raw_data.txt"
MEAS_FILENAME = "calibration_meas.txt"
start_test_time = time.time()
......@@ -324,27 +336,35 @@ def main (default_directory = '.'):
print "%5s: %1.5fV" % (item[0], float(item[1]))
# Dict to store ADC calibration data
adc_corr_data = {'10V':{'offset':[],'gain':[]},
'1V':{'offset':[],'gain':[]},
'100mV':{'offset':[],'gain':[]}}
adc_corr_data = {'10V':{'offset':[],'gain':[],'temp':0},
'1V':{'offset':[],'gain':[],'temp':0},
'100mV':{'offset':[],'gain':[],'temp':0}}
# Dict to store DAC calibration data
dac_corr_data = {'10V':{'offset':[],'gain':[]},
'1V':{'offset':[],'gain':[]},
'100mV':{'offset':[],'gain':[]}}
dac_corr_data = {'10V':{'offset':[],'gain':[],'temp':0},
'1V':{'offset':[],'gain':[],'temp':0},
'100mV':{'offset':[],'gain':[],'temp':0}}
############################################################################
# Calibration
error = 0
f_out = open(RAW_CALIBR_FILENAME, 'w')
for IN_RANGE in RANGES:
print "\n--------------------------------------------------------------------------------"
print "%s range calibration\n----------------------------------\n"%(IN_RANGE)
for ch in range(1,NB_CHANNELS+1):
print "Channel %d ADC gain correction register : 0x%04X" % (ch, fmc.get_adc_gain_corr(ch))
print "Channel %d ADC offset correction register: 0x%04X" % (ch, fmc.get_adc_offset_corr(ch))
print ""
print "SPEC temperature: %3.3f°C" % carrier.get_temp()
print "FMC temperature : %3.3f°C" % fmc.get_temp()
adc_corr_data[IN_RANGE]['temp'] = fmc.get_temp()
print "FMC temperature : %3.3f°C" % adc_corr_data[IN_RANGE]['temp']
print "\nADC LSB:%1.9f"%(ADC_LSB[IN_RANGE])
......@@ -368,12 +388,12 @@ def main (default_directory = '.'):
v_meas.append(mean)
d_meas.append(diff)
for ch in range(1,NB_CHANNELS+1):
print "Channel %d: v_meas=%02.9fV delta=%1.9f"%(ch, v_meas[i][ch-1], d_meas[i][ch-1])
print "Channel %d: v_meas=%02.9fV delta=%1.9fV"%(ch, v_meas[i][ch-1], d_meas[i][ch-1])
print " Check voltage stability"
meas = d_meas[i][ch-1]
expect = (2*ADC_LSB[IN_RANGE])
if meas > expect:
print " ERROR: measure:%1.9f expect:%1.9f"%(meas, expect)
if abs(meas) > expect:
print " ERROR: measure:%1.9fV expect:+/-%1.9fV"%(meas, expect)
error += 1
else:
print " OK"
......@@ -392,21 +412,25 @@ def main (default_directory = '.'):
for ch in range(1,NB_CHANNELS+1):
ga.append(calc_ga(v_meas[0][ch-1], v_meas[1][ch-1], vref_in))
print "Channel %d ADC gain coeff: %02.9f"%(ch, ga[ch-1])
f_out.write('%.30f\n'%(ga[ch-1]))
oa = []
for ch in range(1,NB_CHANNELS+1):
oa.append(calc_oa(v_meas[1][ch-1], v_meas[2][ch-1], v_meas[3][ch-1]))
print "Channel %d ADC offset : %02.9f"%(ch, oa[ch-1])
f_out.write('%.30f\n'%(oa[ch-1]))
gd = []
for ch in range(1,NB_CHANNELS+1):
gd.append(calc_gd(v_meas[0][ch-1], v_meas[1][ch-1], v_meas[2][ch-1], vref_in, vref_dac))
print "Channel %d DAC gain coeff: %02.9f"%(ch, gd[ch-1])
f_out.write('%.30f\n'%(gd[ch-1]))
od = []
for ch in range(1,NB_CHANNELS+1):
od.append(calc_od(v_meas[0][ch-1], v_meas[1][ch-1], v_meas[2][ch-1], v_meas[3][ch-1], vref_in))
print "Channel %d DAC offset : %02.9f"%(ch, od[ch-1])
f_out.write('%.30f\n'%(od[ch-1]))
#-----------------------------------------------------------------------
# Calculate ADC correction register values
......@@ -430,6 +454,8 @@ def main (default_directory = '.'):
# to be written in offset correction register
dac_corr_data[IN_RANGE]['offset'] = [-(volt2digital_without_offset(item,DAC_FS,DAC_NBITS)) for item in od]
f_out.close()
############################################################################
......@@ -444,21 +470,43 @@ def main (default_directory = '.'):
for IN_RANGE in RANGES:
#print "%s range"%(IN_RANGE)
for item in adc_corr_data[IN_RANGE]['offset']:
#print '0x%.4X,yes'%(signed2hex(item))
print "0x%04X" % (signed2hex(item))
f_out.write('0x%.4X\n'%(signed2hex(item)))
for item in adc_corr_data[IN_RANGE]['gain']:
#print '0x%.4X,yes'%(signed2hex(item))
print "0x%04X" % (signed2hex(item))
f_out.write('0x%.4X\n'%(signed2hex(item)))
temp = adc_corr_data[IN_RANGE]['temp']*100
print "0x%04X, %d" % (temp, temp)
f_out.write('0x%.4X\n'%(temp))
print "\nWrite DAC correction data to %s"%(out_filename)
for IN_RANGE in RANGES:
#print "%s range"%(IN_RANGE)
for item in dac_corr_data[IN_RANGE]['offset']:
#print '0x%.4X,yes'%(signed2hex(item))
print "0x%04X" % (signed2hex(item))
f_out.write('0x%.4X\n'%(signed2hex(item)))
for item in dac_corr_data[IN_RANGE]['gain']:
#print '0x%.4X,yes'%(signed2hex(item))
print "0x%04X" % (signed2hex(item))
f_out.write('0x%.4X\n'%(signed2hex(item)))
temp = adc_corr_data[IN_RANGE]['temp']*100
print "0x%04X, %d" % (temp, temp)
f_out.write('0x%.4X\n'%(temp))
f_out.close()
############################################################################
############################################################################
# Write calibration measurment to file
out_filename = MEAS_FILENAME
f_out = open(out_filename, 'w')
print "\n--------------------------------------------------------------------------------"
print "\nWrite calibration measurement to %s"%(out_filename)
print v_meas
for meas in v_meas:
for ch in meas:
print "%.30f" % ch
f_out.write('%.30f\n'%ch)
f_out.close()
############################################################################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment