Skip to content

Commit

Permalink
examples: ad4020_example: Calculate voltage using driver scale attribute
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
machschmitt committed May 23, 2024
1 parent 4de88bd commit aa72d7e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions examples/ad4020_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(
Expand All @@ -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)

Expand Down

0 comments on commit aa72d7e

Please sign in to comment.