-
Notifications
You must be signed in to change notification settings - Fork 15
DRAFT: add AD7173 family #42
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| classdef Rx < adi.common.Rx & adi.common.RxTx ... | ||
| & adi.AD7193.Base | ||
| % AD4111 Precision ADC Class | ||
| % | ||
| % adi.AD4111.Rx Receives data from the AD4111 ADC | ||
| % The adi.AD4111.Rx System object is a signal source that can receive | ||
| % data from the AD4111. | ||
| % | ||
| % `rx = adi.AD4111.Rx;` | ||
| % `rx = adi.AD4111.Rx('uri','ip:192.168.2.1');` | ||
| % | ||
| % `AD4111 Datasheet <https://www.analog.com/media/en/technical-documentation/data-sheets/ad4111.pdf>`_ | ||
|
|
||
|
|
||
| properties (Nontunable, Hidden) | ||
| channel_names = {'voltage0','voltage1','voltage2','voltage3',... | ||
| 'voltage4','voltage5','voltage6','voltage7','current0', ... | ||
| 'current1','current2','current3','differential0', ... | ||
| 'differential1','differential2','differential3', 'temp'}; | ||
| end | ||
|
|
||
| methods | ||
| %% Constructor | ||
| function obj = Rx(varargin) | ||
| obj = obj@adi.AD7193.Base('ad4111','ad4111',varargin{:}); | ||
| end | ||
| end | ||
|
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| classdef Base < adi.common.Rx & adi.common.RxTx & ... | ||
| matlabshared.libiio.base & adi.common.Attribute & ... | ||
| adi.common.RegisterReadWrite & adi.common.Channel | ||
| % AD7193 Precision ADC Class | ||
| % AD4111 is a 12 channel ADC with temperature/voltage/differential/current inputs | ||
|
|
||
| properties (Nontunable) | ||
| % SampleRate Sample Rate | ||
| % Baseband sampling rate in Hz, specified as a scalar | ||
| % in samples per second. | ||
| SampleRate = '19200' | ||
|
|
||
| % SamplesPerFrame Samples Per Frame | ||
| % Number of samples per frame, specified as an even positive | ||
| % integer. | ||
| SamplesPerFrame = 400 | ||
|
granquet marked this conversation as resolved.
|
||
| end | ||
|
|
||
| % isOutput | ||
| properties (Hidden, Nontunable, Access = protected) | ||
| isOutput = false | ||
| end | ||
|
|
||
| properties (Nontunable, Hidden, Constant) | ||
| Type = 'Rx' | ||
| end | ||
|
|
||
| properties (Nontunable, Hidden) | ||
| Timeout = Inf | ||
| kernelBuffersCount = 1 | ||
| dataTypeStr = 'int32' | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is int32 the best type available? most devices declare realbits to 24 and ad4113 is 16 bits
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For 16 bit resolution & less than that, dataTypeStr should be set to int16. For values higher than 16 (eg. 18/24 etc), the dataTypeStr has to be set to int32, which is the next value of powers of two. |
||
| phyDevName | ||
| devName | ||
| end | ||
|
|
||
| properties (Hidden, Constant) | ||
| ComplexData = false | ||
| end | ||
|
|
||
| methods | ||
| %% Constructor | ||
| function obj = Base(phydev,dev,varargin) | ||
| coder.allowpcode('plain'); | ||
| % Initialize the Rx object | ||
| obj = obj@matlabshared.libiio.base(varargin{:}); | ||
| obj.enableExplicitPolling = false; | ||
| obj.EnabledChannels = 1; | ||
| obj.BufferTypeConversionEnable = true; | ||
| obj.phyDevName = phydev; | ||
| obj.devName = dev; | ||
| obj.uri = 'ip:analog.local'; | ||
| end | ||
|
|
||
| function flush(obj) | ||
| % Flush the buffer | ||
| flushBuffers(obj); | ||
| end | ||
|
|
||
| function delete(obj) | ||
| % Destructor | ||
| delete@adi.common.RxTx(obj); | ||
| end | ||
|
|
||
| function set.SampleRate(obj, value) | ||
| % Set device sampling rate | ||
| obj.SampleRate = value; | ||
| if obj.ConnectedToDevice | ||
| obj.setDeviceAttributeRAW('sampling_frequency', value); | ||
| end | ||
| end | ||
|
|
||
| %% Check Voltage Scale | ||
| function rValue = get.VoltageScale(obj) | ||
| if obj.ConnectedToDevice | ||
| rValue = obj.getAttributeDouble('voltage0', 'scale', obj.isOutput); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the default of 'voltage0' might not exists depending on how the dtb is written, how to account for that? I see
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you have access to the hardware, the fastest way to get the channels names & attributes is running iio_info.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have access to the hardware, but if no voltage channels are declared in dts, there will be no voltage channels?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think they are named "voltage0" and so on in the dts. I think they are reffered to as "channels". I'm not very familiar with Linux, but if I'm not wrong, those namings are from iio. |
||
| else | ||
| rValue = NaN; | ||
| end | ||
| end | ||
|
|
||
| %% Check Voltage Offset | ||
| function rValue = get.VoltageOffset(obj) | ||
| if obj.ConnectedToDevice | ||
| rValue = obj.getAttributeDouble('voltage0', 'offset', obj.isOutput); | ||
| else | ||
| rValue = NaN; | ||
| end | ||
| end | ||
|
|
||
| %% Check Current Scale | ||
| function rValue = get.CurrentScale(obj) | ||
| if obj.ConnectedToDevice | ||
| rValue = obj.getAttributeDouble('current0', 'scale', obj.isOutput); | ||
| else | ||
| rValue = NaN; | ||
| end | ||
| end | ||
|
|
||
| %% Check Current Offset | ||
| function rValue = get.CurrentOffset(obj) | ||
| if obj.ConnectedToDevice | ||
| rValue = obj.getAttributeDouble('current0', 'offset', obj.isOutput); | ||
| else | ||
| rValue = NaN; | ||
| end | ||
| end | ||
|
|
||
| %% Check Temperature Scale | ||
| function rValue = get.TemperatureScale(obj) | ||
| if obj.ConnectedToDevice | ||
| rValue = obj.getAttributeDouble('temp', 'scale', obj.isOutput); | ||
| else | ||
| rValue = NaN; | ||
| end | ||
| end | ||
|
|
||
| %% Check Temperature Offset | ||
| function rValue = get.TemperatureOffset(obj) | ||
| if obj.ConnectedToDevice | ||
| rValue = obj.getAttributeDouble('temp', 'offset', obj.isOutput); | ||
| else | ||
| rValue = NaN; | ||
| end | ||
| end | ||
| end | ||
|
|
||
| %% API Functions | ||
| methods (Hidden, Access = protected) | ||
| function setupInit(obj) | ||
| % Write all attributes to device once connected through set | ||
| % methods | ||
| % Do writes directly to hardware without using set methods. | ||
| % This is required since Simulink support doesn't support | ||
| % modification to nontunable variables at SetupImpl | ||
| obj.setDeviceAttributeRAW('sampling_frequency',num2str(obj.SampleRate)); | ||
| end | ||
| end | ||
|
|
||
| %% External Dependency Methods | ||
| methods (Hidden, Static) | ||
| function tf = isSupportedContext(bldCfg) | ||
| tf = matlabshared.libiio.ExternalDependency.isSupportedContext(bldCfg); | ||
| end | ||
|
|
||
| function updateBuildInfo(buildInfo, bldCfg) | ||
| % Call the matlabshared.libiio.method first | ||
| matlabshared.libiio.ExternalDependency.updateBuildInfo(buildInfo, bldCfg); | ||
| end | ||
|
granquet marked this conversation as resolved.
|
||
|
|
||
| function bName = getDescriptiveName(~) | ||
| bName = 'AD7193 ADC'; | ||
| end | ||
| end | ||
|
|
||
| end | ||
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.
the channels will not be named
differentialXbut something likein_voltage3-voltage5_rawI'm unsure how to translate this here? other devices in the toolbox seems to use
differentialX, not sure how this works?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.
Right, as I mentioned above, if you can run iio_info it should ease the naming process. If you're using only the Linux drivers, you can take an example from previous similar scenarios.
In this PR there are both differential and non-differential parts.
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 but, the number and naming of the differential channels depends on the device tree... and this is hardcoded... so should I hardcode all possible values in this PR!?
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, if the values are hardcoded I think we should have separate files for each devicetree/ channels combinations.