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
1 change: 1 addition & 0 deletions adi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from adi.ad7689 import ad7689
from adi.ad7746 import ad7746
from adi.ad7768 import ad7768, ad7768_4
from adi.ad7768_1 import ad7768_1
from adi.ad7799 import ad7799
from adi.ad9081 import ad9081
from adi.ad9081_mc import QuadMxFE, ad9081_mc
Expand Down
117 changes: 117 additions & 0 deletions adi/ad7768_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Copyright (C) 2025 Analog Devices, Inc.
#
# SPDX short identifier: ADIBSD
from decimal import Decimal

import numpy as np

from adi.attribute import attribute
from adi.context_manager import context_manager
from adi.rx_tx import rx


class ad7768_1(rx, context_manager):

""" AD7768-1 1-channel, Dynamic Signal Analysis Sigma-Delta ADC """

_device_name = " "
_rx_data_type = np.int32

def __init__(self, uri="ip:analog.local", device_name=""):
"""Initialize."""
context_manager.__init__(self, uri, self._device_name)

compatible_parts = ["ad7768-1", "adaq7767-1", "adaq7768-1", "adaq7769-1"]

self._ctrl = None

if not device_name:
device_name = compatible_parts[0]
else:
if device_name not in compatible_parts:
raise Exception(f"Not a compatible device: {device_name}")

# Select the device matching device_name as working device
for device in self._ctx.devices:
if device.name == device_name:
self._ctrl = device
self._rxadc = device
break

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

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

self._rx_channel_names = []
self.channel = []
for ch in self._ctrl.channels:
name = ch._id
self._rx_channel_names.append(name)
self.channel.append(self._channel(self._ctrl, name))

rx.__init__(self)

@property
def sampling_frequency_available(self):
"""Get available sampling frequencies."""
return self._get_iio_dev_attr("sampling_frequency_available")

@property
def sampling_frequency(self):
"""Get sampling frequency."""
return self._get_iio_dev_attr("sampling_frequency")

@sampling_frequency.setter
def sampling_frequency(self, rate):
"""Set sampling frequency."""
if rate in self.sampling_frequency_available:
self._set_iio_dev_attr("sampling_frequency", rate)
else:
raise ValueError(
"Error: Sampling frequency not supported \nUse one of: "
+ str(self.sampling_frequency_available)
)

@property
def common_mode_voltage_available(self):
"""Get common mode voltage available."""
return self._get_iio_dev_attr_str("common_mode_voltage_available")

@property
def common_mode_voltage(self):
"""Get common mode voltage."""
return self._get_iio_dev_attr_str("common_mode_voltage")

@common_mode_voltage.setter
def common_mode_voltage(self, rate):
"""Set sampling frequency."""
if rate in self.common_mode_voltage_available:
self._set_iio_dev_attr_str("common_mode_voltage", rate)
else:
raise ValueError(
"Error: Common mode voltage not supported \nUse one of: "
+ str(self.common_mode_voltage_available)
)

class _channel(attribute):
"""AD7768-1 channel"""

def __init__(self, ctrl, channel_name):
self.name = channel_name
self._ctrl = ctrl

@property
def value(self):
"""AD7768-1 channel raw value"""
return self._get_iio_attr(self.name, "raw", False)

@property
def scale(self):
"""AD7768-1 channel scale."""
return float(self._get_iio_attr_str(self.name, "scale", False))

@scale.setter
def scale(self, value):
self._set_iio_attr(self.name, "scale", False, str(Decimal(value).real))
7 changes: 7 additions & 0 deletions doc/source/devices/adi.ad7768_1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ad7768_1
=================

.. automodule:: adi.ad7768_1
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions doc/source/devices/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Supported Devices
adi.ad7689
adi.ad7746
adi.ad7768
adi.ad7768_1
adi.ad777x
adi.ad7799
adi.ad9081
Expand Down
80 changes: 80 additions & 0 deletions examples/ad7768_1_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright (C) 2023 Analog Devices, Inc.
#
# SPDX short identifier: ADIBSD

import sys
from time import sleep

import matplotlib.pyplot as plt

import adi


def display_settings(sampling_frequency, rx_enabled_channels, common_mode_voltage):
# def display_settings(sampling_frequency, rx_enabled_channels):
print("Sampling Frequency: ", sampling_frequency)
print("Enabled Channels: ", rx_enabled_channels)
print("Common mode voltage: ", common_mode_voltage)


# Optionally pass URI as command line argument,

my_uri = sys.argv[1] if len(sys.argv) >= 2 else "ip:analog.local"
part_name = sys.argv[2].lower() if len(sys.argv) >= 3 else "adaq7768-1"

print(f"URI: {my_uri}")
print(f"Selected device: {part_name}")

# Initialize ADC depending on device name
if part_name == "ad7768-1":
my_adc = adi.ad7768_1(uri=my_uri)
elif part_name == "adaq7767-1":
my_adc = adi.adaq7767_1(uri=my_uri)
elif part_name == "adaq7768-1":
my_adc = adi.adaq7768_1(uri=my_uri)
elif part_name == "adaq7769-1":
my_adc = adi.adaq7769_1(uri=my_uri)
else:
raise ValueError(f"Unsupported device: {part_name}")

my_adc = adi.ad7768_1(uri=my_uri)
my_adc.rx_buffer_size = 1024

my_adc.sampling_frequency = 8000 # Set Sample Rate

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

my_adc.common_mode_voltage = "(AVDD1-AVSS)/2" # mV # Set common mode voltage: (AVDD1-AVSS)/2 2V5 2V05 1V9 1V65 1V1 0V9 OFF

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

# --- Live Plot Setup ---
plt.ion() # turn on interactive mode
fig, ax = plt.subplots(figsize=(10, 6)) # reasonable size for most monitors
(line,) = ax.plot([], [], label="voltage")
ax.set_xlabel("Data Point")
ax.set_ylabel("Millivolts" if my_adc.rx_output_type == "SI" else "ADC counts")
ax.legend(loc="upper right")
plt.show()

# --- Live Update Loop ---
try:
while True:
data = my_adc.rx()
data = data[1:] # skip first sample

line.set_xdata(range(len(data)))
line.set_ydata(data)

ax.relim()
ax.autoscale_view()

plt.pause(0.01)

except KeyboardInterrupt:
print("Stopped by user.")

del my_adc
4 changes: 4 additions & 0 deletions supported_parts.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
- AD7291
- AD7490
- AD7768
- AD7768-1
- AD7768-4
- AD7770
- AD7771
Expand Down Expand Up @@ -127,6 +128,9 @@
- ADAQ4216
- ADAQ4220
- ADAQ4224
- ADAQ7767-1
- ADAQ7768-1
- ADAQ7769-1
- ADAQ8092
- ADAR1000
- ADF4030
Expand Down
1 change: 1 addition & 0 deletions test/emu/devices/ad7768-1.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.3.2 Linux analog 5.15.0-175919-g427c94e8faa5 #823 SMP PREEMPT Tue Dec 12 10:08:06 EET 2023 armv7l" ><context-attribute name="hdl_system_id" value="[ad77681evb] on [zed] git branch [hdl_2022_r2] git [b31d4fbba87a96f329f858da3118771503c7c6b4] clean [2023-10-27 11:04:17] UTC" /><context-attribute name="hw_carrier" value="Xilinx Zynq ZED" /><context-attribute name="hw_model" value="EVAL-AD7768-1FMCZ on Xilinx Zynq ZED" /><context-attribute name="hw_mezzanine" value="EVAL-AD7768-1FMCZ" /><context-attribute name="hw_name" value="AD7768-1" /><context-attribute name="hw_vendor" value="Analog Devices" /><context-attribute name="hw_serial" value="Empty Field" /><context-attribute name="local,kernel" value="5.15.0-175919-g427c94e8faa5" /><context-attribute name="uri" value="ip:192.168.3.2" /><context-attribute name="ip,ip-addr" value="192.168.3.2" /><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="36000" /><attribute name="max_alarm" filename="temp1_max_alarm" value="0" /></channel></device><device id="iio:device0" name="ad7768-1" ><channel id="voltage0" type="input" ><scan-element index="0" format="le:s24/32&gt;&gt;8" scale="0.000488" /><attribute name="label" filename="in_voltage0_label" value="(null)" /><attribute name="raw" filename="in_voltage0_raw" value="-193" /><attribute name="scale" filename="in_voltage_scale" value="0.000488281" /></channel><attribute name="common_mode_voltage" value="(AVDD1-AVSS)/2" /><attribute name="common_mode_voltage_available" value="(AVDD1-AVSS)/2 2V5 2V05 1V9 1V65 1V1 0V9 OFF" /><attribute name="sampling_frequency" value="256000" /><attribute name="sampling_frequency_available" value="256000 128000 64000 32000 16000 8000 4000 2000 1000" /><buffer-attribute name="data_available" value="0" /><buffer-attribute name="length_align_bytes" value="8" /><debug-attribute name="direct_reg_access" value="0x0" /></device><device id="iio:device1" name="xadc" ><channel id="voltage5" name="vccoddr" type="input" ><attribute name="label" filename="in_voltage5_vccoddr_label" value="vccoddr" /><attribute name="raw" filename="in_voltage5_vccoddr_raw" value="2022" /><attribute name="scale" filename="in_voltage5_vccoddr_scale" value="0.732421875" /></channel><channel id="voltage0" name="vccint" type="input" ><attribute name="label" filename="in_voltage0_vccint_label" value="vccint" /><attribute name="raw" filename="in_voltage0_vccint_raw" value="1368" /><attribute name="scale" filename="in_voltage0_vccint_scale" value="0.732421875" /></channel><channel id="voltage4" name="vccpaux" type="input" ><attribute name="label" filename="in_voltage4_vccpaux_label" value="vccpaux" /><attribute name="raw" filename="in_voltage4_vccpaux_raw" value="2440" /><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="2533" /><attribute name="scale" filename="in_temp0_scale" value="123.040771484" /></channel><channel id="voltage7" name="vrefn" type="input" ><attribute name="label" filename="in_voltage7_vrefn_label" value="vrefn" /><attribute name="raw" filename="in_voltage7_vrefn_raw" value="-12" /><attribute name="scale" filename="in_voltage7_vrefn_scale" value="0.732421875" /></channel><channel id="voltage1" name="vccaux" type="input" ><attribute name="label" filename="in_voltage1_vccaux_label" value="vccaux" /><attribute name="raw" filename="in_voltage1_vccaux_raw" value="2437" /><attribute name="scale" filename="in_voltage1_vccaux_scale" value="0.732421875" /></channel><channel id="voltage2" name="vccbram" type="input" ><attribute name="label" filename="in_voltage2_vccbram_label" value="vccbram" /><attribute name="raw" filename="in_voltage2_vccbram_raw" value="1364" /><attribute name="scale" filename="in_voltage2_vccbram_scale" value="0.732421875" /></channel><channel id="voltage3" name="vccpint" type="input" ><attribute name="label" filename="in_voltage3_vccpint_label" value="vccpint" /><attribute name="raw" filename="in_voltage3_vccpint_raw" value="1367" /><attribute name="scale" filename="in_voltage3_vccpint_scale" value="0.732421875" /></channel><channel id="voltage6" name="vrefp" type="input" ><attribute name="label" filename="in_voltage6_vrefp_label" value="vrefp" /><attribute name="raw" filename="in_voltage6_vrefp_raw" value="1690" /><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>
1 change: 1 addition & 0 deletions test/emu/devices/adaq7767-1.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.3.2 Linux analog 5.15.0-175919-g427c94e8faa5 #823 SMP PREEMPT Tue Dec 12 10:08:06 EET 2023 armv7l" ><context-attribute name="hdl_system_id" value="[ad77681evb] on [zed] git branch [hdl_2022_r2] git [b31d4fbba87a96f329f858da3118771503c7c6b4] clean [2023-10-27 11:04:17] UTC" /><context-attribute name="hw_carrier" value="Xilinx Zynq ZED" /><context-attribute name="hw_model" value="EV-ADAQ7767-1FMC1Z on Xilinx Zynq ZED" /><context-attribute name="hw_mezzanine" value="EV-ADAQ7767-1FMC1Z" /><context-attribute name="hw_name" value="ADAQ7767-1" /><context-attribute name="hw_vendor" value="Analog Devices" /><context-attribute name="hw_serial" value="Empty Field" /><context-attribute name="local,kernel" value="5.15.0-175919-g427c94e8faa5" /><context-attribute name="uri" value="ip:192.168.3.2" /><context-attribute name="ip,ip-addr" value="192.168.3.2" /><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="36000" /><attribute name="max_alarm" filename="temp1_max_alarm" value="0" /></channel></device><device id="iio:device0" name="ad7768-1" ><channel id="voltage0" type="input" ><scan-element index="0" format="le:s24/32&gt;&gt;8" scale="0.000488" /><attribute name="label" filename="in_voltage0_label" value="(null)" /><attribute name="raw" filename="in_voltage0_raw" value="-193" /><attribute name="scale" filename="in_voltage_scale" value="0.000488281" /></channel><attribute name="common_mode_voltage" value="(AVDD1-AVSS)/2" /><attribute name="common_mode_voltage_available" value="(AVDD1-AVSS)/2 2V5 2V05 1V9 1V65 1V1 0V9 OFF" /><attribute name="sampling_frequency" value="256000" /><attribute name="sampling_frequency_available" value="256000 128000 64000 32000 16000 8000 4000 2000 1000" /><buffer-attribute name="data_available" value="0" /><buffer-attribute name="length_align_bytes" value="8" /><debug-attribute name="direct_reg_access" value="0x0" /></device><device id="iio:device1" name="xadc" ><channel id="voltage5" name="vccoddr" type="input" ><attribute name="label" filename="in_voltage5_vccoddr_label" value="vccoddr" /><attribute name="raw" filename="in_voltage5_vccoddr_raw" value="2022" /><attribute name="scale" filename="in_voltage5_vccoddr_scale" value="0.732421875" /></channel><channel id="voltage0" name="vccint" type="input" ><attribute name="label" filename="in_voltage0_vccint_label" value="vccint" /><attribute name="raw" filename="in_voltage0_vccint_raw" value="1368" /><attribute name="scale" filename="in_voltage0_vccint_scale" value="0.732421875" /></channel><channel id="voltage4" name="vccpaux" type="input" ><attribute name="label" filename="in_voltage4_vccpaux_label" value="vccpaux" /><attribute name="raw" filename="in_voltage4_vccpaux_raw" value="2440" /><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="2533" /><attribute name="scale" filename="in_temp0_scale" value="123.040771484" /></channel><channel id="voltage7" name="vrefn" type="input" ><attribute name="label" filename="in_voltage7_vrefn_label" value="vrefn" /><attribute name="raw" filename="in_voltage7_vrefn_raw" value="-12" /><attribute name="scale" filename="in_voltage7_vrefn_scale" value="0.732421875" /></channel><channel id="voltage1" name="vccaux" type="input" ><attribute name="label" filename="in_voltage1_vccaux_label" value="vccaux" /><attribute name="raw" filename="in_voltage1_vccaux_raw" value="2437" /><attribute name="scale" filename="in_voltage1_vccaux_scale" value="0.732421875" /></channel><channel id="voltage2" name="vccbram" type="input" ><attribute name="label" filename="in_voltage2_vccbram_label" value="vccbram" /><attribute name="raw" filename="in_voltage2_vccbram_raw" value="1364" /><attribute name="scale" filename="in_voltage2_vccbram_scale" value="0.732421875" /></channel><channel id="voltage3" name="vccpint" type="input" ><attribute name="label" filename="in_voltage3_vccpint_label" value="vccpint" /><attribute name="raw" filename="in_voltage3_vccpint_raw" value="1367" /><attribute name="scale" filename="in_voltage3_vccpint_scale" value="0.732421875" /></channel><channel id="voltage6" name="vrefp" type="input" ><attribute name="label" filename="in_voltage6_vrefp_label" value="vrefp" /><attribute name="raw" filename="in_voltage6_vrefp_raw" value="1690" /><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>
Loading