-
Notifications
You must be signed in to change notification settings - Fork 11
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
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 = [email protected]('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 | ||
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. 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' | ||
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 |
||
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); | ||
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 |
||
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 | ||
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. not sure what all this boilerplate is doing!? |
||
|
||
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
differentialX
but something likein_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?