Skip to content

Commit

Permalink
examples/ad9094_example: Add example for AD9094
Browse files Browse the repository at this point in the history
Signed-off-by: PopPaul2021 <[email protected]>
  • Loading branch information
PopPaul2021 committed Oct 10, 2024
1 parent 5f1030f commit 21274f1
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 4 deletions.
39 changes: 35 additions & 4 deletions adi/ad9094.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,48 @@
import numpy as np
from adi.context_manager import context_manager
from adi.rx_tx import rx
from adi.sync_start import sync_start
from adi.attribute import attribute


class ad9094(sync_start, rx, context_manager):
class ad9094(rx, context_manager):
""" AD9094 Quad ADC """

_complex_data = False
_rx_channel_names = ["voltage0", "voltage1", "voltage2", "voltage3", "voltage4"]
_rx_channel_names = ["voltage0", "voltage1", "voltage2", "voltage3"]
_device_name = ""

def __init__(self, uri=""):
context_manager.__init__(self, uri, self._device_name)
self._ctrl = self._ctx.find_device("axi-ad9094-hpc")
self._rxadc = self._ctx.find_device("axi-ad9094-hpc")

self.channel = []

for name in self._rx_channel_names:
self.channel.append(self._channel(self._rxadc, name))

rx.__init__(self)

def register_read(self, reg):
"""Direct Register Access via debugfs"""
self._set_iio_debug_attr_str("direct_reg_access", reg, self._rxadc)
return self._get_iio_debug_attr_str("direct_reg_access", self._rxadc)

def register_write(self, reg, value):
"""Direct Register Access via debugfs"""
self._set_iio_debug_attr_str("direct_reg_access", f"{reg} {value}", self._rxadc)

class _channel(attribute):

"""AD9094 channel"""

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

@property
def test_mode(self):
"""AD9094 channel test mode value"""
return self._get_iio_attr_str(self.name, "test_mode", False, self._ctrl)
@test_mode.setter
def test_mode(self, value):
self._set_iio_attr(self.name, "test_mode", False, value, self._ctrl)
61 changes: 61 additions & 0 deletions examples/ad9094_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright (C) 2020 Analog Devices, Inc.
#
# SPDX short identifier: ADIBSD

import time
import sys
import adi
import math
import matplotlib.pyplot as plt
import numpy as np

url = "local:" if len(sys.argv) == 1 else sys.argv[1]
dev = adi.ad9094(url)

print("--Setting up chip")

# dev.rx_enabled_channels = [0,1,2,3]
dev.rx_buffer_size = 2 ** 16

print(" CHIP_VENDOR_ID:", dev.register_read(0xC))

print("CHIP_SCRATCH phy is:", dev.register_read(0xA))
print("Writing 0xAB to 0xA scratch register")
dev.register_write(0xA,0xAB)
print("CHIP_SCRATCH phy is:", dev.register_read(0xA))

## test_mode_available value:
## off midscale_short pos_fullscale neg_fullscale checkerboard pn_long pn_short one_zero_toggle user ramp

dev.channel[0].test_mode = "ramp"
dev.channel[1].test_mode = "ramp"
dev.channel[2].test_mode = "off"
dev.channel[3].test_mode = "ramp"

x = dev.rx()

fig, axs = plt.subplots(4, 1)

axs[0].plot(x[0])
axs[0].set_title("Channel 0 data")
axs[0].set_xlabel("Sample")
axs[0].set_ylabel("Amplitude")

axs[1].plot(x[1])
axs[1].set_title("Channel 1 data")
axs[1].set_xlabel("Sample")
axs[1].set_ylabel("Amplitude")


axs[2].plot(x[2])
axs[2].set_title("Channel 2 data")
axs[2].set_xlabel("Sample")
axs[2].set_ylabel("Amplitude")

axs[3].plot(x[3])
axs[3].set_title("Channel 3 data")
axs[3].set_xlabel("Sample")
axs[3].set_ylabel("Amplitude")

plt.tight_layout()
plt.show()

0 comments on commit 21274f1

Please sign in to comment.