From 58f8c2996929450395eb61ec8ef3a9ad4d93cc3f 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 + CI/gen_doc/docs/_pages/index.md | 1 + CI/gen_doc/docs/gen_sysobj_doc.m | 1 + examples/ad4170_DataCapture.m | 24 +++++++ 5 files changed, 147 insertions(+) create mode 100644 +adi/+AD4170/Rx.m 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/CI/gen_doc/docs/_pages/index.md b/CI/gen_doc/docs/_pages/index.md index 84fdabf..b71bfcc 100644 --- a/CI/gen_doc/docs/_pages/index.md +++ b/CI/gen_doc/docs/_pages/index.md @@ -49,5 +49,6 @@ 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) | +| AD4170 | 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 1b0a6ff..df64459 100644 --- a/CI/gen_doc/docs/gen_sysobj_doc.m +++ b/CI/gen_doc/docs/gen_sysobj_doc.m @@ -29,6 +29,7 @@ , {'AD4020', {'Rx'}}... , {'AD4021', {'Rx'}}... , {'AD4022', {'Rx'}}... + , {'AD4170', {'Rx'}}... , {'AD5760', {'Tx'}}... , {'AD5780', {'Tx'}}... , {'AD5781', {'Tx'}}... 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