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

DRAFT: add AD7173 family #42

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
29 changes: 29 additions & 0 deletions +adi/+AD4111/Rx.m
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'};
Copy link
Author

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 differentialX but something like in_voltage3-voltage5_raw
I'm unsure how to translate this here? other devices in the toolbox seems to use differentialX, not sure how this works?

end

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

end
155 changes: 155 additions & 0 deletions +adi/+AD7173/Base.m
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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand where the SampleRate/SamplesPerFrame default values come from?

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'
Copy link
Author

Choose a reason for hiding this comment

The 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

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.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);
Copy link
Author

Choose a reason for hiding this comment

The 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 GetChannelAttrValue() exists in +Generic/Rx.m but I'm unsure how to get the chnID from the first enabled channel?

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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what all this boilerplate is doing!?


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

end