Skip to content

Commit

Permalink
Add support for ADAQ42xx
Browse files Browse the repository at this point in the history
AD4630 and ADAQ42xx designs are very similar, differing mainly on the
availability (or not) of PGIA gain.
Add input scale properties to handle ADAQ42xx PGIA control and add
ADAQ4216, ADAQ4220, and ADAQ4224 to the list of supported devices.

Signed-off-by: Marcelo Schmitt <[email protected]>
  • Loading branch information
machschmitt committed Oct 19, 2023
1 parent 1ee2658 commit 21d39f4
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 12 deletions.
95 changes: 83 additions & 12 deletions adi/ad4630.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX short identifier: ADIBSD

from decimal import Decimal

import numpy as np
from adi.attribute import attribute
Expand Down Expand Up @@ -32,6 +33,20 @@ class ad4630(rx, context_manager, attribute):

""" Default part to initialize is ad4630-24. If you don't hardware test fails"""

def __init_channels__(self):
_channels = []
self.output_bits = []
for ch in self._ctrl.channels:
self.output_bits.append(ch.data_format.bits)
self._rx_channel_names.append(ch.id)
_channels.append((ch.id, self._channel(self._ctrl, ch.id)))
if "0" in ch.id:
self.chan0 = self._channel(self._ctrl, ch.id)
if "1" in ch.id:
self.chan1 = self._channel(self._ctrl, ch.id)

rx.__init__(self)

def __init__(self, uri="", device_name="ad4630-24"):

context_manager.__init__(self, uri, self._device_name)
Expand All @@ -49,18 +64,7 @@ def __init__(self, uri="", device_name="ad4630-24"):
self._ctrl = self._ctx.find_device(device_name)
self._rxadc = self._ctx.find_device(device_name)

_channels = []
self.output_bits = []
for ch in self._ctrl.channels:
self.output_bits.append(ch.data_format.bits)
self._rx_channel_names.append(ch.id)
_channels.append((ch.id, self._channel(self._ctrl, ch.id)))
if "0" in ch.id:
self.chan0 = self._channel(self._ctrl, ch.id)
if "1" in ch.id:
self.chan1 = self._channel(self._ctrl, ch.id)

rx.__init__(self)
self.__init_channels__(self)

def rx(self):
if not self._rx__rxbuf:
Expand Down Expand Up @@ -166,3 +170,70 @@ def calibscale(self):
def calibscale(self, calibscale):
"""Set calibration scale value."""
self._set_iio_attr(self.name, "calibscale", False, calibscale, self._ctrl)


class adaq42xx(ad4630):

""" ADAQ4224 is a 24-bit precision SAR ADC data acquisition module """

def __init__(self, uri="", device_name="adaq4224"):

context_manager.__init__(self, uri, self._device_name)

compatible_parts = ["adaq4224", "adaq4216", "adaq4220"]

if device_name not in compatible_parts:
raise Exception(
"Not a compatible device: "
+ str(device_name)
+ ". Please select from "
+ str(compatible_parts)
)
else:
self._ctrl = self._ctx.find_device(device_name)
self._rxadc = self._ctx.find_device(device_name)

self.__init_channels__(self)

class _channel(attribute):
"""ADAQ42xx differential channel."""

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

@property
def calibbias(self):
"""Get calibration bias/offset value."""
return self._get_iio_attr(self.name, "calibbias", False, self._ctrl)

@calibbias.setter
def calibbias(self, calibbias):
"""Set calibration bias/offset value."""
self._set_iio_attr(
self.name, "calibbias", False, int(calibbias), self._ctrl
)

@property
def calibscale(self):
"""Get calibration scale value."""
return self._get_iio_attr(self.name, "calibscale", False, self._ctrl)

@calibscale.setter
def calibscale(self, calibscale):
"""Set calibration scale value."""
self._set_iio_attr(self.name, "calibscale", False, calibscale, self._ctrl)

@property
def scale_available(self):
"""Provides all available scale(gain) settings for the ADAQ42xx channel"""
return self._get_iio_attr(self.channel[0].name, "scale_available", False)

@property
def scale(self):
"""ADAQ42xx 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))
3 changes: 3 additions & 0 deletions supported_parts.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
- AD4858
- AD9739A
- ADA4961
- ADAQ4216
- ADAQ4220
- ADAQ4224
- ADAQ8092
- ADAR1000
- ADF4159
Expand Down

0 comments on commit 21d39f4

Please sign in to comment.