Skip to content

Commit

Permalink
Add support and doc for AD4858
Browse files Browse the repository at this point in the history
Added initial precision toolbox support for AD4858 ADC

Signed-off-by: MPhalke <[email protected]>
  • Loading branch information
mphalke authored and ribdp committed Oct 13, 2023
1 parent a6e79aa commit a9135e7
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 1 deletion.
97 changes: 97 additions & 0 deletions +adi/+AD4858/Rx.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
classdef Rx < adi.common.Rx & matlabshared.libiio.base & adi.common.Attribute
% AD4858 Precision ADC Class
% adi.AD4858.Rx Receives data from the AD4858 ADC
% The adi.AD4858.Rx System object is a signal source that can receive
% data from the AD4858.
%
% rx = adi.AD4858.Rx;
% rx = adi.AD4858.Rx('uri','192.168.2.1');
%
% <a href="https://www.analog.com/media/en/technical-documentation/data-sheets/ad4858.pdf">AD4858 Datasheet</a>

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

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

properties (Hidden)
% Number of frames or buffers of data to capture
FrameCount = 1
end

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

% isOutput
properties (Hidden, Nontunable, Access = protected)
isOutput = false
end

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

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

properties (Hidden, Constant)
ComplexData = false
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 = 'ip:analog.local';
end

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

function set.SampleRate(obj, value)
% Set device sampling rate
obj.SampleRate = value;
if obj.ConnectedToDevice
obj.setDeviceAttributeRAW('sampling_frequency', value);
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
end
1 change: 1 addition & 0 deletions +adi/Contents.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
% <a href="matlab:help adi.AD4030 ">AD4030-24</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.AD4858 ">AD4858</a> - ADC
1 change: 1 addition & 0 deletions CI/doc/SysObjsProps.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
% * AD4030 <AD4030_Rx.html Rx>
% * AD463x <AD463x_Rx.html Rx>
% * AD7768 <AD7768_Rx.html Rx>
% * AD7768 <AD4858_Rx.html Rx>

2 changes: 1 addition & 1 deletion CI/doc/genhtml.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mfiledir = '..\..\+adi\';
docdir = '..\..\doc\';
parts = {'AD4630','AD4030','AD463x','AD7768'};
parts = {'AD4630','AD4030','AD463x','AD7768','AD4858'};
trx_files = {'Rx','Base','Tx'};
for ii = 1:numel(parts)
for jj = 1:numel(trx_files)
Expand Down
1 change: 1 addition & 0 deletions CI/gen_doc/docs/_pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ The following have device-specific implementations in MATLAB and Simulink. If a
| AD4030-24 | Zedboard | Yes | No | ADI (2021b) |
| AD4630-16 | Zedboard | Yes | No | ADI (2021b) |
| AD4630-24 | Zedboard | Yes | No | ADI (2021b) |
| AD4858 | Zedboard | Yes | No | ADI (2021b) |
1 change: 1 addition & 0 deletions CI/gen_doc/docs/gen_sysobj_doc.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
, {'AD4030', {'Rx'}}...
, {'AD4630_16', {'Rx'}}...
, {'AD4630_24', {'Rx'}}...
, {'AD4858', {'Rx'}}...
%{'QuadMxFE',{'Rx','Tx'}}...
};

Expand Down
32 changes: 32 additions & 0 deletions examples/ad4858_DataCapture.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
%% Script for capturing and displaying a continuous set of samples from a
%% connected AD4858 board

%% Trigger setup needs to be performed before this example script can be run
%% Refer to the Limitations section in the documentation for details

% Instantiate the system object
rx = adi.AD4858.Rx;
% Specify uri
rx.uri = 'ip:analog.local';
rx.SamplesPerFrame = 4096; % Using values less than 3660 can yield poor
% performance, generally
rx.EnabledChannels = [1 2 3 4 5 6 7 8];

% The parameter below specifies the number of frames or buffers to capture.
% Refer to the Streaming section in the documentation if discontinuities
% are observed in the acquired data.
rx.FrameCount = 1;

% Capture data
data = rx();

enabledChannels = size(data, 2);
figure(1);
for i = 1:enabledChannels
subplot(enabledChannels, 1, i);
plot(data(1:rx.FrameCount * rx.SamplesPerFrame, i));
title("Channel " + num2str(rx.EnabledChannels(i)));
end

% Delete the system object
release(rx);

0 comments on commit a9135e7

Please sign in to comment.