diff --git a/ohmpi/hardware_components/mb_2023_0_X.py b/ohmpi/hardware_components/mb_2023_0_X.py index 4b6f2b0dd0b6ee8d8005babfd340bf29c5559a4a..b900f80f7ba0a06bcac09c9af3aa91cda4a10e9d 100644 --- a/ohmpi/hardware_components/mb_2023_0_X.py +++ b/ohmpi/hardware_components/mb_2023_0_X.py @@ -144,7 +144,7 @@ class Tx(TxAbstract): self.pin1 = self.mcp_board.get_pin(1) self.pin1.direction = Direction.OUTPUT self.polarity = 0 - self.adc_gain = 2 / 3 + self.gain = 2 / 3 # MCP23008 pins for LEDs self.pin4 = self.mcp_board.get_pin(4) # TODO: Delete me? No LED on this version of the board @@ -154,11 +154,11 @@ class Tx(TxAbstract): self.exec_logger.event(f'{self.board_name}\ttx_init\tend\t{datetime.datetime.utcnow()}') @property - def adc_gain(self): + def gain(self): return self._adc_gain - @adc_gain.setter - def adc_gain(self, value): + @gain.setter + def gain(self, value): assert value in [2/3, 2, 4, 8, 16] self._adc_gain = value self._ads_current = ads.ADS1115(self.connection, gain=self.adc_gain, @@ -171,7 +171,7 @@ class Tx(TxAbstract): 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}') - self.adc_gain = gain + self.gain = gain self.exec_logger.event(f'{self.board_name}\ttx_adc_auto_gain\tend\t{datetime.datetime.utcnow()}') def current_pulse(self, **kwargs): diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py index 00f2738c92ccdc9b69315a74d5260a5c0b19a9bb..cd9b9bc0b2ad39e05422dc8aa1e3b8e4d1967c95 100644 --- a/ohmpi/hardware_system.py +++ b/ohmpi/hardware_system.py @@ -173,11 +173,14 @@ class OhmPiHardware: def _gain_auto(self, polarities=(1, -1)): # TODO: improve _gain_auto self.exec_logger.event(f'OhmPiHardware\ttx_rx_gain_auto\tbegin\t{datetime.datetime.utcnow()}') current, voltage = 0., 0. + gains = [] for pol in polarities: self.tx.polarity = pol # self.tx_sync.wait() # set gains automatically injection = Thread(target=self._inject, kwargs={'injection_duration': 0.2, 'polarity': pol}) + self.tx.gain_auto() + gains.append(self.tx.gain) readings = Thread(target=self._read_values) readings.start() injection.start()