Skip to content

Commit

Permalink
Merge branch 'analogdevicesinc:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SaikiranGudla authored Oct 23, 2023
2 parents 7c05d6d + 1ee2658 commit 84ecac9
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 158 deletions.
92 changes: 30 additions & 62 deletions adi/ad4630.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ad4630(rx, context_manager, attribute):
""" AD4630 is low power 24-bit precision SAR ADC """

_complex_data = False
_data_type = "voltage"
_data_type = np.uint32
_device_name = ""
_rx_channel_names = []

Expand Down Expand Up @@ -54,17 +54,15 @@ def __init__(self, uri="", device_name="ad4630-24"):
for ch in self._ctrl.channels:
self.output_bits.append(ch.data_format.bits)
self._rx_channel_names.append(ch.id)
if "differential" in ch.name:
_channels.append((ch.id, self._diff_channel(self._ctrl, ch.id)))
if "0" in ch.name:
self.chan0 = self._diff_channel(self._ctrl, ch.name)
if "1" in ch.name:
self.chan1 = self._diff_channel(self._ctrl, ch.name)
_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 rx(self):

if not self._rx__rxbuf:
self._rx_init_channels()
self._rx__rxbuf.refill()
Expand Down Expand Up @@ -108,45 +106,13 @@ def output_data_mode(self):

@property
def sample_rate(self):
"""Get/Set the sampling frequency."""
"""Get the sampling frequency."""
return self._get_iio_dev_attr("sampling_frequency")

@sample_rate.setter
def sample_rate(self, rate):
"""Get/Set the sampling frequency."""
if str(rate) in str(self.sample_rate_avail):
self._set_iio_dev_attr("sampling_frequency", str(rate))
else:
raise ValueError(
"Error: Sample rate not supported \nUse one of: "
+ str(self.sample_rate_avail)
)

@property
def sample_rate_avail(self):
"""Get list of all the sampling frequency available."""
return self._get_iio_dev_attr("sampling_frequency_available")

@property
def operating_mode_avail(self):
"""Get list of all the operating mode available."""
return self._get_iio_dev_attr_str("operating_mode_available")

@property
def operating_mode(self):
"""Get/Set the operating mode."""
return self._get_iio_dev_attr_str("operating_mode")

@operating_mode.setter
def operating_mode(self, mode):
"""Get/Set the operating mode."""
if mode in self.operating_mode_avail:
self._set_iio_dev_attr_str("operating_mode", mode)
else:
raise ValueError(
"Error: Operating mode not supported \nUse one of: "
+ str(self.operating_mode_avail)
)
"""Set the sampling frequency."""
self._set_iio_dev_attr("sampling_frequency", str(rate))

@property
def sample_averaging_avail(self):
Expand All @@ -155,12 +121,12 @@ def sample_averaging_avail(self):

@property
def sample_averaging(self):
"""Get/Set the sample averaging. Only available in 30bit averaged mode."""
"""Get the sample averaging. Only available in 30bit averaged mode."""
return self._get_iio_dev_attr_str("sample_averaging")

@sample_averaging.setter
def sample_averaging(self, n_sample):
"""Get/Set the sample averaging. Only available in 30bit averaged mode."""
"""Set the sample averaging. Only available in 30bit averaged mode."""
if str(self.sample_averaging) != "OFF":
if str(n_sample) in str(self.sample_averaging_avail):
self._set_iio_dev_attr("sample_averaging", str(n_sample))
Expand All @@ -172,29 +138,31 @@ def sample_averaging(self, n_sample):
else:
raise Exception("Sample Averaging only available in 30bit averaged mode.")

class _diff_channel(attribute):
class _channel(attribute):
"""AD4x30 differential channel."""

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

@property
def hw_gain(self):
"""Get/Set the hardwaregain of differential channel."""
return self._get_iio_attr(self.name, "hardwaregain", False)

@hw_gain.setter
def hw_gain(self, gain):
"""Get/Set the hardwaregain of differential channel."""
self._set_iio_attr(self.name, "hardwaregain", False, int(gain))
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 offset(self):
"""Get/Set the offset of differential channel."""
return self._get_iio_attr(self.name, "offset", False, self._ctrl)

@offset.setter
def offset(self, offset):
"""Get/Set the offset of differential channel."""
self._set_iio_attr(self.name, "offset", False, int(offset), self._ctrl)
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)
2 changes: 1 addition & 1 deletion adi/rx_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def rx_buffer_size(self, value):
self.__rx_buffer_size = value

@property
def rx_enabled_channels(self) -> List[int]:
def rx_enabled_channels(self) -> Union[List[int], List[str]]:
"""rx_enabled_channels: List of enabled channels (channel 1 is 0)
Either a list of channel numbers or channel names can be used to set
Expand Down
27 changes: 12 additions & 15 deletions examples/ad4630/ad4630_example_all_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,19 @@
import numpy as np
import sin_params as sp

device_name = "ad4030-24"
device_name = "ad4630-24"
fs = 2000000 # Sampling Frequency
N = 65536 # Length of rx buffer


def main():
""" Instantiate the device and set th parameters."""
adc = adi.ad4630(
uri="ip:169.254.92.202", device_name=device_name
) # To connect via ip address 169.254.92.202
uri="ip:192.168.10.171", device_name=device_name
) # To connect via ip address
adc.rx_buffer_size = N
adc.sample_rate = fs

"""To switch the device b/w low_power_mode and normal_operating_mode."""
adc.operating_mode = "normal_operating_mode"

"""sample_averaging is only supported by 30bit mode. and in this mode it cannot be OFF."""
if adc.output_data_mode == "30bit_avg":
adc.sample_averaging = 16
Expand All @@ -34,11 +31,11 @@ def main():
print(adc.output_data_mode)

""" Differential Channel attributes"""
adc.chan0.hw_gain = 2
adc.chan0.offset = 2
adc.chan0.calibscale = 1
adc.chan0.calibbias = 2
if device_name == "ad4630-24":
adc.chan1.hw_gain = 2
adc.chan1.offset = 2
adc.chan1.calibscale = 1
adc.chan1.calibbias = 2

data = adc.rx() # Receive the data
adc.rx_destroy_buffer() # Destroy the remaining data in buffer
Expand Down Expand Up @@ -110,11 +107,11 @@ def analysis(bits, op_data):
print("Binwidth = ", bin_width)
print("SNR (dB) = ", snr)
print("SNR of Adjacent chan (dB) =", snr_adj)
print("thd = " + str(thd) + " calculated thd = " + thd_calc)
print("sfdr = " + str(sfdr) + " adjacent chan sfdr = " + sfdr_adj)
print("ENOB = " + str(enob) + " calculated ENOB = " + enob_calc)
print("sinad = " + str(sinad) + " calculated sinad = " + sinad_calc)
print("Max code = " + str(max_code) + "Min code = " + str(min_code))
print("thd = " + str(thd) + " calculated thd = " + str(thd_calc))
print("sfdr = " + str(sfdr) + " adjacent chan sfdr = " + str(sfdr_adj))
print("ENOB = " + str(enob) + " calculated ENOB = " + str(enob_calc))
print("sinad = " + str(sinad) + " calculated sinad = " + str(sinad_calc))
print("Max code = " + str(max_code) + " Min code = " + str(min_code))
print("Lent of each captured array =", len(op_data))


Expand Down
11 changes: 9 additions & 2 deletions examples/ad4630/ad4630_example_simple_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
# SPDX short identifier: ADIBSD


import sys

import adi
import matplotlib.pyplot as plt
import numpy as np

device_name = "ad4630-23"
# Optionally pass URI as command line argument,
# else use default context manager search
my_uri = sys.argv[1] if len(sys.argv) >= 2 else None
print("uri: " + str(my_uri))

device_name = "ad4630-24"

adc = ad4630(uri="ip:192.168.0.130", device_name=device_name)
adc = adi.ad4630(uri=my_uri, device_name=device_name)
adc.rx_buffer_size = 500
adc.sample_rate = 2000000

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"hpAdcCorner": 20000000,
"lpAdcCorner": 0,
"adcClk_kHz": 2211840,
"rxCorner3dB_kHz": 10000,
"rxCorner3dBLp_kHz": 10000,
"rxCorner3dB_kHz": 40000,
"rxCorner3dBLp_kHz": 40000,
"tiaPower": 2,
"tiaPowerLp": 2,
"channelType": 1,
Expand Down Expand Up @@ -131,7 +131,8 @@
"numberLnaGainSteps": 0,
"lnaGainSteps_mdB": [ 0, 0, 0, 0 ],
"lnaDigitalGainDelay": 0,
"minGainIndex": 0
"minGainIndex": 0,
"lnaType": 0
},
"rxSsiConfig": {
"ssiType": 2,
Expand Down Expand Up @@ -165,8 +166,8 @@
"hpAdcCorner": 20000000,
"lpAdcCorner": 0,
"adcClk_kHz": 2211840,
"rxCorner3dB_kHz": 10000,
"rxCorner3dBLp_kHz": 10000,
"rxCorner3dB_kHz": 40000,
"rxCorner3dBLp_kHz": 40000,
"tiaPower": 2,
"tiaPowerLp": 2,
"channelType": 2,
Expand Down Expand Up @@ -248,7 +249,8 @@
"numberLnaGainSteps": 0,
"lnaGainSteps_mdB": [ 0, 0, 0, 0 ],
"lnaDigitalGainDelay": 0,
"minGainIndex": 0
"minGainIndex": 0,
"lnaType": 0
},
"rxSsiConfig": {
"ssiType": 2,
Expand Down Expand Up @@ -365,7 +367,8 @@
"numberLnaGainSteps": 0,
"lnaGainSteps_mdB": [ 0, 0, 0, 0 ],
"lnaDigitalGainDelay": 0,
"minGainIndex": 0
"minGainIndex": 0,
"lnaType": 0
},
"rxSsiConfig": {
"ssiType": 0,
Expand Down Expand Up @@ -482,7 +485,8 @@
"numberLnaGainSteps": 0,
"lnaGainSteps_mdB": [ 0, 0, 0, 0 ],
"lnaDigitalGainDelay": 0,
"minGainIndex": 0
"minGainIndex": 0,
"lnaType": 0
},
"rxSsiConfig": {
"ssiType": 0,
Expand Down Expand Up @@ -599,7 +603,8 @@
"numberLnaGainSteps": 0,
"lnaGainSteps_mdB": [ 0, 0, 0, 0 ],
"lnaDigitalGainDelay": 0,
"minGainIndex": 0
"minGainIndex": 0,
"lnaType": 0
},
"rxSsiConfig": {
"ssiType": 2,
Expand Down Expand Up @@ -716,7 +721,8 @@
"numberLnaGainSteps": 0,
"lnaGainSteps_mdB": [ 0, 0, 0, 0 ],
"lnaDigitalGainDelay": 0,
"minGainIndex": 0
"minGainIndex": 0,
"lnaType": 0
},
"rxSsiConfig": {
"ssiType": 2,
Expand Down Expand Up @@ -833,7 +839,8 @@
"numberLnaGainSteps": 0,
"lnaGainSteps_mdB": [ 0, 0, 0, 0 ],
"lnaDigitalGainDelay": 0,
"minGainIndex": 0
"minGainIndex": 0,
"lnaType": 0
},
"rxSsiConfig": {
"ssiType": 0,
Expand Down Expand Up @@ -950,7 +957,8 @@
"numberLnaGainSteps": 0,
"lnaGainSteps_mdB": [ 0, 0, 0, 0 ],
"lnaDigitalGainDelay": 0,
"minGainIndex": 0
"minGainIndex": 0,
"lnaType": 0
},
"rxSsiConfig": {
"ssiType": 0,
Expand Down Expand Up @@ -1254,17 +1262,17 @@
} ],
"pfirRxMagLowTiaLowSRHp": [ {
"numCoeff": 21,
"coefficients": [ -346, 1329, -1178, -1281, 1308, 2727, -1341, -5852, -1018, 12236, 19599, 12236, -1018, -5852, -1341, 2727, 1308, -1281, -1178, 1329, -346 ]
"coefficients": [ -12, 83, -293, 734, -1489, 2594, -3965, 5403, -6516, 5868, 27957, 5868, -6516, 5403, -3965, 2594, -1489, 734, -293, 83, -12 ]
}, {
"numCoeff": 21,
"coefficients": [ -346, 1329, -1178, -1281, 1308, 2727, -1341, -5852, -1018, 12236, 19599, 12236, -1018, -5852, -1341, 2727, 1308, -1281, -1178, 1329, -346 ]
"coefficients": [ -12, 83, -293, 734, -1489, 2594, -3965, 5403, -6516, 5868, 27957, 5868, -6516, 5403, -3965, 2594, -1489, 734, -293, 83, -12 ]
} ],
"pfirRxMagLowTiaHighSRHp": [ {
"numCoeff": 21,
"coefficients": [ -2474, 892, 6049, 4321, -7599, -15881, -6074, 13307, 18926, 6338, -2843, 6338, 18926, 13307, -6074, -15881, -7599, 4321, 6049, 892, -2474 ]
"coefficients": [ -62, 194, 80, -829, 201, 1857, -179, -4602, -1259, 11431, 19102, 11431, -1259, -4602, -179, 1857, 201, -829, 80, 194, -62 ]
}, {
"numCoeff": 21,
"coefficients": [ -2474, 892, 6049, 4321, -7599, -15881, -6074, 13307, 18926, 6338, -2843, 6338, 18926, 13307, -6074, -15881, -7599, 4321, 6049, 892, -2474 ]
"coefficients": [ -62, 194, 80, -829, 201, 1857, -179, -4602, -1259, 11431, 19102, 11431, -1259, -4602, -179, 1857, 201, -829, 80, 194, -62 ]
} ],
"pfirRxMagHighTiaHighSRHp": [ {
"numCoeff": 21,
Expand All @@ -1275,17 +1283,17 @@
} ],
"pfirRxMagLowTiaLowSRLp": [ {
"numCoeff": 21,
"coefficients": [ -346, 1329, -1178, -1281, 1308, 2727, -1341, -5851, -1018, 12236, 19599, 12236, -1018, -5851, -1341, 2727, 1308, -1281, -1178, 1329, -346 ]
"coefficients": [ -12, 83, -293, 733, -1488, 2593, -3963, 5401, -6514, 5870, 27953, 5870, -6514, 5401, -3963, 2593, -1488, 733, -293, 83, -12 ]
}, {
"numCoeff": 21,
"coefficients": [ -346, 1329, -1178, -1281, 1308, 2727, -1341, -5851, -1018, 12236, 19599, 12236, -1018, -5851, -1341, 2727, 1308, -1281, -1178, 1329, -346 ]
"coefficients": [ -12, 83, -293, 733, -1488, 2593, -3963, 5401, -6514, 5870, 27953, 5870, -6514, 5401, -3963, 2593, -1488, 733, -293, 83, -12 ]
} ],
"pfirRxMagLowTiaHighSRLp": [ {
"numCoeff": 21,
"coefficients": [ -2473, 892, 6048, 4321, -7598, -15879, -6072, 13306, 18924, 6338, -2843, 6338, 18924, 13306, -6072, -15879, -7598, 4321, 6048, 892, -2473 ]
"coefficients": [ -62, 194, 80, -828, 201, 1855, -180, -4597, -1254, 11428, 19093, 11428, -1254, -4597, -180, 1855, 201, -828, 80, 194, -62 ]
}, {
"numCoeff": 21,
"coefficients": [ -2473, 892, 6048, 4321, -7598, -15879, -6072, 13306, 18924, 6338, -2843, 6338, 18924, 13306, -6072, -15879, -7598, 4321, 6048, 892, -2473 ]
"coefficients": [ -62, 194, 80, -828, 201, 1855, -180, -4597, -1254, 11428, 19093, 11428, -1254, -4597, -180, 1855, 201, -828, 80, 194, -62 ]
} ],
"pfirRxMagHighTiaHighSRLp": [ {
"numCoeff": 21,
Expand Down
Loading

0 comments on commit 84ecac9

Please sign in to comment.