commit e75cd2ede43e7c31b9220f870932c98da4dce107
parent 4084980e5c42a72e95f2472569b0c3dcd4331dbc
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date: Fri, 21 Aug 2026 15:23:37 -0300
Actualizar `tp/scripts/owon_hds25s_bode/bode_plot.py`
Diffstat:
1 file changed, 28 insertions(+), 11 deletions(-)
diff --git a/tp/scripts/owon_hds25s_bode/bode_plot.py b/tp/scripts/owon_hds25s_bode/bode_plot.py
@@ -43,12 +43,13 @@ VOLT_SCALES = {
]
}
-LOG_ENABLE = False
-PROBE = "1X"
-GEN_PEAK = 1.00 # 2*GEN_PEAK peak to peak voltage
-FREQS_COUNT = 100
-curr_scale_idx = 2 # 500 mV startup vertical height
-scales = VOLT_SCALES.get(PROBE)
+LOG_ENABLE = False
+PROBE = "1X"
+GEN_PEAK = 0.10 # 2*GEN_PEAK peak to peak voltage
+FREQS_COUNT = 50
+MEAN_SAMPLE_COUNT = 3
+curr_scale_idx = 2 # 500 mV startup vertical height
+scales = VOLT_SCALES.get(PROBE)
def LOG(msg):
if LOG_ENABLE:
@@ -65,6 +66,7 @@ def set_best_timebase(frequency):
# Pick the closest supported value in the list
best_match = min(TIMEBASES, key=lambda x: abs(x[0] - target_scale))
LOG(f"HORizontal:SCALe {best_match[1]}")
+ time.sleep(0.1)
scope.write(f":HORizontal:SCALe {best_match[1]}")
def set_best_vert_scale():
@@ -137,14 +139,25 @@ def set_best_vert_scale():
# example: 5 decades (10^0 to 10^5) at 5 points/decade -> 5 * 5 + 1 = 26 points
# freqs = np.concatenate((np.array([1]), np.logspace(4, 5, num=FREQS_COUNT)))
-freqs = np.logspace(4, 5, num=FREQS_COUNT)
+freqs = np.logspace(0, 5, num=FREQS_COUNT)
freqs = np.unique([int(f) for f in freqs])
print(freqs)
amps = []
rm = pyvisa.ResourceManager('@py')
-scope = rm.open_resource("ASRL/dev/ttyUSB0::INSTR")
+try:
+ scope = rm.open_resource("ASRL/dev/ttyUSB0::INSTR")
+except:
+ print("[ERROR] Device not found")
+ exit(0)
+
+try:
+ data = scope.read_raw()
+ print("Pending:", data)
+except pyvisa.errors.VisaIOError as e:
+ print("No data")
+
print("Identification: ", scope.query("*IDN?"), end="")
# Configure scope
@@ -160,16 +173,20 @@ print(f"Generator set to function SINE")
for freq in freqs:
# print(f"Probing {freq:2.2f} Hz")
scope.write(f":FUNCtion:FREQuency {freq:2.2f}")
+
# print(scope.query(":FUNCtion:FREQuency?"))
set_best_timebase(freq)
# Roll mode
if freq < 10:
+ scope.write(":CH1:COUPling DC")
time.sleep(10)
+ else:
+ scope.write(":CH1:COUPling AC")
+ time.sleep(0.5)
amp_arr = []
- amp_arr_mean_sample_count = 3
- for i in range(amp_arr_mean_sample_count):
+ for i in range(MEAN_SAMPLE_COUNT):
set_best_vert_scale()
read_val_str = scope.query(":MEASurement:CH1:MAX?").strip()
LOG_LOC(f"[main_loop]", f"read_val_str == {read_val_str}")
@@ -186,7 +203,7 @@ for freq in freqs:
time.sleep(0.5) # time between mean samples
- amp_mean = (sum(amp_arr) / amp_arr_mean_sample_count)
+ amp_mean = (sum(amp_arr) / MEAN_SAMPLE_COUNT)
amp_mean = 0.001 if amp_mean < 0.001 else amp_mean
amp_norm = amp_mean / GEN_PEAK