diff --git a/dev/test_mb_2023_0_X.py b/dev/test_mb_2023_0_X.py index 04dfe529d679a698b2137ed915ccdb97009589e6..67878d2fd4ab1d66a3ff2d6a1c944e44cdf48068 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 c403a7f083c35642203001cec84483f24bdf7970..f7d078b91496eadd019ee2ad10e26a69f411e670 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 9c70bd47deaef4b41ec4ab64ab4694adbd379de2..00f2738c92ccdc9b69315a74d5260a5c0b19a9bb 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])))