Skip to content

Commit

Permalink
Merge pull request #446 from nsacut/dev/ad7768_4
Browse files Browse the repository at this point in the history
Adding Support for AD7768-4
  • Loading branch information
tfcollins authored Jun 29, 2023
2 parents b9a6c78 + a743056 commit 03aa90a
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 2 deletions.
2 changes: 1 addition & 1 deletion adi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from adi.ad7606 import ad7606
from adi.ad7689 import ad7689
from adi.ad7746 import ad7746
from adi.ad7768 import ad7768
from adi.ad7768 import ad7768, ad7768_4
from adi.ad7799 import ad7799
from adi.ad9081 import ad9081
from adi.ad9081_mc import QuadMxFE, ad9081_mc
Expand Down
34 changes: 34 additions & 0 deletions adi/ad7768.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,22 @@ def __init__(
self._ctrl = self._ctx.find_device("ad7768")
self._rxadc = self._ctx.find_device("ad7768")
self._device_name = "ad7768"

if not self._rxadc:
self._ctrl = self._ctx.find_device("cf_axi_adc")
self._rxadc = self._ctx.find_device("cf_axi_adc")
self._device_name = "cf_axi_adc"

if not self._ctrl:
raise Exception("Error in selecting matching device")

if not self._rxadc:
raise Exception("Error in selecting matching device")

for ch in self._rxadc.channels:
name = ch._id
self._rx_channel_names.append(name)

rx.__init__(self)

@property
Expand Down Expand Up @@ -95,3 +103,29 @@ def filter_type(self, ftype):
"Error: Filter type not supported \nUse one of: "
+ str(self.filter_type_avail)
)


class ad7768_4(ad7768):

""" AD7768 4-channel, Simultaneous Sampling Sigma-Delta ADC """

@property
def sync_start_enable_available(self):
"""Get available sync start enable types."""
return self._get_iio_dev_attr_str("sync_start_enable_available")

@property
def sync_start_enable(self):
"""Get sync start enable."""
return self._get_iio_dev_attr_str("sync_start_enable")

@sync_start_enable.setter
def sync_start_enable(self, ftype):
"""Set sync start enable."""
if ftype in self.sync_start_enable_available:
self._set_iio_dev_attr_str("sync_start_enable", ftype)
else:
raise ValueError(
"Error: Sync start enable not supported \nUse one of: "
+ str(self.sync_start_enable_available)
)
70 changes: 70 additions & 0 deletions examples/ad7768_4_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright (C) 2023 Analog Devices, Inc.
#
# SPDX short identifier: ADIBSD

import sys
from time import sleep

import adi
import matplotlib.pyplot as plt


def display_settings(power_mode, sampling_frequency, filter_type, rx_enabled_channels):
print("Power Mode: ", power_mode)
print("Sampling Frequency: ", sampling_frequency)
print("Filter Type: ", filter_type)
print("Enabled Channels: ", rx_enabled_channels)


# Optionally pass URI as command line argument,
# else use default ip:analog.local
my_uri = sys.argv[1] if len(sys.argv) >= 2 else "ip:analog.local"
print("uri: " + str(my_uri))

my_adc = adi.ad7768_4(uri=my_uri, device_name="ad7768-4")
my_adc.rx_buffer_size = 1024

# Set Sample Rate. Options are 1ksps to 256ksps, 1k* power of 2.
# Note that sample rate and power mode are not orthogonal - refer
# to datasheet.
my_adc.sampling_frequency = 8000

# Choose a power mode:
# my_adc.power_mode_avail = [LOW_POWER_MODE, MEDIAN_MODE, FAST_MODE]
my_adc.power_mode = "FAST_MODE"

# Choose a filter type:
# my_adc.filter_type_avail = [WIDEBAND, SINC5]
my_adc.filter_type = "WIDEBAND"

# Choose output format:
my_adc.rx_output_type = "SI"

# Verify settings:
display_settings(
my_adc.power_mode,
my_adc.sampling_frequency,
my_adc.filter_type,
my_adc.rx_enabled_channels,
)

plt.clf()
sleep(0.5)
data = my_adc.rx()
for ch in my_adc.rx_enabled_channels:
plt.plot(range(0, len(data[0])), data[ch], label="voltage" + str(ch))
plt.xlabel("Data Point")
if my_adc.rx_output_type == "SI":
plt.ylabel("Millivolts")
else:
plt.ylabel("ADC counts")
plt.legend(
bbox_to_anchor=(0.0, 1.02, 1.0, 0.102),
loc="lower left",
ncol=4,
mode="expand",
borderaxespad=0.0,
)
plt.pause(0.01)

del my_adc
1 change: 1 addition & 0 deletions supported_parts.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
- AD7195
- AD7291
- AD7768
- AD7768-4
- AD7770
- AD7771
- AD7779
Expand Down
1 change: 1 addition & 0 deletions test/emu/devices/ad7768-4.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 description CDATA #IMPLIED><!ATTLIST context-attribute name CDATA #REQUIRED value CDATA #REQUIRED><!ATTLIST device id CDATA #REQUIRED name 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 value CDATA #IMPLIED><!ATTLIST debug-attribute name CDATA #REQUIRED value CDATA #IMPLIED><!ATTLIST buffer-attribute name CDATA #REQUIRED value CDATA #IMPLIED>]><context name="network" description="192.168.10.102 Linux analog 5.10.0-98744-g64e7a607b659 #1788 SMP PREEMPT Fri Mar 31 16:51:05 EEST 2023 armv7l" ><context-attribute name="hdl_system_id" value="[ad7768evb] on [zed] git branch [hdl_2021_r2] git [a83056b11d6b092d342b72c68ef713b362b10521] clean [2023-03-31 19:46:25] UTC" /><context-attribute name="hw_model" value="EVAL-AD7768FMCZ on Xilinx Zynq ZED" /><context-attribute name="hw_carrier" value="Xilinx Zynq ZED" /><context-attribute name="hw_mezzanine" value="EVAL-AD7768FMCZ" /><context-attribute name="hw_name" value="AD7768" /><context-attribute name="hw_vendor" value="Analog Devices" /><context-attribute name="hw_serial" value="Empty Field" /><context-attribute name="local,kernel" value="5.10.0-98744-g64e7a607b659" /><context-attribute name="uri" value="ip:192.168.10.102" /><context-attribute name="ip,ip-addr" value="192.168.10.102" /><device id="hwmon0" name="e000b000ethernetffffffff00" ><channel id="temp1" type="input" ><attribute name="crit" filename="temp1_crit" value="100000" /><attribute name="input" filename="temp1_input" value="49000" /><attribute name="max_alarm" filename="temp1_max_alarm" value="0" /></channel></device><device id="iio:device1" name="cf_axi_adc" ><channel id="voltage0" type="input" ><scan-element index="0" format="le:s24/32&gt;&gt;0" scale="0.000488" /><attribute name="label" filename="in_voltage0_label" value="ERROR" /><attribute name="scale" filename="in_voltage_scale" value="0.000488281" /></channel><channel id="voltage1" type="input" ><scan-element index="1" format="le:s24/32&gt;&gt;0" scale="0.000488" /><attribute name="label" filename="in_voltage1_label" value="ERROR" /><attribute name="scale" filename="in_voltage_scale" value="0.000488281" /></channel><channel id="voltage2" type="input" ><scan-element index="2" format="le:s24/32&gt;&gt;0" scale="0.000488" /><attribute name="label" filename="in_voltage2_label" value="ERROR" /><attribute name="scale" filename="in_voltage_scale" value="0.000488281" /></channel><channel id="voltage3" type="input" ><scan-element index="3" format="le:s24/32&gt;&gt;0" scale="0.000488" /><attribute name="label" filename="in_voltage3_label" value="ERROR" /><attribute name="scale" filename="in_voltage_scale" value="0.000488281" /></channel><attribute name="filter_type" value="SINC5" /><attribute name="filter_type_available" value="WIDEBAND SINC5" /><attribute name="power_mode" value="FAST_MODE" /><attribute name="power_mode_available" value="LOW_POWER_MODE MEDIAN_MODE FAST_MODE" /><attribute name="sampling_frequency" value="32000" /><attribute name="sampling_frequency_available" value="1000 2000 4000 8000 16000 32000 64000 128000 256000" /><attribute name="sync_start_enable" value="arm" /><attribute name="sync_start_enable_available" value="arm" /><buffer-attribute name="data_available" value="0" /><buffer-attribute name="length_align_bytes" value="8" /><debug-attribute name="pseudorandom_err_check" value="ERROR" /><debug-attribute name="direct_reg_access" value="0x0" /></device><device id="iio:device2" name="xadc" ><channel id="voltage5" name="vccoddr" type="input" ><attribute name="raw" filename="in_voltage5_vccoddr_raw" value="2056" /><attribute name="scale" filename="in_voltage5_vccoddr_scale" value="0.732421875" /></channel><channel id="voltage0" name="vccint" type="input" ><attribute name="raw" filename="in_voltage0_vccint_raw" value="1399" /><attribute name="scale" filename="in_voltage0_vccint_scale" value="0.732421875" /></channel><channel id="voltage4" name="vccpaux" type="input" ><attribute name="raw" filename="in_voltage4_vccpaux_raw" value="2465" /><attribute name="scale" filename="in_voltage4_vccpaux_scale" value="0.732421875" /></channel><channel id="temp0" type="input" ><attribute name="offset" filename="in_temp0_offset" value="-2219" /><attribute name="raw" filename="in_temp0_raw" value="2649" /><attribute name="scale" filename="in_temp0_scale" value="123.040771484" /></channel><channel id="voltage7" name="vrefn" type="input" ><attribute name="raw" filename="in_voltage7_vrefn_raw" value="14" /><attribute name="scale" filename="in_voltage7_vrefn_scale" value="0.732421875" /></channel><channel id="voltage1" name="vccaux" type="input" ><attribute name="raw" filename="in_voltage1_vccaux_raw" value="2467" /><attribute name="scale" filename="in_voltage1_vccaux_scale" value="0.732421875" /></channel><channel id="voltage2" name="vccbram" type="input" ><attribute name="raw" filename="in_voltage2_vccbram_raw" value="1396" /><attribute name="scale" filename="in_voltage2_vccbram_scale" value="0.732421875" /></channel><channel id="voltage3" name="vccpint" type="input" ><attribute name="raw" filename="in_voltage3_vccpint_raw" value="1394" /><attribute name="scale" filename="in_voltage3_vccpint_scale" value="0.732421875" /></channel><channel id="voltage6" name="vrefp" type="input" ><attribute name="raw" filename="in_voltage6_vrefp_raw" value="1718" /><attribute name="scale" filename="in_voltage6_vrefp_scale" value="0.732421875" /></channel><attribute name="sampling_frequency" value="961538" /></device><device id="iio_sysfs_trigger" ><attribute name="add_trigger" value="ERROR" /><attribute name="remove_trigger" value="ERROR" /></device></context>
11 changes: 10 additions & 1 deletion test/emu/hardware_map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,16 @@ ad7768:
- filename: ad7768.xml
- data_devices:
- iio:device0


ad7768-4:
- ad7768-4
- pyadi_iio_class_support:
- ad7768_4
- emulate:
- filename: ad7768-4.xml
- data_devices:
- iio:device0

ad5592r:
- ad5592r
- pyadi_iio_class_support:
Expand Down
41 changes: 41 additions & 0 deletions test/test_ad7768_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest

hardware = ["ad7768-4"]
classname = "adi.ad7768_4"

#########################################
@pytest.mark.iio_hardware(hardware, True)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize("channel", [0, 1, 2, 3])
def test_ad7768_4_rx_data(test_dma_rx, iio_uri, classname, channel):
test_dma_rx(iio_uri, classname, channel)


#########################################
@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
"attr, val",
[
(
"sampling_frequency",
[
1000,
2000,
4000,
8000,
16000,
32000,
64000,
128000,
256000,
32000,
], # End on a rate compatible with all power modes
),
("filter_type", ["WIDEBAND", "SINC5"],),
("power_mode", ["MEDIAN_MODE", "FAST_MODE"],),
("sync_start_enable", ["arm"],),
],
)
def test_ad7768_4_attr(test_attribute_multipe_values, iio_uri, classname, attr, val):
test_attribute_multipe_values(iio_uri, classname, attr, val, 0)

0 comments on commit 03aa90a

Please sign in to comment.