-
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:ad4080: Add initial AD4080 support #24
Open
ribdp
wants to merge
1
commit into
main
Choose a base branch
from
add-ad4080-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+216
−1
Open
Changes from all commits
Commits
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,146 @@ | ||
classdef Rx < adi.common.Rx & adi.common.RxTx & ... | ||
matlabshared.libiio.base & adi.common.Attribute & ... | ||
adi.common.RegisterReadWrite & adi.common.Channel | ||
% AD4080 Precision ADC Class | ||
% adi.AD4080.Rx Receives data from the AD4080 ADC | ||
% The adi.AD4080.Rx System object is a signal source that can receive | ||
% data from the AD4080. | ||
% | ||
% rx = adi.AD4080.Rx; | ||
% rx = adi.AD4080.Rx('uri','192.168.2.1'); | ||
% | ||
% <a href="https://www.analog.com/media/en/technical-documentation/data-sheets/ad4080.pdf">AD4080 Datasheet</a> | ||
|
||
properties (Nontunable) | ||
% SampleRate Sample Rate | ||
% Baseband sampling rate in Hz, specified as a scalar | ||
% in samples per second. Options are: | ||
% '256000','128000','64000','32000','16000','8000','4000', | ||
% '2000','1000' | ||
SampleRate = '40000000' | ||
|
||
% SamplesPerFrame Samples Per Frame | ||
% The number of samples to be captured as part of one continuous buffer | ||
SamplesPerFrame = 4096 | ||
|
||
% Scale Scale | ||
% Scale value to be used to convert the code to voltage | ||
Scale = 0.005722 | ||
|
||
% TestMode Test Mode | ||
% Test Mode for AD4080. Options are: | ||
% 'off', 'midscale_short', 'pos_fullscale', | ||
% 'neg_fullscale', 'checkerboard', 'pn_long', 'on_short', 'one_zero_toggle', | ||
% 'user', 'bit_toggle', 'sync', 'one_bit_high', 'mixed_bit_frequency' | ||
TestMode = 'off' | ||
|
||
end | ||
|
||
properties (Nontunable, Hidden) | ||
channel_names = { ... | ||
'voltage0'} | ||
end | ||
|
||
properties (Hidden, Nontunable, Access = protected) | ||
isOutput = false | ||
end | ||
|
||
properties (Constant, Hidden) | ||
SampleRateSet = matlab.system.StringSet({ ... | ||
'40000000', '256000', '128000', '64000', ... | ||
'32000', '16000', '8000', '4000', ... | ||
'2000', '1000'}) | ||
|
||
TestModeSet = matlab.system.StringSet({'off', 'midscale_short', 'pos_fullscale', ... | ||
'neg_fullscale', 'checkerboard', 'pn_long', 'on_short', 'one_zero_toggle', ... | ||
'user', 'bit_toggle', 'sync', 'one_bit_high', 'mixed_bit_frequency'}) | ||
|
||
end | ||
|
||
properties (Nontunable, Hidden) | ||
Timeout = Inf | ||
dataTypeStr = 'int32' | ||
phyDevName = 'ad4080' | ||
devName = 'ad4080' | ||
end | ||
|
||
properties (Nontunable, Hidden, Constant) | ||
Type = 'Rx' | ||
ComplexData = false | ||
end | ||
|
||
methods | ||
|
||
%% Constructor | ||
function obj = Rx(varargin) | ||
obj = [email protected](varargin{:}); | ||
obj.enableExplicitPolling = false; | ||
obj.EnabledChannels = 1; | ||
obj.BufferTypeConversionEnable = true; | ||
obj.uri = 'ip:analog.local'; | ||
end | ||
|
||
function flush(obj) | ||
flushBuffers(obj); | ||
end | ||
|
||
% Check SamplingRate | ||
function set.SampleRate(obj, value) | ||
obj.SampleRate = value; | ||
if obj.ConnectedToDevice | ||
obj.setDeviceAttributeRAW('sampling_frequency', value); | ||
end | ||
end | ||
|
||
% Check TestMode | ||
function set.TestMode(obj, value) | ||
obj.TestMode = value; | ||
if obj.ConnectedToDevice | ||
obj.setDeviceAttributeRAW('test_mode', value); | ||
end | ||
end | ||
|
||
end | ||
|
||
methods (Access = protected) | ||
|
||
function numOut = getNumOutputsImpl(~) | ||
numOut = 2; | ||
end | ||
|
||
end | ||
|
||
%% API Functions | ||
methods (Hidden) | ||
|
||
function setupExtra(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)); | ||
obj.setAttributeRAW('voltage0', 'test_mode', obj.TestMode, false); | ||
end | ||
|
||
end | ||
|
||
%% External Dependency Methods | ||
methods (Hidden, Static) | ||
|
||
function tf = isSupportedContext(bldCfg) | ||
tf = matlabshared.libiio.ExternalDependency.isSupportedContext(bldCfg); | ||
end | ||
|
||
function updateBuildInfo(buildInfo, bldCfg) | ||
% Call the matlabshared.libiio.method first | ||
matlabshared.libiio.ExternalDependency.updateBuildInfo(buildInfo, bldCfg); | ||
end | ||
|
||
function bName = getDescriptiveName(~) | ||
bName = 'AD4080 Precision ADC'; | ||
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
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
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,25 @@ | ||
%% Script for capturing and displaying a continuous set of samples from a | ||
%% connected EVAL-AD4080-FMCZ board | ||
|
||
% Instantiate the system object | ||
rx = adi.AD4080.Rx; | ||
% Specify uri | ||
rx.uri = 'ip:analog.local'; | ||
|
||
rx.SamplesPerFrame = 4096; | ||
rx.EnabledChannels = [1]; | ||
rx.TestMode = 'midscale_short'; | ||
|
||
% 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); |
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.
Add "ip:" prior to the address