-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ad3552r_hs (high speed) driver, test script, example code, rst file and emu xml. This driver is intended to be used with AXI driver version (named as high-speed, with hs suffix in Linux). Tested: - pytest - invoke precommit - pre-commit run --all-files - executed sample on target All tests passed. Signed-off-by: Angelo Dureghello <[email protected]>
- Loading branch information
1 parent
c7c4ca6
commit da47181
Showing
8 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# Copyright (C) 2024-2025 Analog Devices, Inc. | ||
# | ||
# SPDX short identifier: ADIBSD | ||
|
||
from decimal import Decimal | ||
|
||
from adi.attribute import attribute | ||
from adi.context_manager import context_manager | ||
from adi.rx_tx import tx | ||
|
||
|
||
class ad3552r_hs(tx, context_manager): | ||
"""AD3552R_HS DAC""" | ||
|
||
_complex_data = False | ||
_device_name = "AD3552R_HS" | ||
|
||
def __init__(self, uri="", device_name=""): | ||
""" Constructor for AD3552R_HS driver class """ | ||
|
||
context_manager.__init__(self, uri, self._device_name) | ||
|
||
compatible_parts = [ | ||
"ad3552r", | ||
"ad3551r", | ||
"ad3542r", | ||
"ad3541r", | ||
] | ||
|
||
self._ctrl = None | ||
self._txdac = 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}. Supported device names " | ||
f"are: {','.join(compatible_parts)}" | ||
) | ||
|
||
# Select the device matching device_name as working device | ||
for device in self._ctx.devices: | ||
if device.name == device_name: | ||
self._ctrl = device | ||
self._txdac = device | ||
break | ||
|
||
if not self._ctrl: | ||
raise Exception("Error in selecting matching device") | ||
|
||
if not self._txdac: | ||
raise Exception("Error in selecting matching device") | ||
|
||
self.output_bits = [] | ||
self.channel = [] | ||
self._tx_channel_names = [] | ||
for ch in self._ctrl.channels: | ||
name = ch._id | ||
output = ch._output | ||
self.output_bits.append(ch.data_format.bits) | ||
self._tx_channel_names.append(name) | ||
self.channel.append(self._channel(self._ctrl, name, output)) | ||
if output is True: | ||
setattr(self, name, self._channel(self._ctrl, name, output)) | ||
|
||
tx.__init__(self) | ||
|
||
@property | ||
def input_source(self): | ||
"""Input source of the DAC""" | ||
return self._get_iio_dev_attr_str("input_source", self._txdac) | ||
|
||
@input_source.setter | ||
def input_source(self, value): | ||
self._set_iio_dev_attr_str("input_source", value, self._txdac) | ||
|
||
@property | ||
def stream_status(self): | ||
"""Stream status of the DAC""" | ||
return self._get_iio_dev_attr_str("stream_status", self._txdac) | ||
|
||
@stream_status.setter | ||
def stream_status(self, value): | ||
self._set_iio_dev_attr_str("stream_status", value, self._txdac) | ||
|
||
@property | ||
def output_range(self): | ||
"""Stream status of the DAC""" | ||
return self._get_iio_dev_attr_str("output_range", self._txdac) | ||
|
||
@output_range.setter | ||
def output_range(self, value): | ||
self._set_iio_dev_attr_str("output_range", value, self._txdac) | ||
|
||
class _channel(attribute): | ||
"""AD3552R_HS channel""" | ||
|
||
def __init__(self, ctrl, channel_name, output): | ||
self.name = channel_name | ||
self._ctrl = ctrl | ||
self._output = output | ||
|
||
@property | ||
def sample_rate(self): | ||
"""Sample rate of the DAC""" | ||
return self._get_iio_attr(self.name, "sampling_frequency", True) | ||
|
||
@sample_rate.setter | ||
def sample_rate(self, value): | ||
self._set_iio_attr(self.name, "sampling_frequency", True, value) | ||
|
||
@property | ||
def raw(self): | ||
"""Get channel raw value | ||
DAC code in the range 0-65535""" | ||
return self._get_iio_attr(self.name, "raw", True) | ||
|
||
@raw.setter | ||
def raw(self, value): | ||
"""Set channel raw value""" | ||
self._set_iio_attr(self.name, "raw", True, str(int(value))) | ||
|
||
@property | ||
def offset(self): | ||
"""Get channel offset""" | ||
return self._get_iio_attr_str(self.name, "offset", True) | ||
|
||
@offset.setter | ||
def offset(self, value): | ||
"""Set channel offset""" | ||
self._set_iio_attr(self.name, "offset", True, str(Decimal(value).real)) | ||
|
||
@property | ||
def scale(self): | ||
"""Get channel scale""" | ||
return float(self._get_iio_attr_str(self.name, "scale", True)) | ||
|
||
@scale.setter | ||
def scale(self, value): | ||
self._set_iio_attr(self.name, "scale", True, str(Decimal(value).real)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
adi.ad3552r_hs module | ||
===================== | ||
|
||
.. automodule:: adi.ad3552r_hs | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import sys | ||
import time | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
import adi | ||
|
||
# Optionally passs 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)) | ||
|
||
# device connection | ||
dev = adi.ad3552r_hs(uri=my_uri, device_name="ad3552r") | ||
|
||
dev.tx_enabled_channels = [0, 1] | ||
dev.tx_cyclic_buffer = False | ||
|
||
dev._tx_data_type = np.uint16 | ||
|
||
# signal generation | ||
fs = int(dev.channel[0].sample_rate) | ||
# Signal frequency | ||
fc = 80000 | ||
# Number of samples | ||
N = int(fs / fc) | ||
# Period | ||
ts = 1 / float(fs) | ||
# Time array | ||
t = np.arange(0, N * ts, ts) | ||
# Sine generation | ||
samples = np.sin(2 * np.pi * t * fc) | ||
# Amplitude (full_scale / 2) | ||
samples *= (2 ** 15) - 1 | ||
# Offset (full_scale / 2) | ||
samples += 2 ** 15 | ||
# conversion to unsigned int and offset binary | ||
samples = np.uint16(samples) | ||
|
||
print("sample rate:", dev.channel[0].sample_rate) | ||
print("Sample data min:", samples.min()) | ||
print("Sample data max:", samples.max()) | ||
|
||
if dev.tx_cyclic_buffer == True: | ||
dev.tx([samples, samples]) | ||
else: | ||
for i in range(2): | ||
dev.tx([samples, samples]) | ||
|
||
plt.suptitle("AD3552R samples data") | ||
plt.plot(t, samples) | ||
plt.xlabel("Samples") | ||
plt.show() | ||
|
||
dev.tx_destroy_buffer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.0.166 Linux analog 6.13.0-rc7-xilinx-gfebd1b8aa9f3 #35 SMP PREEMPT Thu Jan 23 16:19:36 CET 2025 armv7l" ><context-attribute name="hw_carrier" value="Avnet ZedBoard board" /><context-attribute name="local,kernel" value="6.13.0-rc7-xilinx-gfebd1b8aa9f3" /><context-attribute name="uri" value="ip:192.168.0.166" /><context-attribute name="ip,ip-addr" value="192.168.0.166" /><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="26000" /><attribute name="max_alarm" filename="temp1_max_alarm" value="0" /></channel></device><device id="iio:device0" name="ad3552r" ><channel id="voltage0" type="output" ><scan-element index="0" format="be:U16/16>>0" scale="0.152588" /><attribute name="offset" filename="out_voltage0_offset" value="-32768.000000" /><attribute name="raw" filename="out_voltage0_raw" value="31450" /><attribute name="sampling_frequency" filename="out_voltage0_sampling_frequency" value="16666667" /><attribute name="scale" filename="out_voltage0_scale" value="0.152588" /></channel><channel id="voltage1" type="output" ><scan-element index="1" format="be:U16/16>>0" scale="0.152588" /><attribute name="offset" filename="out_voltage1_offset" value="-32768.000000" /><attribute name="raw" filename="out_voltage1_raw" value="31450" /><attribute name="sampling_frequency" filename="out_voltage1_sampling_frequency" value="16666667" /><attribute name="scale" filename="out_voltage1_scale" value="0.152588" /></channel><attribute name="waiting_for_supplier" value="0" /><buffer-attribute name="data_available" value="3328" /><buffer-attribute name="direction" value="out" /><buffer-attribute name="length_align_bytes" value="4" /></device></context> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters