From aab98e568c5dee004fb75d1147f264563eb19098 Mon Sep 17 00:00:00 2001 From: awatlet <arnaud.watlet@umons.ac.be> Date: Wed, 4 Oct 2023 12:20:24 +0200 Subject: [PATCH] Fixes gain_auto --- dev/test_mb_2023_0_X.py | 4 ++-- ohmpi/hardware_components/mb_2023_0_X.py | 8 ++++++-- ohmpi/hardware_system.py | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dev/test_mb_2023_0_X.py b/dev/test_mb_2023_0_X.py index 04dfe529..67878d2f 100644 --- a/dev/test_mb_2023_0_X.py +++ b/dev/test_mb_2023_0_X.py @@ -17,8 +17,8 @@ print(f'TX current: {tx.current:.3f} mA') print(f'RX voltage: {rx.voltage:.3f} mV') tx.inject(state='on', polarity=1) -tx.adc_gain_auto() -rx.adc_gain_auto() +tx._adc_gain_auto() +rx._adc_gain_auto() r = [] for i in range(30): r.append(rx.voltage/tx.current) diff --git a/ohmpi/hardware_components/mb_2023_0_X.py b/ohmpi/hardware_components/mb_2023_0_X.py index c403a7f0..f7d078b9 100644 --- a/ohmpi/hardware_components/mb_2023_0_X.py +++ b/ohmpi/hardware_components/mb_2023_0_X.py @@ -167,7 +167,7 @@ class Tx(TxAbstract): self._ads_current.mode = Mode.CONTINUOUS self.exec_logger.debug(f'Setting TX ADC gain to {value}') - def adc_gain_auto(self): + def _adc_gain_auto(self): self.exec_logger.event(f'{self.board_name}\ttx_adc_auto_gain\tbegin\t{datetime.datetime.utcnow()}') gain = _gain_auto(AnalogIn(self._ads_current, ads.P0)) self.exec_logger.debug(f'Setting TX ADC gain automatically to {gain}') @@ -191,6 +191,8 @@ class Tx(TxAbstract): assert self.adc_voltage_min / (50 * self.r_shunt) <= value <= self.adc_voltage_max / (50 * self.r_shunt) self.exec_logger.warning(f'Current pulse is not implemented for the {self.board_name} board') + def gain_auto(self): + self._adc_gain_auto() def inject(self, polarity=1, injection_duration=None): self.polarity = polarity TxAbstract.inject(self, polarity=polarity, injection_duration=injection_duration) @@ -288,7 +290,7 @@ class Rx(RxAbstract): self._ads_voltage.mode = Mode.CONTINUOUS self.exec_logger.debug(f'Setting RX ADC gain to {value}') - def adc_gain_auto(self): + def _adc_gain_auto(self): self.exec_logger.event(f'{self.board_name}\trx_adc_auto_gain\tbegin\t{datetime.datetime.utcnow()}') gain_0 = _gain_auto(AnalogIn(self._ads_voltage, ads.P0)) gain_2 = _gain_auto(AnalogIn(self._ads_voltage, ads.P2)) @@ -297,6 +299,8 @@ class Rx(RxAbstract): self.adc_gain = gain self.exec_logger.event(f'{self.board_name}\trx_adc_auto_gain\tend\t{datetime.datetime.utcnow()}') + def gain_auto(self): + self._adc_gain_auto() @property def voltage(self): """ Gets the voltage VMN in Volts diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py index 9c70bd47..00f2738c 100644 --- a/ohmpi/hardware_system.py +++ b/ohmpi/hardware_system.py @@ -175,7 +175,7 @@ class OhmPiHardware: current, voltage = 0., 0. for pol in polarities: self.tx.polarity = pol - self.tx_sync.wait() + # self.tx_sync.wait() # set gains automatically injection = Thread(target=self._inject, kwargs={'injection_duration': 0.2, 'polarity': pol}) readings = Thread(target=self._read_values) @@ -183,6 +183,7 @@ class OhmPiHardware: injection.start() readings.join() injection.join() + v = self.readings[:, 2] != 0 current = max(current, np.mean(self.readings[v, 3])) voltage = max(voltage, np.abs(np.mean(self.readings[v, 2] * self.readings[v, 4]))) -- GitLab