-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Add voltage divider device (#492)
* feature: Add voltage divider device * fix: Rst polish and save metadata * fix: Save value also when getting * docs: Better docstring
- Loading branch information
1 parent
954f9f2
commit 7e7155a
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .devices import VoltageDivider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |