Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions adi/ad4630.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ class ad4630(rx, context_manager, attribute):

""" AD4630 is low power 24-bit precision SAR ADC """

_compatible_parts = ["ad4630-24", "ad4030-24", "ad4630-16"]
_compatible_parts = [
"ad4030-24",
"ad4630-16",
"ad4630-24",
"ad4632-16",
"ad4632-24",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update supported parts MD

]
_complex_data = False
_data_type = np.uint32
_device_name = ""
Expand Down Expand Up @@ -113,26 +119,25 @@ def sample_rate(self, rate):
@property
def sample_averaging_avail(self):
"""Get list of all the sample averaging values available. Only available in 30bit averaged mode."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as below comment

return self._get_iio_dev_attr("sample_averaging_available")
return self._get_iio_dev_attr("oversampling_ratio_available")

@property
def sample_averaging(self):
"""Get the sample averaging. Only available in 30bit averaged mode."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the docstring and property name still correct? Does this apply to all supported parts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tfcollins
All parts are supported by the same drivers both in Linux and No-OS.
The IIO ABI used for controlling the sample averaging is oversampling_ratio. That applies to all supported parts.
The docstring abstracts the oversampling_ratio interface and presents it to users in terms of data sheet nomenclature (which is sample averaging). Should we update the docstrigs to match the underlying interfaces?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you be more descriptive on what this means. sample_averaging seems to be a boolean but oversampling_ratio would be an integer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sample_averaging should be an integer, not a boolean.
It is set in AD4630 averaging mode register 1 as an integer. The oversampling_ratio ABI 2 is the one that matches the sample_averaging device functionality 3. The use of oversampling_ratio is also documented within the IIO documentation 4.

return self._get_iio_dev_attr_str("sample_averaging")
return self._get_iio_dev_attr_str("oversampling_ratio")

@sample_averaging.setter
def sample_averaging(self, n_sample):
"""Set the sample averaging. Only available in 30bit averaged mode."""
if str(self.sample_averaging) != "OFF":
if str(n_sample) in str(self.sample_averaging_avail):
self._set_iio_dev_attr("sample_averaging", str(n_sample))
else:
raise ValueError(
"Error: Number of avg samples not supported \nUse one of: "
+ str(self.sample_averaging_avail)
)
"""Set the sample averaging. The device driver will automatically set
the ADC into 30bit averaged mode."""

if str(n_sample) in str(self.sample_averaging_avail):
self._set_iio_dev_attr("oversampling_ratio", str(n_sample))
else:
raise Exception("Sample Averaging only available in 30bit averaged mode.")
raise ValueError(
"Error: Number of avg samples not supported \nUse one of: "
+ str(self.sample_averaging_avail)
)

class _channel(attribute):
"""AD4x30 differential channel."""
Expand Down
43 changes: 39 additions & 4 deletions examples/ad4630/ad4630_example_simple_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX short identifier: ADIBSD


import argparse
import sys

import matplotlib.pyplot as plt
Expand All @@ -12,12 +13,44 @@

# Optionally pass URI as command line argument,
# else use default context manager search
my_uri = sys.argv[1] if len(sys.argv) >= 2 else None
print("uri: " + str(my_uri))
parser = argparse.ArgumentParser(description="AD4630 Series Example Script")
parser.add_argument(
"-u",
"--uri",
metavar="uri",
default="ip:analog.local",
help="An URI to the libiio context. e.g.: 'ip:analog.local'\
'ip:192.168.1.3'\
'serial:/dev/ttyUSB1,115200,8n1n'",
)
parser.add_argument(
"-d",
"--device",
metavar="device",
default="ad4630-24",
help="Device name. e.g.: 'ad4030-24', 'ad4632-16', 'adaq4224'",
)

device_name = "ad4630-24"
args = parser.parse_args()
print("uri: " + str(args.uri))
print("device: " + str(args.device))

if (
args.device == "ad4030-24"
or args.device == "ad4630-16"
or args.device == "ad4630-24"
or args.device == "ad4632-16"
or args.device == "ad4632-24"
):
adc = adi.ad4630(uri=args.ri, device_name=args.device)
elif (
args.device == "adaq4224" or args.device == "adaq4216" or args.device == "adaq4220"
):
adc = adi.adaq42xx(uri=args.uri, device_name=args.device)
else:
print("Error: device: " + str(args.device) + " not supported.")
quit()

adc = adi.ad4630(uri=my_uri, device_name=device_name)
adc.rx_buffer_size = 500
adc.sample_rate = 2000000

Expand All @@ -32,4 +65,6 @@
x = np.arange(0, len(data[ch]))
plt.figure(adc._ctrl.channels[ch]._name)
plt.plot(x, data[ch])
plt.xlabel("Data Point")
plt.ylabel("Voltage (mV)")
plt.show()
5 changes: 5 additions & 0 deletions supported_parts.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- AD4002 (AD4006, AD4010)
- AD4003 (AD4007, AD4011)
- AD4020
- AD4030-24
- AD405x
- AD4080
- AD4130
Expand All @@ -33,6 +34,10 @@
- AD4170
- AD4190
- AD4630
- AD4630-16
- AD4630-24
- AD4632-16
- AD4632-24
- AD4696
- AD4697
- AD4698
Expand Down
1 change: 1 addition & 0 deletions test/emu/devices/adaq4216.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE context [<!ELEMENT context (device | context-attribute)*><!ELEMENT context-attribute EMPTY><!ELEMENT device (channel | attribute | debug-attribute | buffer-attribute)*><!ELEMENT channel (scan-element?, attribute*)><!ELEMENT attribute EMPTY><!ELEMENT scan-element EMPTY><!ELEMENT debug-attribute EMPTY><!ELEMENT buffer-attribute EMPTY><!ATTLIST context name CDATA #REQUIRED version-major CDATA #REQUIRED version-minor CDATA #REQUIRED version-git CDATA #REQUIRED description CDATA #IMPLIED><!ATTLIST context-attribute name CDATA #REQUIRED value CDATA #REQUIRED><!ATTLIST device id CDATA #REQUIRED name CDATA #IMPLIED label CDATA #IMPLIED><!ATTLIST channel id CDATA #REQUIRED type (input|output) #REQUIRED name CDATA #IMPLIED><!ATTLIST scan-element index CDATA #REQUIRED format CDATA #REQUIRED scale CDATA #IMPLIED><!ATTLIST attribute name CDATA #REQUIRED filename CDATA #IMPLIED><!ATTLIST debug-attribute name CDATA #REQUIRED><!ATTLIST buffer-attribute name CDATA #REQUIRED>]><context name="xml" version-major="0" version-minor="25" version-git="5e7f76e" description="Linux analog 6.17.0-rc3-iio-zed-new+ #114 SMP PREEMPT Mon Oct 6 13:59:42 -03 2025 armv7l" ><context-attribute name="hw_model" value="EVAL-ADAQ4216-FMCZ on Xilinx Zynq ZED" /><context-attribute name="hw_carrier" value="Xilinx Zynq ZED" /><context-attribute name="local,kernel" value="6.17.0-rc3-iio-zed-new+" /><context-attribute name="uri" value="local:" /><device id="hwmon0" name="e000b000ethernetffffffff00" ><channel id="temp1" type="input" ><attribute name="crit" filename="temp1_crit" /><attribute name="input" filename="temp1_input" /><attribute name="max_alarm" filename="temp1_max_alarm" /></channel></device><device id="iio:device0" name="adaq4216" ><channel id="voltage0-voltage1" type="input" ><scan-element index="0" format="le:s16/32&gt;&gt;0" scale="0.018750" /><attribute name="calibbias" filename="in_voltage0-voltage1_calibbias" /><attribute name="calibbias_available" filename="in_voltage0-voltage1_calibbias_available" /><attribute name="calibscale" filename="in_voltage0-voltage1_calibscale" /><attribute name="calibscale_available" filename="in_voltage0-voltage1_calibscale_available" /><attribute name="label" filename="in_voltage0-voltage1_label" /><attribute name="raw" filename="in_voltage0-voltage1_raw" /><attribute name="scale" filename="in_voltage0-voltage1_scale" /><attribute name="scale_available" filename="in_voltage0-voltage1_scale_available" /></channel><channel id="voltage2" type="input" ><scan-element index="1" format="be:U8/8&gt;&gt;0" scale="16.000000" /><attribute name="label" filename="in_voltage2_label" /><attribute name="raw" filename="in_voltage2_raw" /><attribute name="scale" filename="in_voltage2_scale" /></channel><attribute name="oversampling_ratio" /><attribute name="oversampling_ratio_available" /><attribute name="sampling_frequency" /><attribute name="waiting_for_supplier" /><buffer-attribute name="data_available" /><buffer-attribute name="direction" /><buffer-attribute name="length_align_bytes" /><debug-attribute name="direct_reg_access" /></device><device id="iio_sysfs_trigger" ><attribute name="add_trigger" /><attribute name="remove_trigger" /></device></context>
8 changes: 8 additions & 0 deletions test/emu/hardware_map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,14 @@ ad4020:
- filename: ad4020.xml
- data_devices:
- iio:device0
adaq4216:
- adaq4216
- pyadi_iio_class_support:
- adaq42xx
- emulate:
- filename: adaq4216.xml
- data_devices:
- iio:device0
adaq4224:
- adaq4224
- pyadi_iio_class_support:
Expand Down
Loading