-
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
adi: Add support for AD4052 #28
Merged
+222
−5
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,9 @@ jobs: | |
with: | ||
submodules: recursive | ||
- name: Set up Python 3.7 | ||
uses: actions/setup-python@v2 | ||
uses: actions/setup-python@v5 | ||
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. 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: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: Can format comment spacing in-line with the line 85. Same comment for line 93.