-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pyadi support for ADAQ4001 and ADAQ4003 #571
base: main
Are you sure you want to change the base?
Conversation
aa72d7e
to
fab6245
Compare
@property | ||
def scale_available(self): | ||
"""Provides all available scale(gain) settings for the ADC channel""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@machschmitt I believe these are all fixed-scale devices. Accessing the scale_available property throws a KeyError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well yes, at least what is in ADI Linux right now.
Though, the driver will provide a scale_available attribute in the future for configuring span compression.
Some explanation taken from commit log:
AD4000 series of devices have a span compression feature that allows
reducing the ADC input range while keeping the same range of raw output
codes, thus providing a slight increase in measurement precision.
The span compression selection (enable/disable) is done by writing to
the scale attribute. The list of valid scale values is listed by the
scale_available attribute.
@tfcollins, can we have scale_available
attribute (even if it is not working right now) or would you prefer to only introduce it when the changes get to ADI Linux?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@machschmitt noted - although has the decision been made whether the compression will be changeable at run time, or set in the device tree? Typically the decision would be made as the analog front end circuit is being designed, then "set and forget" in software / device tree.
But if it will be run-time adjustable, this makes perfect sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mthoren-adi, I was developing this as a runtime feature but it could definitely be set in device tree as you said so that's indeed a good question. Who can I ask about this configuration decision? Part application engineer?
adi/ad4020.py
Outdated
def __call__(self, mV=None): | ||
"""Convenience function, set / get voltages in SI units (millivolts)""" | ||
if mV is not None: | ||
self.raw = int(float(mV) / float(self.scale)) | ||
return self.raw * self.scale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@machschmitt raw is a read-only attribute, attempting to set throws an error. (the mV=None argument is not needed.) Looks like this was carried over from a DAC device.
Also the formula should include the offset:
((self.raw + self.offset) * self.scale)
so an offset property should also be added. (The device does have an offset attribute.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's true. I don't even recall where I got that from but am fixing it now.
The driver doesn't provide offset attribute right now but it may in the future for scenarios where differential ADCs get set in single-ended to differential configuration.
@pytest.mark.parametrize("classname", [(classname)]) | ||
@pytest.mark.parametrize( | ||
"attr, avail_attr, tol, repeats, sub_channel", | ||
[("scale", "scale_available", 0, 1, "voltage0-voltage1",),], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted above, there is no scale_available. Also this is a single-channel device with a single differential input, voltage0. The voltage0-voltage-1 nomenclature is typical of multichannel devices that can be arbitrarily configured.
Note that I am looking at the ADAQ4003 on Cora, but I see zynq-zed-adv7511-adxxxx noted below. The ADAQ4003 attributes, channel, etc.
@machschmitt the only other peculiarity I notice is that the sampling_frequency can only be set if there's no buffer created. That is, initially I can set the sample rate, but after calling rx(), attempting to set the sample rate throws: |
The "nice" way to do this is with a decorator that manages it for you like so: https://github.com/analogdevicesinc/pyadi-iio/blob/main/adi/cn0540.py#L81 |
fab6245
to
3814809
Compare
Updated according to suggestions. Change log v1 -> v2:
|
aef7b26
to
3814809
Compare
I reverted the patch adding the reset_buffer convenience decorator because it was failing pytest and I am having trouble trying to run pytests with iio-emu locally. It looks like pytest is not starting iio-emu on my setup for it was failing with The launch command was
I updated and reinstalled libtinyiiod, iio-emu, and pyadi-iio, but the issue was not solved so I reverted the offending patch. |
test/test_adaq4003.py
Outdated
# if not hasattr(sdr, attr): | ||
# raise AttributeError(attr + " not defined in " + classname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy paste error on the last 2 lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy paste error on the last 2 lines?
Yes. Removed those in newer version.
3814809
to
3751591
Compare
AD4003/AD4007/AD4011, AD4020/AD4021/AD4022, and ADAQ4001/ADAQ4003 belong to a series of differential SAR ADC devices which are supported by the same Linux kernel driver. Add python class for ADAQ4001 and ADAQ4003. Signed-off-by: Marcelo Schmitt <[email protected]>
Add adaq4003 python class to the list of classes provided by ad4020 module. Signed-off-by: Marcelo Schmitt <[email protected]>
AD4000 series of devices have a span compression feature that allows reducing the ADC input range while keeping the same range of raw output codes, thus providing a slightly increase in measurement precision. The span compression selection (enable/disable) is done by writing to the scale attribute. The list of valid scale values is listed by the scale_available attribute. Signed-off-by: Marcelo Schmitt <[email protected]>
Add iio-emu xml for emulating ADAQ4003 devices. Add hardware map entry for ADAQ4003. Signed-off-by: Marcelo Schmitt <[email protected]>
Add tests for adaq4003 python class. Tests included: - Buffered capture test with DMA - Sampling frequency attribute test - Scale attribute test Signed-off-by: Marcelo Schmitt <[email protected]>
Signed-off-by: Marcelo Schmitt <[email protected]>
Use python argparse [1] to handle command-line arguments thus making the example more flexible with respect to its input arguments. This also extends the example to work with other ADCs that belong to the AD4000 series by enabling a device argument and using it to instantiate the correct ADC object. [1]: https://docs.python.org/3/library/argparse.html Signed-off-by: Marcelo Schmitt <[email protected]>
The scale may vary according to ADC characteristics such as precision bits, span compression, gain, etc. and also with setup properties such as voltage reference. Use driver provided scale to convert back to milli-voltage units which is the standard IIO unit for voltage type channels. Signed-off-by: Marcelo Schmitt <[email protected]>
The voltage spectrum plot quickly closed with almost no time the user to see it. Keep the plot visible for the user to analyse it. Signed-off-by: Marcelo Schmitt <[email protected]>
3751591
to
e4155e1
Compare
Hi @tfcollins, Only changes to this PR were rebasing to main branch and removing leftover comments. Unrelated to this PR, I re-run pytest and got |
This is what I get when I target those updated tests:
That expected?
iio_get_backends_count is in the compat layer of v1 so it may not exist in your build. My guess is you are using the old v0.25 python bindings with v1. Be careful not to mix these. |
I get this:
It looks like pyadi can't connect to the IIO context.
In the same venv I use to run pyadi tests and examples I have the following:
I did try to update libiio for my venv, by re-installing libiio v1 locally and running the python bindings setup script.
Don't want to drag anyone into debugging specific setups so I'm happy with any advice on how to (re)set pyadi venv installation to any known working configuration. |
O sorry forgot to mention. iio-emu does not support libiio v1 so all the tests will fail ish. |
Description
This PR adds pyadi support for ADAQ4001 and ADAQ4003.
AD4003/AD4007/AD4011, AD4020/AD4021/AD4022, and ADAQ4001/ADAQ4003 belong
to a series of differential SAR ADC devices which are supported by the
same Linux kernel driver.
This PR:
Related JIRA task: https://jira.analog.com/browse/COSGTM-277
Type of change
How has this been tested?
Test Configuration:
Documentation
The new python class was added to the list of documented classes provided by the ad4020 python module.
Checklist: