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: Add support for AD4052 #28

Merged
merged 3 commits into from
May 20, 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
39 changes: 39 additions & 0 deletions +adi/+AD4052/Rx.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
classdef Rx < adi.common.Rx & adi.common.RxTx ...
& adi.AD405x.Base

% AD4052 Precision ADC Class
%
% adi.AD4052.Rx Receive data from the AD4052 ADC
% The adi.AD4052.Rx System object is a signal source that can receive
% data from the AD4052.
%
% `rx = adi.AD4052.Rx;`
% `rx = adi.AD4052.Rx('uri','serial:COM5,230400');`
%
% `AD4052 Datasheet <http://www.analog.com/media/en/technical-documentation/data-sheets/AD4052.pdf>`_

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

properties (Hidden)
Timeout = Inf
kernelBuffersCount = 1
dataTypeStr = 'int32'
phyDevName = 'ad4052'
devName = 'ad4052'
end

methods
%% Constructor

function obj = Rx(Args)
arguments
Args.uri
end
coder.allowpcode('plain');
obj = [email protected]('devName', 'ad4052', 'phyDevName', 'ad4052', 'uri', Args.uri);
end

end
end
118 changes: 118 additions & 0 deletions +adi/+AD405x/Base.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
classdef Base < adi.common.Rx & adi.common.RxTx & ...
matlabshared.libiio.base & adi.common.Attribute & ...
adi.common.RegisterReadWrite & adi.common.Channel
% AD405x is a family of Precision ADC
% AD4052 is single channel 16bit SAR ADC with max sampling frequency
% of 2MSPS

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

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

% BurstAveragingLength Burst Averaging Length
% Length of the averaging filter in 'burst averaging mode'
AvgFilterLength = 2

% BurstSampleRate Burst Sample Rate
% Rate of internal averaging in 'burst averaging mode'
BurstSampleRate = "2msps"

end

properties (Nontunable, Hidden)
channel_names = {'voltage0'}
end

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

properties (Hidden, Constant)
ComplexData = false
end

methods

%% Constructor
function obj = Base(Args)
arguments
Args.devName
Args.phyDevName
Args.uri
end

obj = [email protected]();
obj.enableExplicitPolling = false;
obj.EnabledChannels = 1;
obj.BufferTypeConversionEnable = true;

% Set device name, phyDevName, uri from input arguments
try
obj.devName = Args.devName;
obj.phyDevName = Args.phyDevName;
obj.uri = Args.uri;
catch
e = MException('MATLAB:notEnoughInputs',['Not enough input ' ...
'arguments. Specify devName, phyDevName and uri']);
throw(e)
end

% Determine datatype using trial and error
possibleDataTypeStr = {'int16', 'int32'};
for k = 1:length(possibleDataTypeStr)
try
obj.dataTypeStr = possibleDataTypeStr{k};
obj.setup();
break;
catch
end
end
assert(obj.ConnectedToDevice == 1, "Connection could not be established with the specified device")

release(obj)

end

function set.AvgFilterLength(obj, value)
% Setter method for the Averaging Filter Length attribute
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Can format comment spacing in-line with the line 85. Same comment for line 93.

obj.AvgFilterLength = value;
if obj.ConnectedToDevice
val = obj.setDeviceAttributeRAW('avg_filter_length', num2str(value));
end

end

function set.BurstSampleRate(obj, value)
% Setter method for the Burst Sampple Rate attribute
obj.BurstSampleRate = value;
if obj.ConnectedToDevice
val = obj.setDeviceAttributeRAW('burst_sample_rate', num2str(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 doesn't support
% modification to nontunable variables at SetupImpl

obj.setDeviceAttributeRAW('sampling_frequency', num2str(obj.SampleRate));

end

end
end
Empty file added +adi/+AD405x/Rx.m
Empty file.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ If this PR contains a breaking change, list dependent PRs and try to push all re
- [ ] I have build all projects affected by the changes in this PR
- [ ] I have tested in hardware affected projects, at the relevant boards
- [ ] I have signed off all commits from this PR
- [ ] I have updated the documentation by running CI/gen_doc/docs/gen_sysobj_doc.m script locally, if applies.
- [ ] I have updated the documentation by running /docs/source/reference_api/gen_sysobj_doc.m script locally, if applies.
4 changes: 2 additions & 2 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
with:
submodules: recursive
- name: Set up Python 3.7
uses: actions/setup-python@v2
uses: actions/setup-python@v5
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be part of a separate commit (maybe the previous one on documentation) and a relevant message be added to the commit?

with:
python-version: 3.7
python-version: 3.x

- name: Install dependencies
run: |
Expand Down
3 changes: 2 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ADI maintains a set of tools to interface with ADI precision converters within M
The following have device-specific implementations in MATLAB and Simulink. In general, if a device has an IIO driver, MATLAB support is possible, but a device-specific MATLAB or Simulink interface may not exist yet.

.. csv-table:: Supported Parts
:header: "Evaluation Card", "FPGA Board", "Streaming Support", "Targeting", "Variants and Minimum Supported Release"
:header: "Evaluation Card", "Controller Board", "Streaming Support", "Targeting", "Variants and Minimum Supported Release"
:widths: 30, 30, 30, 30, 30

"AD7380", "Zedboard", "Yes", "No", "ADI (2021b)"
Expand Down Expand Up @@ -57,4 +57,5 @@ The following have device-specific implementations in MATLAB and Simulink. In ge
"AD5791", "Zedboard", "Yes", "No", "ADI (2021b)"
"AD7124-4", "Zedboard", "Yes", "No", "ADI (2021b)"
"AD7124-8", "Zedboard", "Yes", "No", "ADI (2021b)"
"AD4052", "SDP-K1", "Yes", "No", "ADI (2021b)"

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

**AD4052 Precision ADC Class**

adi.AD4052.Rx Receive data from the AD4052 ADC
The adi.AD4052.Rx System object is a signal source that can receive
data from the AD4052.

`rx = adi.AD4052.Rx;`
`rx = adi.AD4052.Rx('uri','serial:COM5,230400');`

`AD4052 Datasheet <http://www.analog.com/media/en/technical-documentation/data-sheets/AD4052.pdf>`_

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

**BurstAveragingLength Burst Averaging Length**
Length of the averaging filter in 'burst averaging mode'Help for adi.AD4052.Rx/AvgFilterLength is inherited from superclass adi.AD405x.Base

**BurstSampleRate Burst Sample Rate**
Rate of internal averaging in 'burst averaging mode'Help for adi.AD4052.Rx/BurstSampleRate is inherited from superclass adi.AD405x.Base

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

**SampleRate Sample Rate**
Baseband sampling rate in Hz, specified as a scalar in samples per second.Help for adi.AD4052.Rx/SampleRate is inherited from superclass adi.AD405x.Base

**SamplesPerFrame Samples Per Frame**
Number of samples per frame, specified as an even positive integer.Help for adi.AD4052.Rx/SamplesPerFrame is inherited from superclass adi.AD405x.Base

**URI - remote host URI**
Hostname or IP address of remote libIIO deviceHelp for adi.AD4052.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 @@ -33,6 +33,7 @@
, {'AD5791', {'Tx'}}...
, {'AD7124_4', {'Rx'}}...
, {'AD7124_8', {'Rx'}}...
, {'AD4052', {'Rx'}}...
};

all_devs = [];
Expand Down
2 changes: 1 addition & 1 deletion docs/source/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sphinx
myst_parser
sphinx
https://github.com/analogdevicesinc/doctools/releases/download/latest/adi-doctools.tar.gz
23 changes: 23 additions & 0 deletions examples/ad4052_DataCapture.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
%% Script for capturing and displaying a continuous set of samples from a
%% connected AD4052 board

% Instantiate the system object
rx = adi.AD4052.Rx('uri', 'serial:COM13,230400');
rx.SamplesPerFrame = 400;
rx.EnabledChannels = [1];

rx.SampleRate = 62500; % In sample mode, the sampling rate can be as high as 1MSPS

% 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