From b160c8563869dbfd5518a55540b4362b1a5dd44c Mon Sep 17 00:00:00 2001 From: Alexander Bessman Date: Wed, 10 Feb 2021 09:30:23 +0100 Subject: [PATCH] Fix incorrect reported current on PCS After setting the current to zero, the reported current was 3.3 mA. The actual current was correct, i.e. zero. --- pslab/instrument/power_supply.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pslab/instrument/power_supply.py b/pslab/instrument/power_supply.py index c83b7bfb..7180ffdd 100644 --- a/pslab/instrument/power_supply.py +++ b/pslab/instrument/power_supply.py @@ -211,7 +211,17 @@ def current(self): @current.setter def current(self, value: float): - raw = 0 if value == 0 else self.unscale(value) - raw = int(np.clip(raw, 0, self._RESOLUTION)) - self._multi_write(raw) - self._current = self.scale(raw) + # Output current is a function of the voltage set on the MCP4728's V+ + # pin (assuming negligible load resistance): + # I(V) = 3.3e-3 - V / 1000 + # I.e. the lower the voltage the higher the current. However, the + # function is discontinuous in V = 0: + # I(0) = 0 + if value == 0: + self._multi_write(0) + self._current = 0 + else: + raw = self.unscale(value) + raw = int(np.clip(raw, 0, self._RESOLUTION)) + self._multi_write(raw) + self._current = self.scale(raw)