From a9135e741da83d829fef443a77a2bf2b7fe298ff Mon Sep 17 00:00:00 2001 From: MPhalke Date: Fri, 28 Jul 2023 15:16:46 +0530 Subject: [PATCH] Add support and doc for AD4858 Added initial precision toolbox support for AD4858 ADC Signed-off-by: MPhalke --- +adi/+AD4858/Rx.m | 97 ++++++++++++++++++++++++++++++++ +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/ad4858_DataCapture.m | 32 +++++++++++ 7 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 +adi/+AD4858/Rx.m create mode 100644 examples/ad4858_DataCapture.m diff --git a/+adi/+AD4858/Rx.m b/+adi/+AD4858/Rx.m new file mode 100644 index 0000000..89d5945 --- /dev/null +++ b/+adi/+AD4858/Rx.m @@ -0,0 +1,97 @@ +classdef Rx < adi.common.Rx & matlabshared.libiio.base & adi.common.Attribute + % AD4858 Precision ADC Class + % adi.AD4858.Rx Receives data from the AD4858 ADC + % The adi.AD4858.Rx System object is a signal source that can receive + % data from the AD4858. + % + % rx = adi.AD4858.Rx; + % rx = adi.AD4858.Rx('uri','192.168.2.1'); + % + % AD4858 Datasheet + + properties (Nontunable) + % SampleRate Sample Rate + % Baseband sampling rate in Hz, specified as a scalar + % in samples per second. + SampleRate = '500000' + + % SamplesPerFrame Samples Per Frame + % Number of samples per frame, specified as an even positive + % integer. + SamplesPerFrame = 1024 + end + + properties (Hidden) + % Number of frames or buffers of data to capture + FrameCount = 1 + end + + % Channel names + properties (Nontunable, Hidden, Constant) + channel_names = { ... + 'voltage0', 'voltage1', 'voltage2', 'voltage3', ... + 'voltage4', 'voltage5', 'voltage6', 'voltage7'} + end + + % isOutput + properties (Hidden, Nontunable, Access = protected) + isOutput = false + end + + properties (Nontunable, Hidden) + Timeout = Inf + kernelBuffersCount = 2 + dataTypeStr = 'int32' + phyDevName = 'ad4858' + devName = 'ad4858' + 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 = 'ip:analog.local'; + end + + function flush(obj) + % Flush the buffer + flushBuffers(obj); + end + + function set.SampleRate(obj, value) + % Set device sampling rate + obj.SampleRate = value; + if obj.ConnectedToDevice + obj.setDeviceAttributeRAW('sampling_frequency', value); + 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('sampling_frequency',num2str(obj.SampleRate)); + end + + end +end diff --git a/+adi/Contents.m b/+adi/Contents.m index 5823d37..8ca3a5d 100644 --- a/+adi/Contents.m +++ b/+adi/Contents.m @@ -11,3 +11,4 @@ % AD4030-24 - ADC % AD4630-16 - ADC % AD4630-24 - ADC +% AD4858 - ADC diff --git a/CI/doc/SysObjsProps.m b/CI/doc/SysObjsProps.m index 32da009..df86f2a 100644 --- a/CI/doc/SysObjsProps.m +++ b/CI/doc/SysObjsProps.m @@ -6,4 +6,5 @@ % * AD4030 % * AD463x % * AD7768 +% * AD7768 diff --git a/CI/doc/genhtml.m b/CI/doc/genhtml.m index 76c34bd..b4130f2 100644 --- a/CI/doc/genhtml.m +++ b/CI/doc/genhtml.m @@ -1,6 +1,6 @@ mfiledir = '..\..\+adi\'; docdir = '..\..\doc\'; -parts = {'AD4630','AD4030','AD463x','AD7768'}; +parts = {'AD4630','AD4030','AD463x','AD7768','AD4858'}; 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 b35e436..9e3ac1d 100644 --- a/CI/gen_doc/docs/_pages/index.md +++ b/CI/gen_doc/docs/_pages/index.md @@ -33,3 +33,4 @@ The following have device-specific implementations in MATLAB and Simulink. If a | AD4030-24 | Zedboard | Yes | No | ADI (2021b) | | AD4630-16 | Zedboard | Yes | No | ADI (2021b) | | AD4630-24 | Zedboard | Yes | No | ADI (2021b) | +| AD4858 | 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 480832e..124addf 100644 --- a/CI/gen_doc/docs/gen_sysobj_doc.m +++ b/CI/gen_doc/docs/gen_sysobj_doc.m @@ -13,6 +13,7 @@ , {'AD4030', {'Rx'}}... , {'AD4630_16', {'Rx'}}... , {'AD4630_24', {'Rx'}}... + , {'AD4858', {'Rx'}}... %{'QuadMxFE',{'Rx','Tx'}}... }; diff --git a/examples/ad4858_DataCapture.m b/examples/ad4858_DataCapture.m new file mode 100644 index 0000000..48bb95b --- /dev/null +++ b/examples/ad4858_DataCapture.m @@ -0,0 +1,32 @@ +%% Script for capturing and displaying a continuous set of samples from a +%% connected AD4858 board + +%% Trigger setup needs to be performed before this example script can be run +%% Refer to the Limitations section in the documentation for details + +% Instantiate the system object +rx = adi.AD4858.Rx; +% Specify uri +rx.uri = 'ip:analog.local'; +rx.SamplesPerFrame = 4096; % Using values less than 3660 can yield poor +% performance, generally +rx.EnabledChannels = [1 2 3 4 5 6 7 8]; + +% 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; + +% 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);