From aa72d7ed40293587dd089f7f337215253e44fea9 Mon Sep 17 00:00:00 2001 From: Marcelo Schmitt Date: Wed, 22 May 2024 16:36:04 -0300 Subject: [PATCH] examples: ad4020_example: Calculate voltage using driver scale attribute The scale may vary according to ADC characteristics such as precision bits, span compression, gain, etc. and also with setup properties such as voltage reference. Use driver provided scale to convert back to milli-voltage units which is the standard IIO unit for voltage type channels. Signed-off-by: Marcelo Schmitt --- examples/ad4020_example.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/ad4020_example.py b/examples/ad4020_example.py index ec7e7f084..71083c195 100644 --- a/examples/ad4020_example.py +++ b/examples/ad4020_example.py @@ -26,7 +26,7 @@ data = my_adc.rx() x = np.arange(0, len(data)) -voltage = data * 2.0 * vref / (2 ** 20) +voltage = data * my_adc.voltage0.scale dc = np.average(voltage) # Extract DC component ac = voltage - dc # Extract AC component @@ -35,7 +35,7 @@ plt.title(dev_name.upper() + " Time Domain Data") plt.plot(x, voltage) plt.xlabel("Data Point") -plt.ylabel("Voltage (V)") +plt.ylabel("Voltage (mV)") plt.show() f, Pxx_spec = signal.periodogram( @@ -49,7 +49,7 @@ plt.semilogy(f, Pxx_abs) plt.ylim([1e-6, 4]) plt.xlabel("frequency [Hz]") -plt.ylabel("Voltage (V)") +plt.ylabel("Voltage (mV)") plt.draw() plt.pause(0.05)