From 71eab147c17c3fce180ce5d799e91b0bc1d15ae0 Mon Sep 17 00:00:00 2001 From: Apelete Seketeli Date: Tue, 29 Aug 2023 19:12:01 +0200 Subject: [PATCH] Add initial support and doc for ad2s1210 This adds initial support for AD2S1210 Resolver-to-Digital Converter. Signed-off-by: Apelete Seketeli --- +adi/+AD2S1210/Rx.m | 128 +++++++++++++++++++++++++++++++ +adi/Contents.m | 1 + CI/doc/SysObjsProps.m | 2 +- CI/doc/genhtml.m | 2 +- CI/gen_doc/docs/_pages/index.md | 1 + CI/gen_doc/docs/gen_sysobj_doc.m | 1 + examples/ad2s1210_DataCapture.m | 19 +++++ 7 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 +adi/+AD2S1210/Rx.m create mode 100644 examples/ad2s1210_DataCapture.m diff --git a/+adi/+AD2S1210/Rx.m b/+adi/+AD2S1210/Rx.m new file mode 100644 index 0000000..170de28 --- /dev/null +++ b/+adi/+AD2S1210/Rx.m @@ -0,0 +1,128 @@ +classdef Rx < adi.common.Rx & matlabshared.libiio.base & adi.common.Attribute + % AD2S1210 Resolver-to-Digital Converter Class + % adi.AD2S1210.Rx Receives data from the AD2S1210 Resolver + % The adi.AD2S1210.Rx System object is a signal source that can receive + % data from the AD2S1210. + % + % rx = adi.AD2S1210.Rx; + % rx = adi.AD2S1210.Rx('uri','192.168.2.1'); + % + % AD2S1210 Datasheet + + properties (Nontunable) + % SamplesPerFrame Samples Per Frame + % Number of samples per frame, specified as an even positive + % integer. + SamplesPerFrame = 4096 + end + + properties + % Angle + % Resolver angle in Degrees. + Angle = 0 + + % AngleScale Angular Scale + % Resolver angle scale. + AngleScale = 0 + + % Velocity Angular Velocity + % Resolver velocity in revolutions per second. + Velocity = 0 + + % VelocityScale Velocity Angular Scale + % Resolver velocityscale. + VelocityScale = 0 + + % ExcitationFrequency Excitation Frequency + % Resolver excitation frequency in Hertz. + ExcitationFrequency = 0 + end + + properties (Hidden) + % Number of frames or buffers of data to capture + FrameCount = 1 + end + + % Channel names + properties (Nontunable, Hidden, Constant) + channel_names = {'angl0', 'anglvel0'} + end + + % isOutput + properties (Hidden, Nontunable, Access = protected) + isOutput = false + end + + properties (Nontunable, Hidden) + Timeout = Inf + kernelBuffersCount = 2 + dataTypeStr = 'int16' + phyDevName = 'ad2s1210' + devName = 'ad2s1210' + end + + properties (Nontunable, Hidden, Constant) + Type = 'Rx' + end + + properties (Hidden, Constant) + ComplexData = false + end + + methods + %% Constructor + function obj = Rx(varargin) + obj = obj@matlabshared.libiio.base(varargin{:}); + obj.enableExplicitPolling = false; + obj.EnabledChannels = [1 2]; + obj.BufferTypeConversionEnable = true; + end + + %% Flush the buffer + function flush(obj) + flushBuffers(obj); + end + + %% Check Angle + function getAngle(obj) + if obj.ConnectedToDevice + obj.Angle = obj.getAttributeRAW('angl0', 'raw', obj.isOutput); + end + end + + %% Check Angular Scale + function getAngleScale(obj) + if obj.ConnectedToDevice + obj.AngleScale = obj.getAttributeDouble('angl0', 'scale', obj.isOutput); + end + end + + %% Check Velocity + function getVelocity(obj) + if obj.ConnectedToDevice + obj.Velocity = obj.getAttributeRAW('anglvel0','raw', obj.isOutput); + end + end + + %% Check Velocity Scale + function getVelocityScale(obj) + if obj.ConnectedToDevice + obj.VelocityScale = obj.getAttributeDouble('anglvel0', 'scale', obj.isOutput); + 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.ExcitationFrequency = obj.getDeviceAttributeLongLong('excitation_frequency'); + end + end +end \ No newline at end of file diff --git a/+adi/Contents.m b/+adi/Contents.m index 5823d37..10f6693 100644 --- a/+adi/Contents.m +++ b/+adi/Contents.m @@ -11,3 +11,4 @@ % AD4030-24 - ADC % AD4630-16 - ADC % AD4630-24 - ADC +% AD2S1210 - Resolver-to-Digital Converter diff --git a/CI/doc/SysObjsProps.m b/CI/doc/SysObjsProps.m index 32da009..3b08e76 100644 --- a/CI/doc/SysObjsProps.m +++ b/CI/doc/SysObjsProps.m @@ -6,4 +6,4 @@ % * AD4030 % * AD463x % * AD7768 - +% * AD2S1210 diff --git a/CI/doc/genhtml.m b/CI/doc/genhtml.m index 76c34bd..f9604a2 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','AD2S1210'}; 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..548b182 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) | +| AD2S1210 | 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..cffb45e 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'}}... + , {'AD2S1210', {'Rx'}}... %{'QuadMxFE',{'Rx','Tx'}}... }; diff --git a/examples/ad2s1210_DataCapture.m b/examples/ad2s1210_DataCapture.m new file mode 100644 index 0000000..222bc30 --- /dev/null +++ b/examples/ad2s1210_DataCapture.m @@ -0,0 +1,19 @@ +%% Script for capturing data from a connected AD2S1210 board + +% Instantiate the system object +rx = adi.AD2S1210.Rx('uri','ip:analog.local'); + +% Connect to device and initialize data +rx(); + +% Retrieve resolver angle and angular velocity +rx.getAngle(); +rx.getAngleScale(); +rx.getVelocity(); +rx.getVelocityScale(); + +% Print system object properties +rx + +% Delete the system object +release(rx);