Skip to content

Commit

Permalink
Merge pull request #499 from analogdevicesinc/tfcollins/ad7124-fixes
Browse files Browse the repository at this point in the history
AD7124 fixes
  • Loading branch information
tfcollins authored Nov 29, 2023
2 parents 6d0f263 + db5933d commit 5670c59
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
28 changes: 6 additions & 22 deletions adi/ad7124.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,16 @@ def __init__(self, uri="", device_index=0):
else:
index += 1

# dynamically get channels and sorting them after the index of the first voltage channel
self._ctrl.channels.sort(key=lambda x: int(x.id[7 : x.id.find("-")]))
self._rx_channel_names = [chan.name for chan in self._ctrl.channels]
if "-" in self._rx_channel_names[0]:
self._rx_channel_names.sort(key=lambda x: int(x[7:].split("-")[0]))
else:
self._rx_channel_names.sort(key=lambda x: int(x[7:]))

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

def rx(self):
sig = super().rx()

if (
self._rx_unbuffered_data
or self._complex_data
or self.rx_output_type == "raw"
):
return sig
else:
mv_sig = []

for signal in sig:
mv_sig.append(signal / 1000)

return mv_sig

@property
def sample_rate(self):
"""Sets sampling frequency of the AD7124"""
Expand Down
1 change: 1 addition & 0 deletions test/emu/devices/ad7124-8.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="serial" description="no-OS 0.1" ><context-attribute name="hw_carrier" value="SDP_K1" /><context-attribute name="hw_mezzanine" value="EVAL-AD7124-8ASDZ" /><context-attribute name="hw_name" value="EVAL-AD7124-8ASDZ" /><context-attribute name="uri" value="serial:/dev/ttyS0,230400,8n1n" /><context-attribute name="serial,port" value="/dev/ttyS0" /><context-attribute name="serial,description" value="ttyS0" /><device id="iio:device0" name="ad7124-8" ><channel id="voltage0" name="voltage0" type="input" ><scan-element index="0" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage0_raw" value="12888383" /><attribute name="scale" filename="in_voltage0_scale" value="0.000298" /><attribute name="offset" filename="in_voltage0_offset" value="-8388608" /></channel><channel id="voltage1" name="voltage1" type="input" ><scan-element index="1" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage1_raw" value="13424123" /><attribute name="scale" filename="in_voltage1_scale" value="0.000298" /><attribute name="offset" filename="in_voltage1_offset" value="-8388608" /></channel><channel id="voltage2" name="voltage2" type="input" ><scan-element index="2" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage2_raw" value="11772319" /><attribute name="scale" filename="in_voltage2_scale" value="0.000298" /><attribute name="offset" filename="in_voltage2_offset" value="-8388608" /></channel><channel id="voltage3" name="voltage3" type="input" ><scan-element index="3" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage3_raw" value="10253543" /><attribute name="scale" filename="in_voltage3_scale" value="0.000298" /><attribute name="offset" filename="in_voltage3_offset" value="-8388608" /></channel><channel id="voltage4" name="voltage4" type="input" ><scan-element index="4" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage4_raw" value="10658046" /><attribute name="scale" filename="in_voltage4_scale" value="0.000298" /><attribute name="offset" filename="in_voltage4_offset" value="-8388608" /></channel><channel id="voltage5" name="voltage5" type="input" ><scan-element index="5" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage5_raw" value="12582563" /><attribute name="scale" filename="in_voltage5_scale" value="0.000298" /><attribute name="offset" filename="in_voltage5_offset" value="-8388608" /></channel><channel id="voltage6" name="voltage6" type="input" ><scan-element index="6" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage6_raw" value="13529249" /><attribute name="scale" filename="in_voltage6_scale" value="0.000298" /><attribute name="offset" filename="in_voltage6_offset" value="-8388608" /></channel><channel id="voltage7" name="voltage7" type="input" ><scan-element index="7" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage7_raw" value="12473086" /><attribute name="scale" filename="in_voltage7_scale" value="0.000298" /><attribute name="offset" filename="in_voltage7_offset" value="-8388608" /></channel><channel id="voltage8" name="voltage8" type="input" ><scan-element index="8" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage8_raw" value="10601046" /><attribute name="scale" filename="in_voltage8_scale" value="0.000298" /><attribute name="offset" filename="in_voltage8_offset" value="-8388608" /></channel><channel id="voltage9" name="voltage9" type="input" ><scan-element index="9" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage9_raw" value="10309732" /><attribute name="scale" filename="in_voltage9_scale" value="0.000298" /><attribute name="offset" filename="in_voltage9_offset" value="-8388608" /></channel><channel id="voltage10" name="voltage10" type="input" ><scan-element index="10" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage10_raw" value="11928386" /><attribute name="scale" filename="in_voltage10_scale" value="0.000298" /><attribute name="offset" filename="in_voltage10_offset" value="-8388608" /></channel><channel id="voltage11" name="voltage11" type="input" ><scan-element index="11" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage11_raw" value="13451002" /><attribute name="scale" filename="in_voltage11_scale" value="0.000298" /><attribute name="offset" filename="in_voltage11_offset" value="-8388608" /></channel><channel id="voltage12" name="voltage12" type="input" ><scan-element index="12" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage12_raw" value="12922814" /><attribute name="scale" filename="in_voltage12_scale" value="0.000298" /><attribute name="offset" filename="in_voltage12_offset" value="-8388608" /></channel><channel id="voltage13" name="voltage13" type="input" ><scan-element index="13" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage13_raw" value="10931057" /><attribute name="scale" filename="in_voltage13_scale" value="0.000298" /><attribute name="offset" filename="in_voltage13_offset" value="-8388608" /></channel><channel id="voltage14" name="voltage14" type="input" ><scan-element index="14" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage14_raw" value="10175125" /><attribute name="scale" filename="in_voltage14_scale" value="0.000298" /><attribute name="offset" filename="in_voltage14_offset" value="-8388608" /></channel><channel id="voltage15" name="voltage15" type="input" ><scan-element index="15" format="le:S32/32&gt;&gt;0" /><attribute name="raw" filename="in_voltage15_raw" value="11752352" /><attribute name="scale" filename="in_voltage15_scale" value="0.000298" /><attribute name="offset" filename="in_voltage15_offset" value="-8388608" /></channel><attribute name="sampling_frequency" value="2400" /><debug-attribute name="direct_reg_access" value="143" /></device></context>
11 changes: 11 additions & 0 deletions test/emu/hardware_map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,14 @@ adis16475:
- iio:device0
- pyadi_iio_class_support:
- adis16475

ad7124-8:
- ad7124
- pyadi_iio_class_support:
- ad7124
- emulate:
- filename: ad7124-8.xml
- data_devices:
- iio:device0
- pyadi_iio_class_support:
- ad7124
14 changes: 14 additions & 0 deletions test/test_ad7124_8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import adi
import pytest

hardware = "ad7124-8"
classname = "adi.ad7124"


#########################################
@pytest.mark.iio_hardware(hardware)
def test_ad7124_8_channels(iio_uri):
dev = adi.ad7124(uri=iio_uri)

for chan_i in range(16):
assert dev.rx_channel_names[chan_i] == f"voltage{str(chan_i)}"

0 comments on commit 5670c59

Please sign in to comment.