aboutsummaryrefslogtreecommitdiff
path: root/qolab/hardware
diff options
context:
space:
mode:
Diffstat (limited to 'qolab/hardware')
-rw-r--r--qolab/hardware/scope/_basic.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/qolab/hardware/scope/_basic.py b/qolab/hardware/scope/_basic.py
index 861340d..7cabf3b 100644
--- a/qolab/hardware/scope/_basic.py
+++ b/qolab/hardware/scope/_basic.py
@@ -60,6 +60,7 @@ class Scope(BasicInstrument):
vertDivOnScreen = 8 # should be adjusted in hardware aware class
horizDivOnScreen = 8 # should be adjusted in hardware aware class
+ minVoltsPerDiv = 0.001 # should be adjusted in hardware aware class
def __init__(self, *args, **kwds):
BasicInstrument.__init__(self, *args, **kwds)
@@ -177,9 +178,6 @@ class Scope(BasicInstrument):
deadline = starttime + timeout
timespan = self.getTimePerDiv() * self.horizDivOnScreen
scaled_corectly = False
- # maximally zoom out to get full signal
- self.setChanVoltageOffset(chNum, 0)
- self.setChanVoltsPerDiv(chNum, 10)
self.setRun(True)
while (not scaled_corectly) and (time.time() < deadline):
@@ -195,19 +193,34 @@ class Scope(BasicInstrument):
y = tr.y.values
tr_max = y.max()
tr_min = y.min()
+ signal_range = tr_max - tr_min
margin_t = (v_max - tr_max) / v_range
margin_b = (tr_min - v_min) / v_range
- is_margin_t_good = (margin_t > margin * 0.5) and (margin_t < margin * 0.7)
- is_margin_b_good = (margin_b > margin * 0.5) and (margin_b < margin * 0.7)
+ is_margin_t_good = (margin_t > margin * 0.5) and (margin_t < margin * 1.0)
+ is_margin_b_good = (margin_b > margin * 0.5) and (margin_b < margin * 1.0)
if (is_margin_b_good) and (is_margin_t_good):
scaled_corectly = True
break
+ old_offset = offset
+ old_vPerDiv = vPerDiv
offset = -(tr_max + tr_min) / 2
- vPerDiv = (tr_max - tr_min) / (self.vertDivOnScreen * (1 - margin * 1.2))
+ if min(margin_t, margin_b) < 0.01: # too close to edge, zoom out
+ vPerDiv *= 2
+ elif (signal_range / v_range) < 0.2: # signal is too small, zoom in
+ vPerDiv /= 2
+ else:
+ vPerDiv = signal_range / (self.vertDivOnScreen * (1 - margin * 1.2))
+ if vPerDiv < self.minVoltsPerDiv:
+ vPerDiv = self.minVoltsPerDiv
logger.debug(f"Auto Scaler Requesting {offset=} for {chNum=}.")
self.setChanVoltageOffset(chNum, offset)
logger.debug(f"Auto Scaler Requesting {vPerDiv=} for {chNum=}.")
self.setChanVoltsPerDiv(chNum, vPerDiv)
+ relOffsetChange = abs(old_offset - offset) / old_vPerDiv
+ relVperDivChange = abs(old_vPerDiv - vPerDiv) / old_vPerDiv
+ if (relOffsetChange < 0.5) and (relVperDivChange < 0.05):
+ # we converge, there is no point to improve
+ break
scaled_corectly = False
if time.time() > deadline:
logger.warning(