From f997ba1e784bd296c7cbac97e5790daceaad0a53 Mon Sep 17 00:00:00 2001 From: Guillaume Ranquet Date: Thu, 21 Nov 2024 16:39:57 +0100 Subject: [PATCH] DRAFT: add AD7173 family * AD4111 12 channel (8 voltage/4 current) +1 temperature Signed-off-by: Guillaume Ranquet --- +adi/+AD4111/Rx.m | 29 +++++++++ +adi/+AD7173/Base.m | 155 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 +adi/+AD4111/Rx.m create mode 100644 +adi/+AD7173/Base.m diff --git a/+adi/+AD4111/Rx.m b/+adi/+AD4111/Rx.m new file mode 100644 index 0000000..718fe8b --- /dev/null +++ b/+adi/+AD4111/Rx.m @@ -0,0 +1,29 @@ +classdef Rx < adi.common.Rx & adi.common.RxTx ... + & adi.AD7193.Base + % AD4111 Precision ADC Class + % + % adi.AD4111.Rx Receives data from the AD4111 ADC + % The adi.AD4111.Rx System object is a signal source that can receive + % data from the AD4111. + % + % `rx = adi.AD4111.Rx;` + % `rx = adi.AD4111.Rx('uri','ip:192.168.2.1');` + % + % `AD4111 Datasheet `_ + + + properties (Nontunable, Hidden) + channel_names = {'voltage0','voltage1','voltage2','voltage3',... + 'voltage4','voltage5','voltage6','voltage7','current0', ... + 'current1','current2','current3','differential0', ... + 'differential1','differential2','differential3', 'temp'}; + end + + methods + %% Constructor + function obj = Rx(varargin) + obj = obj@adi.AD7193.Base('ad4111','ad4111',varargin{:}); + end + end + +end diff --git a/+adi/+AD7173/Base.m b/+adi/+AD7173/Base.m new file mode 100644 index 0000000..fec81fa --- /dev/null +++ b/+adi/+AD7173/Base.m @@ -0,0 +1,155 @@ +classdef Base < adi.common.Rx & adi.common.RxTx & ... + matlabshared.libiio.base & adi.common.Attribute & ... + adi.common.RegisterReadWrite & adi.common.Channel + % AD7193 Precision ADC Class + % AD4111 is a 12 channel ADC with temperature/voltage/differential/current inputs + + 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 + + %% 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 + + %% Check Current Scale + function rValue = get.CurrentScale(obj) + if obj.ConnectedToDevice + rValue = obj.getAttributeDouble('current0', 'scale', obj.isOutput); + else + rValue = NaN; + end + end + + %% Check Current Offset + function rValue = get.CurrentOffset(obj) + if obj.ConnectedToDevice + rValue = obj.getAttributeDouble('current0', 'offset', obj.isOutput); + else + rValue = NaN; + end + end + + %% Check Temperature Scale + function rValue = get.TemperatureScale(obj) + if obj.ConnectedToDevice + rValue = obj.getAttributeDouble('temp', 'scale', obj.isOutput); + else + rValue = NaN; + end + end + + %% Check Temperature Offset + function rValue = get.TemperatureOffset(obj) + if obj.ConnectedToDevice + rValue = obj.getAttributeDouble('temp', 'offset', obj.isOutput); + else + rValue = NaN; + 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 = 'AD7193 ADC'; + end + end + +end