diff --git a/+adi/+AD4052/Rx.m b/+adi/+AD4052/Rx.m new file mode 100644 index 0000000..d3990aa --- /dev/null +++ b/+adi/+AD4052/Rx.m @@ -0,0 +1,39 @@ +classdef Rx < adi.common.Rx & adi.common.RxTx ... + & adi.AD405x.Base + + % AD4052 Precision ADC Class + % + % adi.AD4052.Rx Receive data from the AD4052 ADC + % The adi.AD4052.Rx System object is a signal source that can receive + % data from the AD4052. + % + % `rx = adi.AD4052.Rx;` + % `rx = adi.AD4052.Rx('uri','serial:COM5,230400');` + % + % `AD4052 Datasheet `_ + + properties (Nontunable, Hidden, Constant) + Type = 'Rx' + end + + properties (Hidden) + Timeout = Inf + kernelBuffersCount = 1 + dataTypeStr = 'int32' + phyDevName = 'ad4052' + devName = 'ad4052' + end + + methods + %% Constructor + + function obj = Rx(Args) + arguments + Args.uri + end + coder.allowpcode('plain'); + obj = obj@adi.AD405x.Base('devName', 'ad4052', 'phyDevName', 'ad4052', 'uri', Args.uri); + end + + end +end \ No newline at end of file diff --git a/+adi/+AD405x/Base.m b/+adi/+AD405x/Base.m new file mode 100644 index 0000000..4801442 --- /dev/null +++ b/+adi/+AD405x/Base.m @@ -0,0 +1,118 @@ +classdef Base < adi.common.Rx & adi.common.RxTx & ... + matlabshared.libiio.base & adi.common.Attribute & ... + adi.common.RegisterReadWrite & adi.common.Channel + % AD405x is a family of Precision ADC + % AD4052 is single channel 16bit SAR ADC with max sampling frequency + % of 2MSPS + + properties (Nontunable) + % SampleRate Sample Rate + % Baseband sampling rate in Hz, specified as a scalar + % in samples per second. + SampleRate = '62500' + + % SamplesPerFrame Samples Per Frame + % Number of samples per frame, specified as an even positive + % integer. + SamplesPerFrame = 400 + + % BurstAveragingLength Burst Averaging Length + % Length of the averaging filter in 'burst averaging mode' + AvgFilterLength = 2 + + % BurstSampleRate Burst Sample Rate + % Rate of internal averaging in 'burst averaging mode' + BurstSampleRate = "2msps" + + end + + properties (Nontunable, Hidden) + channel_names = {'voltage0'} + end + + properties (Hidden, Nontunable, Access = protected) + isOutput = false + end + + properties (Hidden, Constant) + ComplexData = false + end + + methods + + %% Constructor + function obj = Base(Args) + arguments + Args.devName + Args.phyDevName + Args.uri + end + + obj = obj@matlabshared.libiio.base(); + obj.enableExplicitPolling = false; + obj.EnabledChannels = 1; + obj.BufferTypeConversionEnable = true; + + % Set device name, phyDevName, uri from input arguments + try + obj.devName = Args.devName; + obj.phyDevName = Args.phyDevName; + obj.uri = Args.uri; + catch + e = MException('MATLAB:notEnoughInputs',['Not enough input ' ... + 'arguments. Specify devName, phyDevName and uri']); + throw(e) + end + + % Determine datatype using trial and error + possibleDataTypeStr = {'int16', 'int32'}; + for k = 1:length(possibleDataTypeStr) + try + obj.dataTypeStr = possibleDataTypeStr{k}; + obj.setup(); + break; + catch + end + end + assert(obj.ConnectedToDevice == 1, "Connection could not be established with the specified device") + + release(obj) + + end + + function set.AvgFilterLength(obj, value) + % Setter method for the Averaging Filter Length attribute + obj.AvgFilterLength = value; + if obj.ConnectedToDevice + val = obj.setDeviceAttributeRAW('avg_filter_length', num2str(value)); + end + + end + + function set.BurstSampleRate(obj, value) + % Setter method for the Burst Sampple Rate attribute + obj.BurstSampleRate = value; + if obj.ConnectedToDevice + val = obj.setDeviceAttributeRAW('burst_sample_rate', num2str(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 doesn't support + % modification to nontunable variables at SetupImpl + + obj.setDeviceAttributeRAW('sampling_frequency', num2str(obj.SampleRate)); + + end + + end +end \ No newline at end of file diff --git a/+adi/+AD405x/Rx.m b/+adi/+AD405x/Rx.m new file mode 100644 index 0000000..e69de29 diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 5182341..147273e 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -15,4 +15,4 @@ If this PR contains a breaking change, list dependent PRs and try to push all re - [ ] I have build all projects affected by the changes in this PR - [ ] I have tested in hardware affected projects, at the relevant boards - [ ] I have signed off all commits from this PR -- [ ] I have updated the documentation by running CI/gen_doc/docs/gen_sysobj_doc.m script locally, if applies. \ No newline at end of file +- [ ] I have updated the documentation by running /docs/source/reference_api/gen_sysobj_doc.m script locally, if applies. \ No newline at end of file diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 409eadf..aa0f6d1 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -11,9 +11,9 @@ jobs: with: submodules: recursive - name: Set up Python 3.7 - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: - python-version: 3.7 + python-version: 3.x - name: Install dependencies run: | diff --git a/docs/source/index.rst b/docs/source/index.rst index fd7e3fc..206c33d 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -25,7 +25,7 @@ ADI maintains a set of tools to interface with ADI precision converters within M The following have device-specific implementations in MATLAB and Simulink. In general, if a device has an IIO driver, MATLAB support is possible, but a device-specific MATLAB or Simulink interface may not exist yet. .. csv-table:: Supported Parts - :header: "Evaluation Card", "FPGA Board", "Streaming Support", "Targeting", "Variants and Minimum Supported Release" + :header: "Evaluation Card", "Controller Board", "Streaming Support", "Targeting", "Variants and Minimum Supported Release" :widths: 30, 30, 30, 30, 30 "AD7380", "Zedboard", "Yes", "No", "ADI (2021b)" @@ -57,4 +57,5 @@ The following have device-specific implementations in MATLAB and Simulink. In ge "AD5791", "Zedboard", "Yes", "No", "ADI (2021b)" "AD7124-4", "Zedboard", "Yes", "No", "ADI (2021b)" "AD7124-8", "Zedboard", "Yes", "No", "ADI (2021b)" + "AD4052", "SDP-K1", "Yes", "No", "ADI (2021b)" diff --git a/docs/source/reference_api/AD4052_Rx.rst b/docs/source/reference_api/AD4052_Rx.rst new file mode 100644 index 0000000..cd71825 --- /dev/null +++ b/docs/source/reference_api/AD4052_Rx.rst @@ -0,0 +1,35 @@ +adi.AD4052.Rx +------------- + +**AD4052 Precision ADC Class** + +adi.AD4052.Rx Receive data from the AD4052 ADC +The adi.AD4052.Rx System object is a signal source that can receive +data from the AD4052. + +`rx = adi.AD4052.Rx;` +`rx = adi.AD4052.Rx('uri','serial:COM5,230400');` + +`AD4052 Datasheet `_ + +Class Properties +================ + +**BurstAveragingLength Burst Averaging Length** + Length of the averaging filter in 'burst averaging mode'Help for adi.AD4052.Rx/AvgFilterLength is inherited from superclass adi.AD405x.Base + +**BurstSampleRate Burst Sample Rate** + Rate of internal averaging in 'burst averaging mode'Help for adi.AD4052.Rx/BurstSampleRate is inherited from superclass adi.AD405x.Base + +**EnabledChannels Enabled Channels** + Indexs of channels to be enabled. Input should be a [1xN] vector with the indexes of channels to be enabled. Order is irrelevant + +**SampleRate Sample Rate** + Baseband sampling rate in Hz, specified as a scalar in samples per second.Help for adi.AD4052.Rx/SampleRate is inherited from superclass adi.AD405x.Base + +**SamplesPerFrame Samples Per Frame** + Number of samples per frame, specified as an even positive integer.Help for adi.AD4052.Rx/SamplesPerFrame is inherited from superclass adi.AD405x.Base + +**URI - remote host URI** + Hostname or IP address of remote libIIO deviceHelp for adi.AD4052.Rx/uri is inherited from superclass matlabshared.libiio.base + diff --git a/docs/source/reference_api/gen_sysobj_doc.m b/docs/source/reference_api/gen_sysobj_doc.m index a99f4a1..2481835 100644 --- a/docs/source/reference_api/gen_sysobj_doc.m +++ b/docs/source/reference_api/gen_sysobj_doc.m @@ -33,6 +33,7 @@ , {'AD5791', {'Tx'}}... , {'AD7124_4', {'Rx'}}... , {'AD7124_8', {'Rx'}}... + , {'AD4052', {'Rx'}}... }; all_devs = []; diff --git a/docs/source/requirements.txt b/docs/source/requirements.txt index 38e1f0c..eb0a0d6 100644 --- a/docs/source/requirements.txt +++ b/docs/source/requirements.txt @@ -1,3 +1,3 @@ -sphinx myst_parser +sphinx https://github.com/analogdevicesinc/doctools/releases/download/latest/adi-doctools.tar.gz \ No newline at end of file diff --git a/examples/ad4052_DataCapture.m b/examples/ad4052_DataCapture.m new file mode 100644 index 0000000..e73b0d3 --- /dev/null +++ b/examples/ad4052_DataCapture.m @@ -0,0 +1,23 @@ +%% Script for capturing and displaying a continuous set of samples from a +%% connected AD4052 board + +% Instantiate the system object +rx = adi.AD4052.Rx('uri', 'serial:COM13,230400'); +rx.SamplesPerFrame = 400; +rx.EnabledChannels = [1]; + +rx.SampleRate = 62500; % In sample mode, the sampling rate can be as high as 1MSPS + +% 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