Skip to content
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

adi: Refactor AD4170 and add AD4190 support #48

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions +adi/+AD4170/Base.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
classdef Base < adi.common.Rx & adi.common.RxTx & ...
matlabshared.libiio.base & adi.common.Attribute & ...
adi.common.RegisterReadWrite & adi.common.Channel
% AD4170/AD4190 Precision ADC Class
% AD4190 is 8 channel ADC
% AD4170 is a 8 channel ADC with additional filter configurations and other added features

properties (Nontunable)
% Fs for configuring the sampling rate of the device.
% It supports a numeric value. Please refer to the DS
% for more details on configuring FS.
% Fs = 1 corresponds to 500ksps with the sinc5 filter
Fs = 1

% AdcMode ADC Mode
% ADC Mode for data capture, represented as a string.
% It supports the following: 'Continuous_Conversion',
% 'Continuous_Conversion_FIR', 'Continuous_Conversion_IIR',
% 'Standby', 'Power_Down', 'Idle'
AdcMode = 'Continuous_Conversion'

% SamplesPerFrame Samples Per Frame
% Number of samples per frame, specified as an even positive
% integer.
SamplesPerFrame = 400
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'
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 = [email protected](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
[email protected](obj);
end

function set.AdcMode(obj, value)
% Set device ADC Mode
obj.AdcMode = value;
if obj.ConnectedToDevice
obj.setDeviceAttributeRAW('adc_mode', value);
end
end

function set.Fs(obj, value)
% Set device Fs
obj.Fs = value;
if obj.ConnectedToDevice
for ch=1:length(obj.channel_names)
obj.setAttributeRAW(obj.channel_names{ch}, 'fs', value, false, obj.iioDev);
end
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('adc_mode',num2str(obj.AdcMode));
for ch=1:length(obj.channel_names)
obj.setAttributeRAW(obj.channel_names{ch}, 'fs', num2str(obj.Fs), false, obj.iioDev, false);
end
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

function bName = getDescriptiveName(~)
bName = 'AD4170 ADC';
end
end

end
112 changes: 9 additions & 103 deletions +adi/+AD4170/Rx.m
Original file line number Diff line number Diff line change
@@ -1,120 +1,26 @@
classdef Rx < adi.common.Rx & matlabshared.libiio.base & adi.common.Attribute
classdef Rx < adi.common.Rx & adi.common.RxTx ...
& adi.AD4170.Base
% AD4170 Precision ADC Class
%
% adi.AD4170.Rx Receives data from the AD4170 ADC
% The adi.AD4170.Rx System object is a signal source that can receive
% data from the AD4170.
%
% `rx = adi.AD4170.Rx;`
% `rx = adi.AD4170.Rx('serial:COM18,230400');`
% `rx = adi.AD4170.Rx('uri','ip:192.168.2.1');`
%
% `AD4170 Datasheet <https://www.analog.com/media/en/technical-documentation/data-sheets/ad4170.pdf>`_

properties (Nontunable)
% SampleRate Sample Rate
% Baseband sampling rate in Hz, specified as a scalar
% in samples per second.
SampleRate = '32500'

% SamplesPerFrame Samples Per Frame
% Number of samples per frame, specified as an even positive
% integer.
SamplesPerFrame = 1024

%AdcMode ADC Mode
% ADC Mode for data capture, represented as a string.
% It supports the following: 'Continuous_Conversion',
% 'Continuous_Conversion_FIR', 'Continuous_Conversion_IIR',
% 'Standby', 'Power_Down', 'Idle'
AdcMode = 'Continuous_Conversion'

%Fs Fs
% Fs for configuring the sampling rate of the device.
% It supports a numeric value. Please refer to the DS
% for more details on configuring FS
Fs = 20

end

% Channel names
properties (Nontunable, Hidden, Constant)
channel_names = { ...
'voltage0', 'voltage1', 'voltage2', 'voltage3'}
end

% isOutput
properties (Hidden, Nontunable, Access = protected)
isOutput = false
end
% `AD4170 Datasheet <https://www.analog.com/media/en/technical-documentation/data-sheets/ad4170-4.pdf>`_

properties (Nontunable, Hidden)
Timeout = Inf
kernelBuffersCount = 1
dataTypeStr = 'int32'
phyDevName = 'ad4170'
devName = 'ad4170'
end

properties (Nontunable, Hidden, Constant)
Type = 'Rx'
end

properties (Hidden, Constant)
ComplexData = false
channel_names = {'voltage0','voltage1','voltage2'...
'voltage3'};
end

methods

%% Constructor
function obj = Rx(varargin)
% Initialize the Rx object
obj = [email protected](varargin{:});
obj.enableExplicitPolling = false;
obj.EnabledChannels = 1;
obj.BufferTypeConversionEnable = true;
obj.uri = 'serial:COM18,230400';
end

function flush(obj)
% Flush the buffer
flushBuffers(obj);
end

function set.AdcMode(obj, value)
% Set device ADC Mode
obj.AdcMode = value;
if obj.ConnectedToDevice
obj.setDeviceAttributeRAW('adc_mode', value);
end
end

function set.Fs(obj, value)
% Set device Fs
obj.Fs = value;
if obj.ConnectedToDevice
obj.setAttributeRAW('voltage0', 'fs', value, false, obj.iioDev);
obj.setAttributeRAW('voltage1', 'fs', value, false, obj.iioDev);
obj.setAttributeRAW('voltage2', 'fs', value, false, obj.iioDev);
obj.setAttributeRAW('voltage3', 'fs', value, false, obj.iioDev);
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('adc_mode',num2str(obj.AdcMode));
obj.setAttributeRAW('voltage0', 'fs', num2str(obj.Fs), false, obj.iioDev, false);
obj.setAttributeRAW('voltage1', 'fs', num2str(obj.Fs), false, obj.iioDev, false);
obj.setAttributeRAW('voltage2', 'fs', num2str(obj.Fs), false, obj.iioDev, false);
obj.setAttributeRAW('voltage3', 'fs', num2str(obj.Fs), false, obj.iioDev, false);
obj = [email protected]('ad4170','ad4170',varargin{:});
end
end
end

end
26 changes: 26 additions & 0 deletions +adi/+AD4190/Rx.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
classdef Rx < adi.common.Rx & adi.common.RxTx ...
& adi.AD4170.Base
% AD4190 Precision ADC Class
%
% adi.AD4190.Rx Receives data from the AD4190 ADC
% The adi.AD4190.Rx System object is a signal source that can receive
% data from the AD4190.
%
% `rx = adi.AD4190.Rx;`
% `rx = adi.AD4190.Rx('uri','ip:192.168.2.1');`
%
% `AD4190 Datasheet <https://www.analog.com/media/en/technical-documentation/data-sheets/ad4190-4.pdf>`_

properties (Nontunable, Hidden)
channel_names = {'voltage0','voltage1','voltage2'...
'voltage3'};
end

methods
%% Constructor
function obj = Rx(varargin)
obj = [email protected]('ad4190','ad4190',varargin{:});
end
end

end
2 changes: 2 additions & 0 deletions +adi/Contents.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
% <a href="matlab:help adi.AD4052 ">AD4052</a> - ADC
% <a href="matlab:help adi.AD4630_16 ">AD4630-16</a> - ADC
% <a href="matlab:help adi.AD4630_24 ">AD4630-24</a> - ADC
% <a href="matlab:help adi.AD4170 ">AD4170</a> - ADC
% <a href="matlab:help adi.AD4190 ">AD4190</a> - ADC
% <a href="matlab:help adi.ADAQ4224 ">ADAQ4224</a> - ADAQ
% <a href="matlab:help adi.AD4858 ">AD4858</a> - ADC
% <a href="matlab:help adi.AD7380 ">AD7380</a> - ADC
Expand Down
2 changes: 2 additions & 0 deletions CI/gen_doc/docs/_pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ The following have device-specific implementations in MATLAB and Simulink. If a
| AD4020 | Zedboard | Yes | No | ADI (2021b) |
| AD4021 | Zedboard | Yes | No | ADI (2021b) |
| AD4022 | Zedboard | Yes | No | ADI (2021b) |
| AD4170 | Zedboard | Yes | No | ADI (2021b) |
| AD4190 | Zedboard | Yes | No | ADI (2021b) |
| AD7124-4 | Zedboard | Yes | No | ADI (2021b) |
| AD7124-8 | Zedboard | Yes | No | ADI (2021b) |
| AD4080 | Zedboard | Yes | No | ADI (2021b) |
Expand Down
2 changes: 2 additions & 0 deletions CI/gen_doc/docs/gen_sysobj_doc.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
, {'AD4020', {'Rx'}}...
, {'AD4021', {'Rx'}}...
, {'AD4022', {'Rx'}}...
, {'AD4170', {'Rx'}}...
, {'AD4190', {'Rx'}}...
, {'AD5760', {'Tx'}}...
, {'AD5780', {'Tx'}}...
, {'AD5781', {'Tx'}}...
Expand Down
3 changes: 3 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ The following have device-specific implementations in MATLAB and Simulink. In ge
"AD7193", "SDP-K1", "Yes", "No", "ADI (2021b)"
"AD7194", "SDP-K1", "Yes", "No", "ADI (2021b)"
"AD7195", "SDP-K1", "Yes", "No", "ADI (2021b)"
"AD4170", "SDP-K1", "Yes", "No", "ADI (2021b)"
"AD4190", "SDP-K1", "Yes", "No", "ADI (2021b)"