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:AD4170:Add support for AD4170 #31

Merged
merged 1 commit into from
Jun 19, 2024
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
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 docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ The following have device-specific implementations in MATLAB and Simulink. In ge
"AD7124-4", "Zedboard", "Yes", "No", "ADI (2021b)"
"AD7124-8", "Zedboard", "Yes", "No", "ADI (2021b)"
"AD4052", "SDP-K1", "Yes", "No", "ADI (2021b)"
"AD4170", "SDP-K1", "Yes", "No", "ADI (2021b)"

35 changes: 35 additions & 0 deletions docs/source/reference_api/AD4170_Rx.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
adi.AD4170.Rx
-------------

**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>`_

Class Properties
================

**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'

**EnabledChannels Enabled Channels**
Indexs of channels to be enabled. Input should be a [1xN] vector with the indexes of channels to be enabled. Order is irrelevant

**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

**SampleRate Sample Rate**
Baseband sampling rate in Hz, specified as a scalar in samples per second.

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

**URI - remote host URI**
Hostname or IP address of remote libIIO deviceHelp for adi.AD4170.Rx/uri is inherited from superclass matlabshared.libiio.base

1 change: 1 addition & 0 deletions docs/source/reference_api/gen_sysobj_doc.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
, {'AD4020', {'Rx'}}...
, {'AD4021', {'Rx'}}...
, {'AD4022', {'Rx'}}...
, {'AD4170', {'Rx'}}...
, {'AD5760', {'Tx'}}...
, {'AD5780', {'Tx'}}...
, {'AD5781', {'Tx'}}...
Expand Down
1 change: 1 addition & 0 deletions docs/source/reference_api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Reference APIs
AD4020_Rx.rst
AD4021_Rx.rst
AD4022_Rx.rst
AD4170_Rx.rst
AD5760_Tx.rst
AD5780_Tx.rst
AD5781_Tx.rst
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);
Loading