From 665144efeab4f96535bdbcef3b4e15f480b74d66 Mon Sep 17 00:00:00 2001 From: Janani Sunil Date: Tue, 18 Jun 2024 14:50:11 +0530 Subject: [PATCH] adi:AD4170:Add support for AD4170 Add MATLAB support for AD4170 Signed-off-by: Janani Sunil --- +adi/+AD4170/Rx.m | 120 +++++++++++++++++++++ +adi/Contents.m | 1 + docs/source/index.rst | 1 + docs/source/reference_api/AD4170_Rx.rst | 35 ++++++ docs/source/reference_api/gen_sysobj_doc.m | 1 + docs/source/reference_api/index.rst | 1 + examples/ad4170_DataCapture.m | 24 +++++ 7 files changed, 183 insertions(+) create mode 100644 +adi/+AD4170/Rx.m create mode 100644 docs/source/reference_api/AD4170_Rx.rst create mode 100644 examples/ad4170_DataCapture.m diff --git a/+adi/+AD4170/Rx.m b/+adi/+AD4170/Rx.m new file mode 100644 index 0000000..26cc6fa --- /dev/null +++ b/+adi/+AD4170/Rx.m @@ -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 `_ + + 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 = obj@matlabshared.libiio.base(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 \ No newline at end of file diff --git a/+adi/Contents.m b/+adi/Contents.m index c2d5536..e912239 100644 --- a/+adi/Contents.m +++ b/+adi/Contents.m @@ -34,3 +34,4 @@ % AD5791 - DAC % AD7124_4 - ADC % AD7124_8 - ADC +% AD7124_8 - ADC diff --git a/docs/source/index.rst b/docs/source/index.rst index 206c33d..2b2fcb8 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -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)" diff --git a/docs/source/reference_api/AD4170_Rx.rst b/docs/source/reference_api/AD4170_Rx.rst new file mode 100644 index 0000000..d9dadf3 --- /dev/null +++ b/docs/source/reference_api/AD4170_Rx.rst @@ -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 `_ + +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 + diff --git a/docs/source/reference_api/gen_sysobj_doc.m b/docs/source/reference_api/gen_sysobj_doc.m index 2481835..fce670f 100644 --- a/docs/source/reference_api/gen_sysobj_doc.m +++ b/docs/source/reference_api/gen_sysobj_doc.m @@ -26,6 +26,7 @@ , {'AD4020', {'Rx'}}... , {'AD4021', {'Rx'}}... , {'AD4022', {'Rx'}}... + , {'AD4170', {'Rx'}}... , {'AD5760', {'Tx'}}... , {'AD5780', {'Tx'}}... , {'AD5781', {'Tx'}}... diff --git a/docs/source/reference_api/index.rst b/docs/source/reference_api/index.rst index 5cb2b62..0188a63 100644 --- a/docs/source/reference_api/index.rst +++ b/docs/source/reference_api/index.rst @@ -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 diff --git a/examples/ad4170_DataCapture.m b/examples/ad4170_DataCapture.m new file mode 100644 index 0000000..d364864 --- /dev/null +++ b/examples/ad4170_DataCapture.m @@ -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); \ No newline at end of file