diff --git a/ohmpi/hardware_components/mb_2024_0_2.py b/ohmpi/hardware_components/mb_2024_0_2.py index cc5dbc21d79c8a66bb2f7a71d2f6360ac9e1c0fe..5deb81270666acccc0afecdc1e9ede331b7986aa 100644 --- a/ohmpi/hardware_components/mb_2024_0_2.py +++ b/ohmpi/hardware_components/mb_2024_0_2.py @@ -130,6 +130,28 @@ class Tx(Tx_mb_2023): self.exec_logger.debug(f'Switching DPS off') self._pwr_state = 'off' + def current_pulse(self, current=None, length=None, polarity=1): + """ Generates a square voltage pulse + + Parameters + ---------- + voltage: float, optional + Voltage to apply in volts, tx_v_def is applied if omitted. + length: float, optional + Length of the pulse in seconds + polarity: 1,0,-1 + Polarity of the pulse + """ + self.exec_logger.event(f'{self.model}\ttx_current_pulse\tbegin\t{datetime.datetime.utcnow()}') + # self.exec_logger.info(f'injection_duration: {length}') # TODO: delete me + if length is None: + length = self.injection_duration + if current is not None: + self.pwr.current = current + self.exec_logger.debug(f'Current pulse of {polarity*self.pwr.voltage:.3f} V for {length:.3f} s') + self.inject(polarity=polarity, injection_duration=length) + self.exec_logger.event(f'{self.model}\ttx_current_pulse\tend\t{datetime.datetime.utcnow()}') + class Rx(Rx_mb_2023): def __init__(self, **kwargs): diff --git a/ohmpi/hardware_components/pwr_dps5005.py b/ohmpi/hardware_components/pwr_dps5005.py index 81371d35d59faab9598bd835701fd3516157f67f..8d0f29639f8bafa47691ad0ba096eba5ffc0787b 100644 --- a/ohmpi/hardware_components/pwr_dps5005.py +++ b/ohmpi/hardware_components/pwr_dps5005.py @@ -87,8 +87,8 @@ class Pwr(PwrAbstract): @current.setter def current(self, value, **kwargs): - value = value # To set DPS max current slightly above (20%) the limit to avoid regulation artefacts - self.connection.write_register(0x0001, int(value), 3) + # value = value # To set DPS max current slightly above (20%) the limit to avoid regulation artefacts + self.connection.write_register(0x0001, np.round((value), 3), 3) self._current = value # self.exec_logger.debug(f'Current cannot be set on {self.model}') diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py index 97abc7ad2d2b6b71b56539489857689b8138a2ee..c24d76852ecf5326ea46da7937b5199465e2c6b3 100644 --- a/ohmpi/hardware_system.py +++ b/ohmpi/hardware_system.py @@ -241,6 +241,11 @@ class OhmPiHardware: self.tx.voltage_pulse(length=injection_duration, polarity=polarity) self.exec_logger.event(f'OhmPiHardware\tinject\tend\t{datetime.datetime.utcnow()}') + def _inject_current(self, polarity=1, injection_duration=None): # TODO: deal with voltage or current pulse + self.exec_logger.event(f'OhmPiHardware\tinject\tbegin\t{datetime.datetime.utcnow()}') + self.tx.current_pulse(length=injection_duration, polarity=polarity) + self.exec_logger.event(f'OhmPiHardware\tinject\tend\t{datetime.datetime.utcnow()}') + def _set_mux_barrier(self): self.mux_barrier = Barrier(len(self.mux_boards) + 1) for mux in self.mux_boards: @@ -639,6 +644,7 @@ class OhmPiHardware: if self.tx.pwr.voltage_adjustable: if self.tx.voltage != vab: self.tx.voltage = vab + self.tx.current = 0.02 else: vab = self.tx.voltage @@ -648,7 +654,7 @@ class OhmPiHardware: self.tx.pwr.pwr_state = 'on' switch_pwr_off = True # reads current and voltage during the pulse - injection = Thread(target=self._inject, kwargs={'injection_duration': duration, 'polarity': polarity}) + injection = Thread(target=self._inject_current, kwargs={'injection_duration': duration, 'polarity': polarity}) readings = Thread(target=self._read_values, kwargs={'sampling_rate': sampling_rate, 'append': append}) readings.start() injection.start()