From 6e2d65a66664ab84878d930e76a6c4e51607ad06 Mon Sep 17 00:00:00 2001 From: Disha D Date: Mon, 11 Mar 2024 12:32:55 +0530 Subject: [PATCH] Add support and doc for AD7124 Signed-off-by: Disha D --- +adi/+AD7124/Base.m | 102 +++++++++++++++++++++++++++++++ +adi/+AD7124_4/Rx.m | 27 ++++++++ +adi/+AD7124_8/Rx.m | 27 ++++++++ +adi/Contents.m | 2 + CI/gen_doc/docs/_pages/index.md | 2 + CI/gen_doc/docs/gen_sysobj_doc.m | 2 + examples/ad7124_DataCapture.m | 25 ++++++++ 7 files changed, 187 insertions(+) create mode 100644 +adi/+AD7124/Base.m create mode 100644 +adi/+AD7124_4/Rx.m create mode 100644 +adi/+AD7124_8/Rx.m create mode 100644 examples/ad7124_DataCapture.m diff --git a/+adi/+AD7124/Base.m b/+adi/+AD7124/Base.m new file mode 100644 index 0000000..b426306 --- /dev/null +++ b/+adi/+AD7124/Base.m @@ -0,0 +1,102 @@ +classdef Base < adi.common.Rx & adi.common.RxTx & ... + matlabshared.libiio.base & adi.common.Attribute & ... + adi.common.RegisterReadWrite & adi.common.Channel + % AD7124 Precision ADC Class + % AD7124-4 is a 8 channel ADC + % AD7124-8 is a 16 channel ADC + + properties (Nontunable) + % SampleRate Sample Rate + % Baseband sampling rate in Hz, specified as a scalar + % in samples per second. + SampleRate = '19200' + + % SamplesPerFrame Samples Per Frame + % Number of samples per frame, specified as an even positive + % integer. + SamplesPerFrame = 400 + end + + % isOutput + properties (Hidden, Nontunable, Access = protected) + isOutput = false + end + + properties (Nontunable, Hidden, Constant) + Type = 'Rx' + end + + properties (Nontunable, Hidden) + Timeout = Inf + kernelBuffersCount = 1 + dataTypeStr = 'int32' + phyDevName + devName + end + + properties (Hidden, Constant) + ComplexData = false + end + + methods + %% Constructor + function obj = Base(phydev,dev,varargin) + coder.allowpcode('plain'); + % Initialize the Rx object + obj = obj@matlabshared.libiio.base(varargin{:}); + obj.enableExplicitPolling = false; + obj.EnabledChannels = 1; + obj.BufferTypeConversionEnable = true; + obj.phyDevName = phydev; + obj.devName = dev; + obj.uri = 'ip:analog.local'; + end + + function flush(obj) + % Flush the buffer + flushBuffers(obj); + end + + function delete(obj) + % Destructor + delete@adi.common.RxTx(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 + + %% External Dependency Methods + methods (Hidden, Static) + function tf = isSupportedContext(bldCfg) + tf = matlabshared.libiio.ExternalDependency.isSupportedContext(bldCfg); + end + + function updateBuildInfo(buildInfo, bldCfg) + % Call the matlabshared.libiio.method first + matlabshared.libiio.ExternalDependency.updateBuildInfo(buildInfo, bldCfg); + end + + function bName = getDescriptiveName(~) + bName = 'AD7124 ADC'; + end + end + +end \ No newline at end of file diff --git a/+adi/+AD7124_4/Rx.m b/+adi/+AD7124_4/Rx.m new file mode 100644 index 0000000..0c62926 --- /dev/null +++ b/+adi/+AD7124_4/Rx.m @@ -0,0 +1,27 @@ +classdef Rx < adi.common.Rx & adi.common.RxTx ... + & adi.AD7124.Base + % AD7124-4 Precision ADC Class + % adi.AD7124-4.Rx Receives data from the AD7124 ADC + % The adi.AD7124-4.Rx System object is a signal source that can receive + % data from the AD7124-4. + % + % rx = adi.AD7124_4.Rx; + % rx = adi.AD7124_4.Rx('uri','ip:192.168.2.1'); + % + % AD7124-4 Datasheet + + properties (Nontunable, Hidden) + channel_names = {'voltage0','voltage1','voltage2'... + 'voltage3','voltage4','voltage5','voltage6','voltage7'}; + end + + methods + %% Constructor + function obj = Rx(varargin) + obj = obj@adi.AD7124.Base('ad7124-4','ad7124-4',varargin{:}); + end + end + + end + + \ No newline at end of file diff --git a/+adi/+AD7124_8/Rx.m b/+adi/+AD7124_8/Rx.m new file mode 100644 index 0000000..84cf2ad --- /dev/null +++ b/+adi/+AD7124_8/Rx.m @@ -0,0 +1,27 @@ +classdef Rx < adi.common.Rx & adi.common.RxTx ... + & adi.AD7124.Base + % AD7124-8 Precision ADC Class + % adi.AD7124-8.Rx Receives data from the AD7124 ADC + % The adi.AD7124-8.Rx System object is a signal source that can receive + % data from the AD7124-8. + % + % rx = adi.AD7124_8.Rx; + % rx = adi.AD7124_8.Rx('uri','ip:192.168.2.1'); + % + % AD7124-8 Datasheet + + + properties (Nontunable, Hidden) + channel_names = {'voltage0','voltage1','voltage2','voltage3',... + 'voltage4','voltage5','voltage6','voltage7','voltage8','voltage9',... + 'voltage10','voltage11','voltage12','voltage13','voltage14','voltage15'}; + end + + methods + %% Constructor + function obj = Rx(varargin) + obj = obj@adi.AD7124.Base('ad7124-8','ad7124-8',varargin{:}); + end + end + +end \ No newline at end of file diff --git a/+adi/Contents.m b/+adi/Contents.m index 68baec2..c2d5536 100644 --- a/+adi/Contents.m +++ b/+adi/Contents.m @@ -32,3 +32,5 @@ % AD5781 - DAC % AD5790 - DAC % AD5791 - DAC +% AD7124_4 - ADC +% AD7124_8 - ADC diff --git a/CI/gen_doc/docs/_pages/index.md b/CI/gen_doc/docs/_pages/index.md index ae892ac..84fdabf 100644 --- a/CI/gen_doc/docs/_pages/index.md +++ b/CI/gen_doc/docs/_pages/index.md @@ -49,3 +49,5 @@ The following have device-specific implementations in MATLAB and Simulink. If a | AD4020 | Zedboard | Yes | No | ADI (2021b) | | AD4021 | Zedboard | Yes | No | ADI (2021b) | | AD4022 | Zedboard | Yes | No | ADI (2021b) | +| AD7124-4 | Zedboard | Yes | No | ADI (2021b) | +| AD7124-8 | Zedboard | Yes | No | ADI (2021b) | \ No newline at end of file diff --git a/CI/gen_doc/docs/gen_sysobj_doc.m b/CI/gen_doc/docs/gen_sysobj_doc.m index dac8620..09dae9b 100644 --- a/CI/gen_doc/docs/gen_sysobj_doc.m +++ b/CI/gen_doc/docs/gen_sysobj_doc.m @@ -35,6 +35,8 @@ , {'AD5781', {'Tx'}}... , {'AD5790', {'Tx'}}... , {'AD5791', {'Tx'}}... + , {'AD7124_4', {'Rx'}}... + , {'AD7124_8', {'Rx'}}... %{'QuadMxFE',{'Rx','Tx'}}... }; diff --git a/examples/ad7124_DataCapture.m b/examples/ad7124_DataCapture.m new file mode 100644 index 0000000..7a548d3 --- /dev/null +++ b/examples/ad7124_DataCapture.m @@ -0,0 +1,25 @@ +%% Script for capturing and displaying a continuous set of samples from a +%% connected AD7124-4 board + +% Instantiate the system object +rx = adi.AD7124_4.Rx(); +rx.uri = 'ip:analog.local'; + +% Samples per frame cannot exceed 500 if all 16 channels need to be captured on ad7124-8 +rx.SamplesPerFrame = 500; +rx.EnabledChannels = [1 2 3 4 5 6 7 8]; +rx.SampleRate = 19200; + +% 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