Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pslab/instrument/analog.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ def resolution(self, value: int):
self._calibrate()

def _calibrate(self):
"""
Calculates the scaling coefficients based on current gain and resolution.

This updates the internal _scale and _unscale callables as a side effect,
preparing them to convert between raw integer ADC values and floating
point voltages.
"""
A = INPUT_RANGES[self._name][0] / self._gain
B = INPUT_RANGES[self._name][1] / self._gain
slope = B - A
Expand Down Expand Up @@ -243,4 +250,4 @@ def lowres_waveform_table(self) -> np.ndarray:
def _range_normalize(self, x: np.ndarray, norm: int = 1) -> np.ndarray:
"""Normalize waveform table to the digital output range."""
x = (x - self.RANGE[0]) / (self.RANGE[1] - self.RANGE[0]) * norm
return np.int16(np.round(x)).tolist()
return np.int16(np.round(x)).tolist()
2 changes: 1 addition & 1 deletion tests/test_spi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
CS = "LA3"
SPIMaster._primary_prescaler = PPRE = 0
SPIMaster._secondary_prescaler = SPRE = 0
PWM_FERQUENCY = SPIMaster._frequency * 2 / 3
PWM_FERQUENCY = 166666.67
MICROSECONDS = 1e-6
RELTOL = 0.05
# Number of expected logic level changes.
Expand Down