From 8a9c6732482dec43a9231862860d65f3fab7a32d Mon Sep 17 00:00:00 2001 From: Apelete Seketeli Date: Wed, 27 Sep 2023 16:26:46 +0200 Subject: [PATCH 1/6] Add initial support and doc for ad4020 This adds initial support and doc for AD4020 ADC. Signed-off-by: Apelete Seketeli --- +adi/+AD4020/Rx.m | 116 +++++++++++++++++++++++++++++++ +adi/Contents.m | 1 + CI/doc/SysObjsProps.m | 1 + CI/doc/genhtml.m | 2 +- CI/gen_doc/docs/_pages/index.md | 1 + CI/gen_doc/docs/gen_sysobj_doc.m | 1 + examples/ad4020_DataCapture.m | 18 +++++ 7 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 +adi/+AD4020/Rx.m create mode 100644 examples/ad4020_DataCapture.m diff --git a/+adi/+AD4020/Rx.m b/+adi/+AD4020/Rx.m new file mode 100644 index 0000000..501c38b --- /dev/null +++ b/+adi/+AD4020/Rx.m @@ -0,0 +1,116 @@ +classdef Rx < adi.common.Rx & matlabshared.libiio.base & adi.common.Attribute + % AD4020 Precision ADC Class + % adi.AD4020.Rx Receives data from the AD4020 ADC + % The adi.AD4020.Rx System object is a signal source that can receive + % data from the AD4020. + % + % rx = adi.AD4020.Rx; + % rx = adi.AD4020.Rx('uri','192.168.2.1'); + % + % AD4020 Datasheet + + properties (Nontunable) + % SamplesPerFrame Samples Per Frame + % Number of samples per frame, specified as an even positive + % integer. + SamplesPerFrame = 4096 + end + + properties (Dependent) + % Voltage + % ADC Voltage in mV + Voltage + + % VoltageScale Voltage Scale + % ADC Voltage scale. + VoltageScale + + % VoltageOffset Voltage Offset + % ADC Voltage offset. + VoltageOffset + end + + properties + % SamplingFrequency + % Sampling Frequency in Hertz. + SamplingFrequency = 0 + end + + properties (Hidden) + % Number of frames or buffers of data to capture + FrameCount = 1 + end + + % Channel names + properties (Nontunable, Hidden, Constant) + channel_names = {'voltage0'} + end + + % isOutput + properties (Hidden, Nontunable, Access = protected) + isOutput = false + end + + properties (Nontunable, Hidden) + Timeout = Inf + kernelBuffersCount = 1 + dataTypeStr = 'int32' + phyDevName = 'ad4020' + devName = 'ad4020' + end + + properties (Nontunable, Hidden, Constant) + Type = 'Rx' + end + + properties (Hidden, Constant) + ComplexData = false + end + + methods + %% Constructor + function obj = Rx(varargin) + obj = obj@matlabshared.libiio.base(varargin{:}); + obj.enableExplicitPolling = false; + obj.EnabledChannels = 1; + obj.BufferTypeConversionEnable = true; + end + + %% Check Voltage + function rValue = get.Voltage(obj) + if obj.ConnectedToDevice + rValue = obj.getAttributeRAW('voltage0', 'raw', obj.isOutput); + else + rValue = NaN; + end + end + + %% Check Voltage Scale + function rValue = get.VoltageScale(obj) + if obj.ConnectedToDevice + rValue = obj.getAttributeDouble('voltage0', 'scale', obj.isOutput); + else + rValue = NaN; + end + end + + %% Check Voltage Offset + function rValue = get.VoltageOffset(obj) + if obj.ConnectedToDevice + rValue = obj.getAttributeDouble('voltage0', 'offset', obj.isOutput); + else + rValue = NaN; + end + end + end + + %% API Functions + methods (Hidden, Access = protected) + + function setupInit(obj) + % Write sampling frequency attribute from device once connected. + + obj.SamplingFrequency = obj.getDeviceAttributeLongLong('sampling_frequency'); + end + end +end diff --git a/+adi/Contents.m b/+adi/Contents.m index 56c2d5a..735aea5 100644 --- a/+adi/Contents.m +++ b/+adi/Contents.m @@ -13,3 +13,4 @@ % AD4630-24 - ADC % AD4858 - ADC % AD2S1210 - Resolver-to-Digital Converter +% AD4020 - ADC diff --git a/CI/doc/SysObjsProps.m b/CI/doc/SysObjsProps.m index 16083f6..c088b24 100644 --- a/CI/doc/SysObjsProps.m +++ b/CI/doc/SysObjsProps.m @@ -8,3 +8,4 @@ % * AD7768 % * AD7768 % * AD2S1210 +% * AD4020 diff --git a/CI/doc/genhtml.m b/CI/doc/genhtml.m index add1204..77043be 100644 --- a/CI/doc/genhtml.m +++ b/CI/doc/genhtml.m @@ -1,6 +1,6 @@ mfiledir = '..\..\+adi\'; docdir = '..\..\doc\'; -parts = {'AD4630','AD4030','AD463x','AD7768','AD4858','AD2S1210'}; +parts = {'AD4630','AD4030','AD463x','AD7768','AD4858','AD2S1210','AD4020'}; trx_files = {'Rx','Base','Tx'}; for ii = 1:numel(parts) for jj = 1:numel(trx_files) diff --git a/CI/gen_doc/docs/_pages/index.md b/CI/gen_doc/docs/_pages/index.md index 0df7e5c..2b66df5 100644 --- a/CI/gen_doc/docs/_pages/index.md +++ b/CI/gen_doc/docs/_pages/index.md @@ -35,3 +35,4 @@ The following have device-specific implementations in MATLAB and Simulink. If a | AD4630-24 | Zedboard | Yes | No | ADI (2021b) | | AD4858 | Zedboard | Yes | No | ADI (2021b) | | AD2S1210 | Zedboard | Yes | No | ADI (2021b) | +| AD4020 | Zedboard | Yes | No | ADI (2021b) | diff --git a/CI/gen_doc/docs/gen_sysobj_doc.m b/CI/gen_doc/docs/gen_sysobj_doc.m index 20b7dde..f4e0c29 100644 --- a/CI/gen_doc/docs/gen_sysobj_doc.m +++ b/CI/gen_doc/docs/gen_sysobj_doc.m @@ -15,6 +15,7 @@ , {'AD4630_24', {'Rx'}}... , {'AD4858', {'Rx'}}... , {'AD2S1210', {'Rx'}}... + , {'AD4020', {'Rx'}}... %{'QuadMxFE',{'Rx','Tx'}}... }; diff --git a/examples/ad4020_DataCapture.m b/examples/ad4020_DataCapture.m new file mode 100644 index 0000000..5e92fe9 --- /dev/null +++ b/examples/ad4020_DataCapture.m @@ -0,0 +1,18 @@ +%% Script for capturing data from a connected AD4020 board + +% Instantiate the system object +rx = adi.AD4020.Rx('uri','ip:analog.local'); + +% Connect to device and initialize data +rx(); + +% Retrieve ADC voltage, scale and offset +rx.Voltage(); +rx.VoltageScale(); +rx.VoltageOffset(); + +% Print system object properties +rx + +% Delete the system object +release(rx) From 3ce078c033116604fc9cd44085713874a710218c Mon Sep 17 00:00:00 2001 From: Apelete Seketeli Date: Wed, 4 Oct 2023 12:10:44 +0200 Subject: [PATCH 2/6] Remove unused property Signed-off-by: Apelete Seketeli --- +adi/+AD4020/Rx.m | 7 ------- 1 file changed, 7 deletions(-) diff --git a/+adi/+AD4020/Rx.m b/+adi/+AD4020/Rx.m index 501c38b..02b45cf 100644 --- a/+adi/+AD4020/Rx.m +++ b/+adi/+AD4020/Rx.m @@ -9,13 +9,6 @@ % % AD4020 Datasheet - properties (Nontunable) - % SamplesPerFrame Samples Per Frame - % Number of samples per frame, specified as an even positive - % integer. - SamplesPerFrame = 4096 - end - properties (Dependent) % Voltage % ADC Voltage in mV From 46d46327418bed1cd86b9c21b690365e524f9796 Mon Sep 17 00:00:00 2001 From: Apelete Seketeli Date: Wed, 4 Oct 2023 13:00:32 +0200 Subject: [PATCH 3/6] Add SamplesPerFrame property back Signed-off-by: Apelete Seketeli --- +adi/+AD4020/Rx.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/+adi/+AD4020/Rx.m b/+adi/+AD4020/Rx.m index 02b45cf..501c38b 100644 --- a/+adi/+AD4020/Rx.m +++ b/+adi/+AD4020/Rx.m @@ -9,6 +9,13 @@ % % AD4020 Datasheet + properties (Nontunable) + % SamplesPerFrame Samples Per Frame + % Number of samples per frame, specified as an even positive + % integer. + SamplesPerFrame = 4096 + end + properties (Dependent) % Voltage % ADC Voltage in mV From aa7fd92645e386f520143752b75f1db1be9ca0f8 Mon Sep 17 00:00:00 2001 From: Apelete Seketeli Date: Wed, 4 Oct 2023 13:01:38 +0200 Subject: [PATCH 4/6] Remove unused FrameCount property Signed-off-by: Apelete Seketeli --- +adi/+AD4020/Rx.m | 5 ----- 1 file changed, 5 deletions(-) diff --git a/+adi/+AD4020/Rx.m b/+adi/+AD4020/Rx.m index 501c38b..e7d7fe6 100644 --- a/+adi/+AD4020/Rx.m +++ b/+adi/+AD4020/Rx.m @@ -36,11 +36,6 @@ SamplingFrequency = 0 end - properties (Hidden) - % Number of frames or buffers of data to capture - FrameCount = 1 - end - % Channel names properties (Nontunable, Hidden, Constant) channel_names = {'voltage0'} From 72ff4b4de354621ea134507fb65a4dc49a383cf7 Mon Sep 17 00:00:00 2001 From: Apelete Seketeli Date: Thu, 5 Oct 2023 11:15:47 +0200 Subject: [PATCH 5/6] Remove read-only SamplingFrequency property Signed-off-by: Apelete Seketeli --- +adi/+AD4020/Rx.m | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/+adi/+AD4020/Rx.m b/+adi/+AD4020/Rx.m index e7d7fe6..0a904cc 100644 --- a/+adi/+AD4020/Rx.m +++ b/+adi/+AD4020/Rx.m @@ -30,12 +30,6 @@ VoltageOffset end - properties - % SamplingFrequency - % Sampling Frequency in Hertz. - SamplingFrequency = 0 - end - % Channel names properties (Nontunable, Hidden, Constant) channel_names = {'voltage0'} @@ -101,11 +95,7 @@ %% API Functions methods (Hidden, Access = protected) - - function setupInit(obj) - % Write sampling frequency attribute from device once connected. - - obj.SamplingFrequency = obj.getDeviceAttributeLongLong('sampling_frequency'); + function setupInit(~) end end end From 6eaf1a5093591034122893af3e0589350e53c72f Mon Sep 17 00:00:00 2001 From: Apelete Seketeli Date: Tue, 10 Oct 2023 11:04:29 +0200 Subject: [PATCH 6/6] Update documentation using doc strings Signed-off-by: Apelete Seketeli --- CI/gen_doc/docs/sysobjs.json | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/CI/gen_doc/docs/sysobjs.json b/CI/gen_doc/docs/sysobjs.json index 33adcd8..6caceaf 100644 --- a/CI/gen_doc/docs/sysobjs.json +++ b/CI/gen_doc/docs/sysobjs.json @@ -236,5 +236,46 @@ "prop_description": "Hostname or IP address of remote libIIO deviceHelp for adi.AD2S1210.Rx/uri is inherited from superclass matlabshared.libiio.base" } ] + }, + { + "name": "adi.AD4020.Rx", + "dec": " adi.AD4020.Rx Receives data from the AD4020 ADC
The adi.AD4020.Rx System object is a signal source that can receive
data from the AD4020.

rx = adi.AD4020.Rx;
rx = adi.AD4020.Rx('uri','192.168.2.1');

AD4020 Datasheet
Documentation for adi.AD4020.Rx
doc adi.AD4020.Rx
", + "props": [ + { + "prop_name": "EnabledChannels", + "prop_title": " EnabledChannels Enabled Channels", + "prop_description": "Indexs of channels to be enabled. Input should be a [1xN] vector with the indexes of channels to be enabled. Order is irrelevant" + }, + { + "prop_name": "SamplesPerFrame", + "prop_title": " Frame size", + "prop_description": "Size of the frame in samplesHelp for adi.AD4020.Rx/SamplesPerFrame is inherited from superclass matlabshared.libiio.base" + }, + { + "prop_name": "SamplingFrequency", + "prop_title": " SamplingFrequency", + "prop_description": "Sampling Frequency in Hertz." + }, + { + "prop_name": "Voltage", + "prop_title": " Voltage", + "prop_description": "ADC Voltage in mV" + }, + { + "prop_name": "VoltageOffset", + "prop_title": " VoltageOffset Voltage Offset", + "prop_description": "ADC Voltage offset." + }, + { + "prop_name": "VoltageScale", + "prop_title": " VoltageScale Voltage Scale", + "prop_description": "ADC Voltage scale." + }, + { + "prop_name": "uri", + "prop_title": " URI - remote host URI", + "prop_description": "Hostname or IP address of remote libIIO deviceHelp for adi.AD4020.Rx/uri is inherited from superclass matlabshared.libiio.base" + } + ] } ]