diff --git a/adi/ad4630.py b/adi/ad4630.py index dbdcce2156..352d140ecf 100644 --- a/adi/ad4630.py +++ b/adi/ad4630.py @@ -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", + ] _complex_data = False _data_type = np.uint32 _device_name = "" @@ -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.""" - 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.""" - 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.""" diff --git a/examples/ad4630/ad4630_example_simple_plot.py b/examples/ad4630/ad4630_example_simple_plot.py index 3f86de1f93..eea9c59205 100644 --- a/examples/ad4630/ad4630_example_simple_plot.py +++ b/examples/ad4630/ad4630_example_simple_plot.py @@ -3,6 +3,7 @@ # SPDX short identifier: ADIBSD +import argparse import sys import matplotlib.pyplot as plt @@ -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 @@ -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() diff --git a/supported_parts.md b/supported_parts.md index 4138edacf9..9542d50d02 100644 --- a/supported_parts.md +++ b/supported_parts.md @@ -19,6 +19,7 @@ - AD4002 (AD4006, AD4010) - AD4003 (AD4007, AD4011) - AD4020 +- AD4030-24 - AD405x - AD4080 - AD4130 @@ -33,6 +34,10 @@ - AD4170 - AD4190 - AD4630 +- AD4630-16 +- AD4630-24 +- AD4632-16 +- AD4632-24 - AD4696 - AD4697 - AD4698 diff --git a/test/emu/devices/adaq4216.xml b/test/emu/devices/adaq4216.xml new file mode 100644 index 0000000000..ba46cac458 --- /dev/null +++ b/test/emu/devices/adaq4216.xml @@ -0,0 +1 @@ +]> diff --git a/test/emu/hardware_map.yml b/test/emu/hardware_map.yml index 4166460884..9ed68b621b 100644 --- a/test/emu/hardware_map.yml +++ b/test/emu/hardware_map.yml @@ -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: