From 9df1085546795539b667724c51c8918514e31dd1 Mon Sep 17 00:00:00 2001 From: SGudla Date: Thu, 3 Oct 2024 19:19:59 +0530 Subject: [PATCH] adi: adaq4224: Add support for adaq4224_DataCapture.m 1. Add driver for adaq4224. 2. Add example script for data capture. 3. Update index.rst and Contents.m files. Signed-off-by: SGudla --- +adi/+ADAQ4224/Rx.m | 77 +++++++++++++++++++++++++++++++++ +adi/Contents.m | 1 + docs/source/index.rst | 1 + examples/adaq4224_DataCapture.m | 54 +++++++++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 +adi/+ADAQ4224/Rx.m create mode 100644 examples/adaq4224_DataCapture.m diff --git a/+adi/+ADAQ4224/Rx.m b/+adi/+ADAQ4224/Rx.m new file mode 100644 index 0000000..81b2355 --- /dev/null +++ b/+adi/+ADAQ4224/Rx.m @@ -0,0 +1,77 @@ +classdef Rx `_ + + properties + % Scale Channel Scale Value + Scale = 0.001464843 + end + + properties (Nontunable, Hidden, Constant) + Type = 'Rx' + end + + properties (Hidden) + % Number of frames or buffers of data to capture + FrameCount = 1 + end + + properties (Nontunable, Hidden) + + % Channels present with default register settings - + channel_names = {'voltage0'} + end + + properties (Hidden) + Timeout = Inf + kernelBuffersCount = 4 + dataTypeStr = 'int64' + phyDevName = 'adaq4224' + devName = 'adaq4224' + end + + methods + %%Constructor + function obj = Rx(varargin) + obj = obj@adi.AD463x.Base(varargin{:}); + end + + function set.Scale(obj, value) + obj.Scale = value; + if obj.ConnectedToDevice + id = 'voltage0'; + obj.setAttributeRAW(id, 'scale', num2str(value), false); + end + end + + function value = get.Scale(obj) + value = obj.Scale; + if obj.ConnectedToDevice + value = obj.getAttributeRAW('voltage0', 'scale', false); + 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.setAttributeRAW('voltage0', 'scale', num2str(obj.Scale), false); + end + end + +end \ No newline at end of file diff --git a/+adi/Contents.m b/+adi/Contents.m index c2d5536..4880534 100644 --- a/+adi/Contents.m +++ b/+adi/Contents.m @@ -22,6 +22,7 @@ % AD4030-24 - ADC % AD4630-16 - ADC % AD4630-24 - ADC +% ADAQ4224 - ADAQ % AD4858 - ADC % AD7380 - ADC % AD7768 - ADC diff --git a/docs/source/index.rst b/docs/source/index.rst index fdd4066..a1d40b9 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -34,6 +34,7 @@ The following have device-specific implementations in MATLAB and Simulink. In ge "AD4030-24", "Zedboard", "Yes", "No", "ADI (2021b)" "AD4630-16", "Zedboard", "Yes", "No", "ADI (2021b)" "AD4630-24", "Zedboard", "Yes", "No", "ADI (2021b)" + "ADAQ4224", "Zedboard", "Yes", "No", "ADI (2021b)" "AD4858", "Zedboard", "Yes", "No", "ADI (2021b)" "AD2S1210", "Zedboard", "Yes", "No", "ADI (2021b)" "AD4000", "Zedboard", "Yes", "No", "ADI (2021b)" diff --git a/examples/adaq4224_DataCapture.m b/examples/adaq4224_DataCapture.m new file mode 100644 index 0000000..d7f90a7 --- /dev/null +++ b/examples/adaq4224_DataCapture.m @@ -0,0 +1,54 @@ +%% Script for capturing and displaying data from a connected ADAQ4224 board + + +% Instantiate the ADAQ4224 Rx system object, and specify the uri in this +% manner +%ip:analog.local +rx = adi.ADAQ4224.Rx('uri','ip:10.32.22.194'); + +rx.SamplesPerFrame = 4096; % Using values less than 3660 can yield poor +% performance, generally +rx.SampleRate = '2000000'; +rx.SampleAveragingLength = '16'; + +% The parameter below specifies the number of frames or buffers to capture. +% Refer to the Streaming section in the documentation if discontinuities +% are observed in the acquired data. +rx.FrameCount = 1; + +% Only a select few channel groupings yield sensible outputs. Refer to the +% Limitations section in the documentation for more details +rx.EnabledChannels = [1]; + +% Set channel scale value +rx.Scale = 0.001464843; +fprintf("Sampling with gain set to %s\n", num2str(rx.Scale)); + +% Capture data +data = rx(); + +enabledChannels = size(data, 2); +figure(1); +for i = 1:enabledChannels + subplot(enabledChannels, 1, i); + plot(data(1:rx.SamplesPerFrame * rx.FrameCount, i)); + title("Channel " + num2str(rx.EnabledChannels(i))); +end + +% Set channel scale value +rx.Scale = 0.000219726; +fprintf("Sampling with gain set to %s\n", num2str(rx.Scale)) + +% Capture data +data = rx(); + +enabledChannels = size(data, 2); +figure(2); +for i = 1:enabledChannels + subplot(enabledChannels, 1, i); + plot(data(1:rx.SamplesPerFrame * rx.FrameCount, i)); + title("Channel " + num2str(rx.EnabledChannels(i))); +end + +% Delete the system object +release(rx);