A
This commit is contained in:
@@ -40,6 +40,13 @@ AMPLITUDE = 10
|
||||
COUNT = 100
|
||||
|
||||
|
||||
class aux_ch:
|
||||
def __init__(self, id):
|
||||
self.id = id
|
||||
self.data = []
|
||||
self.done = False
|
||||
|
||||
|
||||
class ImpedanceAnalyzer:
|
||||
def __init__(self, gen_addr: str, osc_addr: str):
|
||||
self.gen: siglent.SiglentGen = siglent.SiglentGen(gen_addr)
|
||||
@@ -69,6 +76,8 @@ class ImpedanceAnalyzer:
|
||||
self.gen.channels[GEN_CHANNEL].apply_sine(freq, self.amplitude, self.dc)
|
||||
self.gen.channels[GEN_CHANNEL].set_output(True)
|
||||
|
||||
self.autoscale()
|
||||
|
||||
self.osc.run()
|
||||
time.sleep(1)
|
||||
|
||||
@@ -76,11 +85,6 @@ class ImpedanceAnalyzer:
|
||||
|
||||
time.sleep(0.3)
|
||||
|
||||
channel_A_data = self.getScaledWaveform(OSC_CHANNEL_A)
|
||||
channel_B_data = self.getScaledWaveform(OSC_CHANNEL_B)
|
||||
|
||||
self.osc.single()
|
||||
time.sleep(2)
|
||||
channel_A_data = self.osc.getChannel(OSC_CHANNEL_A).getWaveform()
|
||||
channel_B_data = self.osc.getChannel(OSC_CHANNEL_B).getWaveform()
|
||||
|
||||
@@ -138,6 +142,48 @@ class ImpedanceAnalyzer:
|
||||
|
||||
return data
|
||||
|
||||
def autoscale(self):
|
||||
channels = []
|
||||
|
||||
channels.append(aux_ch(1))
|
||||
channels.append(aux_ch(2))
|
||||
|
||||
while not (channels[0].done and channels[1].done):
|
||||
self.osc.single()
|
||||
time.sleep(1)
|
||||
for ch in channels:
|
||||
ch.data = self.osc.getChannel(ch.id).getWaveform()
|
||||
|
||||
minimum = np.min(ch.data)
|
||||
maximum = np.max(ch.data)
|
||||
|
||||
scale_range = self.osc.getChannel(ch.id).getScaleRange()
|
||||
if (
|
||||
maximum / self.scales[ch.id] > UPPER_BOUND_DIV
|
||||
or minimum / self.scales[ch.id] < -UPPER_BOUND_DIV
|
||||
):
|
||||
self.scales[ch.id] = self.scales[ch.id] * 2
|
||||
if self.scales[ch.id] > scale_range[1]:
|
||||
self.scales[ch.id] = scale_range[1]
|
||||
self.osc.getChannel(ch.id).setVScale(self.scales[ch.id])
|
||||
ch.done = True
|
||||
elif (
|
||||
minimum / self.scales[ch.id] < LOWER_BOUND_DIV
|
||||
and minimum / self.scales[ch.id] > -LOWER_BOUND_DIV
|
||||
):
|
||||
self.scales[ch.id] = self.scales[ch.id] / 2
|
||||
if self.scales[ch.id] < scale_range[0]:
|
||||
self.scales[ch.id] = scale_range[0]
|
||||
self.osc.getChannel(ch.id).setVScale(self.scales[ch.id])
|
||||
ch.done = True
|
||||
else:
|
||||
ch.done = True
|
||||
|
||||
self.osc.getChannel(ch.id).setVScale(self.scales[ch.id])
|
||||
print(
|
||||
f"Channel {ch.id} settings: min: {ch.id}, max: {ch.id} scale:{self.scales[ch.id]}"
|
||||
)
|
||||
|
||||
def getSweep(self, start: float, stop: float, samples):
|
||||
f = np.logspace(start, stop, samples, endpoint=True, base=10.0)
|
||||
z_array = []
|
||||
@@ -150,50 +196,6 @@ class ImpedanceAnalyzer:
|
||||
def calculateVRMS(self, array):
|
||||
return np.sqrt(np.sum(np.pow(array, 2)) / len(array))
|
||||
|
||||
def autoscale(self, channel):
|
||||
|
||||
vpp = 0
|
||||
|
||||
while True:
|
||||
# rms = self.osc.getChannel(channel).getVrms()[0]
|
||||
self.osc.single()
|
||||
|
||||
data = self.osc.getChannel(channel).getWaveform()
|
||||
time.sleep(1)
|
||||
# rms = self.calculateVRMS(data)
|
||||
minimum = np.min(data)
|
||||
maximum = np.max(data)
|
||||
|
||||
scale_range = self.osc.getChannel(channel).getScaleRange()
|
||||
|
||||
if (
|
||||
maximum / self.scales[channel] > UPPER_BOUND_DIV
|
||||
or minimum / self.scales[channel] < -UPPER_BOUND_DIV
|
||||
):
|
||||
self.scales[channel] = self.scales[channel] * 2
|
||||
if self.scales[channel] > scale_range[1]:
|
||||
self.scales[channel] = scale_range[1]
|
||||
self.osc.getChannel(channel).setVScale(self.scales[channel])
|
||||
break
|
||||
elif (
|
||||
minimum / self.scales[channel] < LOWER_BOUND_DIV
|
||||
and minimum / self.scales[channel] > -LOWER_BOUND_DIV
|
||||
):
|
||||
self.scales[channel] = self.scales[channel] / 2
|
||||
if self.scales[channel] < scale_range[0]:
|
||||
self.scales[channel] = scale_range[0]
|
||||
self.osc.getChannel(channel).setVScale(self.scales[channel])
|
||||
break
|
||||
else:
|
||||
break
|
||||
|
||||
self.osc.getChannel(channel).setVScale(self.scales[channel])
|
||||
print(
|
||||
f"Autoscaled channel: {channel}, RMS: {rms}, Vpp:{vpp}, Scale:{self.scales[channel]}"
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
def PlotBH(self, freq, amplitude):
|
||||
setWindowSize(self.osc, 2, freq)
|
||||
|
||||
@@ -273,7 +275,8 @@ def main():
|
||||
# imp.PlotBH(10e3, AMPLITUDE)
|
||||
|
||||
# return 0
|
||||
z, f = imp.getSweep(5, 5, 1)
|
||||
imp.autoscale()
|
||||
z, f = imp.getSweep(5, 8, 12)
|
||||
|
||||
z_real = np.real(z)
|
||||
z_imag = np.imag(z)
|
||||
|
||||
Reference in New Issue
Block a user