Skip to content

Commit

Permalink
adi:AD4170:Add support for AD4170
Browse files Browse the repository at this point in the history
Add MATLAB support for AD4170

Signed-off-by: Janani Sunil <[email protected]>
  • Loading branch information
jansunil committed Jun 18, 2024
1 parent 3a846c3 commit 58f8c29
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
120 changes: 120 additions & 0 deletions +adi/+AD4170/Rx.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
classdef Rx < adi.common.Rx & matlabshared.libiio.base & adi.common.Attribute
% 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');`
%
% `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

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
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);
end
end
end
1 change: 1 addition & 0 deletions +adi/Contents.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
% <a href="matlab:help adi.AD5791 ">AD5791</a> - DAC
% <a href="matlab:help adi.AD7124_4 ">AD7124_4</a> - ADC
% <a href="matlab:help adi.AD7124_8 ">AD7124_8</a> - ADC
% <a href="matlab:help adi.AD4170 ">AD7124_8</a> - ADC
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 @@ -49,5 +49,6 @@ 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) |
| AD7124-4 | Zedboard | Yes | No | ADI (2021b) |
| AD7124-8 | 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 @@ -29,6 +29,7 @@
, {'AD4020', {'Rx'}}...
, {'AD4021', {'Rx'}}...
, {'AD4022', {'Rx'}}...
, {'AD4170', {'Rx'}}...
, {'AD5760', {'Tx'}}...
, {'AD5780', {'Tx'}}...
, {'AD5781', {'Tx'}}...
Expand Down
24 changes: 24 additions & 0 deletions examples/ad4170_DataCapture.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
%% Script for capturing and displaying a continuous set of samples from a
%% connected AD4170 board

% Instantiate the system object
rx = adi.AD4170.Rx();
rx.uri = 'serial:COM18,230400';

% Samples per frame cannot exceed 500 if all 16 channels need to be captured on AD4170
rx.SamplesPerFrame = 500;
rx.EnabledChannels = [1];

% Capture data
data = rx();

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

% Delete the system object
release(rx);

0 comments on commit 58f8c29

Please sign in to comment.