Commit c94a86ad authored by Remi Clement's avatar Remi Clement
Browse files

Merge branch 'board_v4' of https://gitlab.irstea.fr/reversaal/OhmPi into board_v4

Showing with 22 additions and 19 deletions
+22 -19
......@@ -5,8 +5,8 @@ mqtt_broker = 'localhost'
# OhmPi configuration
OHMPI_CONFIG = {
'id': '0001', # Unique identifier of the OhmPi board (string)
'R_shunt': 1, # Shunt resistance in Ohms
'Imax': 4800/50/1, # Maximum current
'R_shunt': 2, # Shunt resistance in Ohms
'Imax': 4800/50/2, # Maximum current
'coef_p2': 2.50, # slope for current conversion for ADS.P2, measurement in V/V
'coef_p3': 2.50, # slope for current conversion for ADS.P3, measurement in V/V
'offset_p2': 0,
......@@ -17,7 +17,7 @@ OHMPI_CONFIG = {
'board_address': {'A': 0x72, 'B': 0x73, 'M': 0x70, 'N': 0x71}, # def. {'A': 0x76, 'B': 0x71, 'M': 0x74, 'N': 0x70}
#'board_address': {'A': 0x70, 'B': 0x71, 'M': 0x72, 'N': 0x73}, # def. {'A': 0x76, 'B': 0x71, 'M': 0x74, 'N': 0x70}
'settings': 'ohmpi_settings.json',
'board_version': '22.11',
'board_version': '22.10',
} # TODO: add a dictionary with INA models and associated gain values
CONTROL_CONFIG = {
......
......@@ -114,10 +114,12 @@ class OhmPi(object):
self.mcp = MCP23008(self.i2c, address=0x20)
# ADS1115 for current measurement (AB)
self.ads_current = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=128, address=0x49)
self.ads_current_address = 0x48
self.ads_current = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=self.ads_current_address)
# ADS1115 for voltage measurement (MN)
self.ads_voltage = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=128, address=0x48)
self.ads_voltage_address = 0x49
self.ads_voltage = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=self.ads_voltage_address)
# current injection module
if self.idps:
......@@ -178,6 +180,7 @@ class OhmPi(object):
self.r_shunt = OHMPI_CONFIG['R_shunt'] # reference resistance value in ohm
self.Imax = OHMPI_CONFIG['Imax'] # maximum current
self.exec_logger.warning(f'The maximum current cannot be higher than {self.Imax} mA')
self.coef_p2 = OHMPI_CONFIG['coef_p2'] # slope for current conversion for ads.P2, measurement in V/V
self.nb_samples = OHMPI_CONFIG['integer'] # number of samples measured for each stack
self.version = OHMPI_CONFIG['version'] # hardware version
self.max_elec = OHMPI_CONFIG['max_elec'] # maximum number of electrodes
......@@ -461,8 +464,8 @@ class OhmPi(object):
time.sleep(best_tx_injtime) # inject for given tx time
# autogain
self.ads_current = ads.ADS1115(self.i2c, gain=2/3, data_rate=860, address=0x49)
self.ads_voltage = ads.ADS1115(self.i2c, gain=2/3, data_rate=860, address=0x48)
self.ads_current = ads.ADS1115(self.i2c, gain=2/3, data_rate=860, address=self.ads_current_address)
self.ads_voltage = ads.ADS1115(self.i2c, gain=2/3, data_rate=860, address=self.ads_voltage_address)
#print('current P0', AnalogIn(self.ads_current, ads.P0).voltage)
#print('voltage P0', AnalogIn(self.ads_voltage, ads.P0).voltage)
#print('voltage P2', AnalogIn(self.ads_voltage, ads.P2).voltage)
......@@ -471,8 +474,8 @@ class OhmPi(object):
gain_voltage2 = self.gain_auto(AnalogIn(self.ads_voltage, ads.P2))
gain_voltage = np.min([gain_voltage0, gain_voltage2])
#print('gain current: {:.3f}, gain voltage: {:.3f}'.format(gain_current, gain_voltage))
self.ads_current = ads.ADS1115(self.i2c, gain=gain_current, data_rate=860, address=0x49)
self.ads_voltage = ads.ADS1115(self.i2c, gain=gain_voltage, data_rate=860, address=0x48)
self.ads_current = ads.ADS1115(self.i2c, gain=gain_current, data_rate=860, address=self.ads_current_address)
self.ads_voltage = ads.ADS1115(self.i2c, gain=gain_voltage, data_rate=860, address=self.ads_voltage_address)
# we measure the voltage on both A0 and A2 to guess the polarity
I = (AnalogIn(self.ads_current, ads.P0).voltage) * 1000/50/self.r_shunt # measure current
......@@ -602,8 +605,8 @@ class OhmPi(object):
polarity = 1
# first reset the gain to 2/3 before trying to find best gain (mode 0 is continuous)
self.ads_current = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=0x49, mode=0)
self.ads_voltage = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=0x48, mode=0)
self.ads_current = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=self.ads_current_address, mode=0)
self.ads_voltage = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=self.ads_voltage_address, mode=0)
# turn on the power supply
oor = False
......@@ -630,8 +633,8 @@ class OhmPi(object):
self.pin0.value = False
self.pin1.value = False
self.exec_logger.debug('Gain current: {:.3f}, gain voltage: {:.3f}'.format(gain_current, gain_voltage))
self.ads_current = ads.ADS1115(self.i2c, gain=gain_current, data_rate=860, address=0x49, mode=0)
self.ads_voltage = ads.ADS1115(self.i2c, gain=gain_voltage, data_rate=860, address=0x48, mode=0)
self.ads_current = ads.ADS1115(self.i2c, gain=gain_current, data_rate=860, address=self.ads_current_address, mode=0)
self.ads_voltage = ads.ADS1115(self.i2c, gain=gain_voltage, data_rate=860, address=self.ads_voltage_address, mode=0)
self.pin0.value = False
self.pin1.value = False
......@@ -674,7 +677,7 @@ class OhmPi(object):
else:
meas[k, 1] = AnalogIn(self.ads_voltage, ads.P2).voltage * 1000 *-1
elif self.board_version == '22.10':
meas[k, 1] = AnalogIn(self.ads_voltage, ads.P0, ads.P1).voltage * 1000
meas[k, 1] = -AnalogIn(self.ads_voltage, ads.P0, ads.P1).voltage * self.coef_p2 * 1000
#else:
# self.exec_logger.debug('Unknown board')
time.sleep(sampling_interval / 1000)
......@@ -704,7 +707,7 @@ class OhmPi(object):
else:
measpp[k, 1] = AnalogIn(self.ads_voltage, ads.P2).voltage * 1000 *-1
elif self.board_version == '22.10':
measpp[k, 1] = AnalogIn(self.ads_voltage, ads.P0, ads.P1).voltage * 1000
measpp[k, 1] = -AnalogIn(self.ads_voltage, ads.P0, ads.P1).voltage * self.coef_p2 * 1000
else:
self.exec_logger.debug('unknown board')
time.sleep(sampling_interval / 1000)
......
......@@ -8,7 +8,7 @@ m = a + 1
n = a + 2
seq = np.c_[a, b, m, n]
k = OhmPi(idps=True)
k = OhmPi(idps=False)
k.settings['injection_duration'] = 0.5
k.settings['nb_stack'] = 1
k.settings['nbr_meas'] = 1
......@@ -24,10 +24,10 @@ k.settings['nbr_meas'] = 1
#k.rs_check(tx_volt=12)
# x = []
for i in range(5):
out = k.run_measurement(injection_duration=0.5, nb_stack=2, strategy='constant', tx_volt=12, autogain=True)
for i in range(3):
out = k.run_measurement(injection_duration=2, nb_stack=2, strategy='constant', tx_volt=5, autogain=False)
#x.append(out['R [ohm]'])
k.append_and_save('out.csv', out)
#k.append_and_save('out.csv', out)
data = out['fulldata']
inan = ~np.isnan(data[:,0])
......
Supports Markdown
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