diff --git a/ohmpi/hardware_components/abstract_hardware_components.py b/ohmpi/hardware_components/abstract_hardware_components.py index 0abc3e8261b1bb1db631841b0c0cd2cdebc1213f..977736fd22c8ff69262a0a637588be66bc645ee6 100644 --- a/ohmpi/hardware_components/abstract_hardware_components.py +++ b/ohmpi/hardware_components/abstract_hardware_components.py @@ -379,7 +379,7 @@ class RxAbstract(ABC): self._adc_gain = 1. self._max_sampling_rate = np.inf self._latency = kwargs.pop('latency', 0.) - self._bias = 0. + self._bias = kwargs.pop('bias', 0.) @property def adc_gain(self): diff --git a/ohmpi/hardware_components/ohmpi_card_3_15.py b/ohmpi/hardware_components/ohmpi_card_3_15.py index 20c93a1016c40e072d84543896a192b23ed70d6d..2a88de919c5b35c44fbf9e7253073de6565b127d 100644 --- a/ohmpi/hardware_components/ohmpi_card_3_15.py +++ b/ohmpi/hardware_components/ohmpi_card_3_15.py @@ -30,6 +30,8 @@ RX_CONFIG['sampling_rate'] = RX_CONFIG.pop('sampling_rate', sampling_rate) RX_CONFIG['data_rate'] = RX_CONFIG.pop('data_rate', data_rate) RX_CONFIG['coef_p2'] = RX_CONFIG.pop('coef_p2', 2.5) RX_CONFIG['latency'] = RX_CONFIG.pop('latency', 0.01) +RX_CONFIG['bias'] = RX_CONFIG.pop('bias', 0.) + # *** TX *** # ADC for current @@ -52,6 +54,8 @@ TX_CONFIG['default_voltage'] = np.min([TX_CONFIG.pop('default_voltage', np.inf), # TX_CONFIG['pwr_switch_on_warm_up'] = TX_CONFIG.pop('pwr_switch_on_warmup', pwr_switch_on_warmup) TX_CONFIG['mcp_board_address'] = TX_CONFIG.pop('mcp_board_address', tx_mcp_board_address) TX_CONFIG['low_battery'] = TX_CONFIG.pop('low_battery', low_battery) +TX_CONFIG['latency'] = TX_CONFIG.pop('latency', 0.01) +TX_CONFIG['bias'] = TX_CONFIG.pop('bias', 0.) def _gain_auto(channel): @@ -115,6 +119,8 @@ class Tx(TxAbstract): self.pin4 = self.mcp_board.get_pin(4) # Ohmpi_run self.pin4.direction = Direction.OUTPUT self.pin4.value = True + self._latency = kwargs.pop('latency', TX_CONFIG['latency']) + self._bias = kwargs.pop('bias', TX_CONFIG['bias']) self.exec_logger.event(f'{self.board_name}\ttx_init\tend\t{datetime.datetime.utcnow()}') @property @@ -228,6 +234,8 @@ class Rx(RxAbstract): self._coef_p2 = kwargs.pop('coef_p2', RX_CONFIG['coef_p2']) self._voltage_max = kwargs.pop('voltage_max', RX_CONFIG['voltage_max']) self._sampling_rate = kwargs.pop('sampling_rate', sampling_rate) + self._latency = kwargs.pop('latency', RX_CONFIG['latency']) + self._bias = kwargs.pop('bias', RX_CONFIG['bias']) self.exec_logger.event(f'{self.board_name}\trx_init\tend\t{datetime.datetime.utcnow()}') @property @@ -256,6 +264,6 @@ class Rx(RxAbstract): """ Gets the voltage VMN in Volts """ self.exec_logger.event(f'{self.board_name}\trx_voltage\tbegin\t{datetime.datetime.utcnow()}') - u = -AnalogIn(self._ads_voltage, ads.P0, ads.P1).voltage * self._coef_p2 * 1000. - self._bias # TODO: check if it should be negated + u = -AnalogIn(self._ads_voltage, ads.P0, ads.P1).voltage * self._coef_p2 * 1000. + self._bias # TODO: check if it should be negated self.exec_logger.event(f'{self.board_name}\trx_voltage\tend\t{datetime.datetime.utcnow()}') return u diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py index 262d98415214ea762377e04240d7d500f231457f..eb9491a7cd0bfbdfc182baf5d7ed842a83394b80 100644 --- a/ohmpi/hardware_system.py +++ b/ohmpi/hardware_system.py @@ -323,7 +323,8 @@ class OhmPiHardware: plt.show() def calibrate_rx_bias(self): - self.rx._bias = (np.mean(self.readings[self.readings[:, 2] == 1, 4]) + np.mean(self.readings[self.readings[:, 2] == -1, 4])) / 2. + self.rx._bias = (np.mean(self.readings[self.readings[:, 2] == 1, 4]) + + np.mean(self.readings[self.readings[:, 2] == -1, 4])) / 2. def vab_square_wave(self, vab, cycle_duration, sampling_rate=None, cycles=3, polarity=1, append=False): self.exec_logger.event(f'OhmPiHardware\tvab_square_wave\tbegin\t{datetime.datetime.utcnow()}')