-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MATLAB support for AD4170 Signed-off-by: Janani Sunil <[email protected]>
- Loading branch information
Showing
7 changed files
with
183 additions
and
0 deletions.
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,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 |
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,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 | ||
|
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,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); |