diff --git a/qcodes/instrument_drivers/__init__.py b/qcodes/instrument_drivers/__init__.py index e69de29bb2d1..bd33da07dd44 100644 --- a/qcodes/instrument_drivers/__init__.py +++ b/qcodes/instrument_drivers/__init__.py @@ -0,0 +1 @@ +from .devices import VoltageDivider diff --git a/qcodes/instrument_drivers/devices.py b/qcodes/instrument_drivers/devices.py new file mode 100644 index 000000000000..0294b3ddf8e9 --- /dev/null +++ b/qcodes/instrument_drivers/devices.py @@ -0,0 +1,93 @@ +from typing import Union + +from qcodes import Parameter, StandardParameter + + +class VoltageDivider(Parameter): + """ + Resitive voltage divider + + To be used when you use a physical voltage divider to set or get a voltage. + + Initialize the voltage diveder by passing the parameter to be measured + and the value of the division (which should be calibrated beforehand) + + >>> vd = VoltageDivider(dac.chan0, 10) + + The voltage divider acts a your original parameter, but will set the right + value, and store the division_value in the metadata. + + Set the value you want to set your device at 10 V + + >>> vd(10) + + This will set the dac.cha0 at 10*10, but upon measuring the divider + the value returned is the voltage at the sample. + + >>> vd() + 10 + + To get the voltage that was actually set on the instrument: + + >>> vd.get_instrument_value() + 100 + + + + Args: + v1: Parameter physically attached to the divider as input + division_value: the divsion value of the divider + label: label of this parameter, by default uses v1 label + but attaches _attenuated + name: name of this parameter, by default uses v1 name + but attaches _attenuated + """ + + def __init__(self, + v1: StandardParameter, + division_value: Union[int, float], + name: str=None, + label: str=None) -> None: + self.v1 = v1 + self.division_value = division_value + if label: + self.label = label + else: + self.label = "{}_attenuated".format(self.v1.label) + + if name: + self.name = name + else: + self.name = "{}_attenuated".format(self.v1.name) + + super().__init__( + name=self.name, + instrument=getattr(self.v1, "_instrument", None), + label=self.label, + unit=self.v1.unit, + metadata=self.v1.metadata) + + # extend metadata + self._meta_attrs.extend(['v1', 'division_value']) + + def set(self, value: Union[int, float]) -> None: + instrument_value = value * self.division_value + self._save_val(value) + self.v1.set(instrument_value) + + def get(self) -> Union[int, float]: + """ + Returns: + number: value at which was set at the sample + """ + value = self.v1.get() / self.division_value + self._save_val(value) + return value + + def get_instrument_value(self) -> Union[int, float]: + """ + Returns: + number: value at which the attached paraemter is (i.e. does + not account for the scaling) + """ + return self.v1.get()