Skip to content

Commit

Permalink
try setting sample rate in the device class
Browse files Browse the repository at this point in the history
Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
  • Loading branch information
threexc committed Feb 5, 2025
1 parent 15055e3 commit bb133b5
Show file tree
Hide file tree
Showing 17 changed files with 1,002 additions and 0 deletions.
8 changes: 8 additions & 0 deletions +adi/+AD4000/Rx.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
obj.EnabledChannels = 1;
obj.BufferTypeConversionEnable = true;
end

% Set SampleRate
function set.SampleRate(obj, value)
obj.SampleRate = value;
if obj.ConnectedToDevice
obj.setAttributeRAW('voltage0', 'sampling_frequency', num2str(value), false);
end
end
end
end
8 changes: 8 additions & 0 deletions +adi/+AD4001/Rx.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
obj.EnabledChannels = 1;
obj.BufferTypeConversionEnable = true;
end

% Set SampleRate
function set.SampleRate(obj, value)
obj.SampleRate = value;
if obj.ConnectedToDevice
obj.setAttributeRAW('voltage0-voltage1', 'sampling_frequency', num2str(value), false);
end
end
end
end
8 changes: 8 additions & 0 deletions +adi/+AD4002/Rx.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
obj.EnabledChannels = 1;
obj.BufferTypeConversionEnable = true;
end

% Set SampleRate
function set.SampleRate(obj, value)
obj.SampleRate = value;
if obj.ConnectedToDevice
obj.setAttributeRAW('voltage0', 'sampling_frequency', num2str(value), false);
end
end
end
end
8 changes: 8 additions & 0 deletions +adi/+AD4003/Rx.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
obj.EnabledChannels = 1;
obj.BufferTypeConversionEnable = true;
end

% Set SampleRate
function set.SampleRate(obj, value)
obj.SampleRate = value;
if obj.ConnectedToDevice
obj.setAttributeRAW('voltage0-voltage1', 'sampling_frequency', num2str(value), false);
end
end
end
end
8 changes: 8 additions & 0 deletions +adi/+AD4004/Rx.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
obj.EnabledChannels = 1;
obj.BufferTypeConversionEnable = true;
end

% Set SampleRate
function set.SampleRate(obj, value)
obj.SampleRate = value;
if obj.ConnectedToDevice
obj.setAttributeRAW('voltage0', 'sampling_frequency', num2str(value), false);
end
end
end
end
8 changes: 8 additions & 0 deletions +adi/+AD4005/Rx.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
obj.EnabledChannels = 1;
obj.BufferTypeConversionEnable = true;
end

% Set SampleRate
function set.SampleRate(obj, value)
obj.SampleRate = value;
if obj.ConnectedToDevice
obj.setAttributeRAW('voltage0-voltage1', 'sampling_frequency', num2str(value), false);
end
end
end
end
8 changes: 8 additions & 0 deletions +adi/+AD4006/Rx.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
obj.EnabledChannels = 1;
obj.BufferTypeConversionEnable = true;
end

% Set SampleRate
function set.SampleRate(obj, value)
obj.SampleRate = value;
if obj.ConnectedToDevice
obj.setAttributeRAW('voltage0', 'sampling_frequency', num2str(value), false);
end
end
end
end
8 changes: 8 additions & 0 deletions +adi/+AD4007/Rx.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
obj.EnabledChannels = 1;
obj.BufferTypeConversionEnable = true;
end

% Set SampleRate
function set.SampleRate(obj, value)
obj.SampleRate = value;
if obj.ConnectedToDevice
obj.setAttributeRAW('voltage0-voltage1', 'sampling_frequency', num2str(value), false);
end
end
end
end
8 changes: 8 additions & 0 deletions +adi/+AD4008/Rx.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
obj.EnabledChannels = 1;
obj.BufferTypeConversionEnable = true;
end

% Set SampleRate
function set.SampleRate(obj, value)
obj.SampleRate = value;
if obj.ConnectedToDevice
obj.setAttributeRAW('voltage0', 'sampling_frequency', num2str(value), false);
end
end
end
end
5 changes: 5 additions & 0 deletions +adi/+AD400x/Base.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
% Number of samples per frame, specified as an even positive
% integer.
SamplesPerFrame = 4096

% SampleRate Sample Rate
% Baseband sampling rate in Hz, specified as a scalar
% in samples per second.
SampleRate = '1000000'
end

properties (Dependent)
Expand Down
8 changes: 8 additions & 0 deletions +adi/+AD4010/Rx.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
obj.EnabledChannels = 1;
obj.BufferTypeConversionEnable = true;
end

% Set SampleRate
function set.SampleRate(obj, value)
obj.SampleRate = value;
if obj.ConnectedToDevice
obj.setAttributeRAW('voltage0', 'sampling_frequency', num2str(value), false);
end
end
end
end
8 changes: 8 additions & 0 deletions +adi/+AD4011/Rx.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
obj.EnabledChannels = 1;
obj.BufferTypeConversionEnable = true;
end

% Set SampleRate
function set.SampleRate(obj, value)
obj.SampleRate = value;
if obj.ConnectedToDevice
obj.setAttributeRAW('voltage0-voltage1', 'sampling_frequency', num2str(value), false);
end
end
end
end
120 changes: 120 additions & 0 deletions +adi/+AD4020/0001-AD4020-try-isolating.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
From 849166893ffa1841a03dee595a5ac9a4b6493b4b Mon Sep 17 00:00:00 2001
From: Trevor Gamblin <tgamblin@baylibre.com>
Date: Tue, 4 Feb 2025 17:11:04 -0500
Subject: [PATCH] AD4020: try isolating

Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
---
+adi/+AD4020/Rx.m | 88 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 86 insertions(+), 2 deletions(-)

diff --git a/+adi/+AD4020/Rx.m b/+adi/+AD4020/Rx.m
index b5fd904..7468f15 100644
--- a/+adi/+AD4020/Rx.m
+++ b/+adi/+AD4020/Rx.m
@@ -1,4 +1,4 @@
-classdef Rx < adi.AD400x.Base & matlabshared.libiio.base & adi.common.Attribute
+classdef Rx < matlabshared.libiio.base & adi.common.Attribute
% AD4020 Precision ADC Class
%
% adi.AD4020.Rx Receives data from the AD4020 ADC
@@ -10,11 +10,95 @@ classdef Rx < adi.AD400x.Base & matlabshared.libiio.base & adi.common.Attribute
%
% `AD4020 Datasheet <https://www.analog.com/media/en/technical-documentation/data-sheets/ad4020-4021-4022.pdf>`_

- % Channel names
+ properties (Nontunable)
+ % SamplesPerFrame Samples Per Frame
+ % Number of samples per frame, specified as an even positive
+ % integer.
+ SamplesPerFrame = 4096
+
+ % SampleRate Sample Rate
+ % Baseband sampling rate in Hz, specified as a scalar
+ % in samples per second.
+ SampleRate = '500000'
+ end
+
+ properties (Dependent)
+ % VoltageScale Voltage Scale
+ % ADC Voltage scale.
+ VoltageScale
+
+ % VoltageOffset Voltage Offset
+ % ADC Voltage offset.
+ VoltageOffset
+ end
+
+ % isOutput
+ properties (Hidden, Nontunable, Access = protected)
+ isOutput = false
+ end
+
+ properties (Nontunable, Hidden)
+ Timeout = Inf
+ kernelBuffersCount = 1
+ dataTypeStr
+ phyDevName
+ devName
+ end
+
properties (Nontunable, Hidden, Constant)
+ Type = 'Rx'
channel_names = {'voltage0-voltage1'}
end

+ properties (Hidden, Constant)
+ ComplexData = false
+ end
+
+ methods
+ %% Constructor
+ function obj = Base(phydev, dev, dtype, varargin)
+ obj = obj@matlabshared.libiio.base(varargin{:});
+ obj.phyDevName = phydev;
+ obj.devName = dev;
+ obj.dataTypeStr = dtype;
+ end
+
+ %% Set SampleRate
+ function set.SampleRate(obj, value)
+ % Set device sampling rate
+ obj.SampleRate = value;
+ if obj.ConnectedToDevice
+ obj.setAttributeRAW('voltage0-voltage1', 'sampling_frequency', num2str(value), false);
+ end
+ end
+
+ %% Check Voltage Scale
+ function rValue = get.VoltageScale(obj)
+ if obj.ConnectedToDevice
+ rValue = obj.getAttributeDouble('voltage0-voltage1', 'scale', obj.isOutput);
+ else
+ rValue = NaN;
+ end
+ end
+
+ %% Check Voltage Offset
+ function rValue = get.VoltageOffset(obj)
+ if obj.ConnectedToDevice
+ rValue = obj.getAttributeDouble('voltage0-voltage1', 'offset', obj.isOutput);
+ else
+ rValue = NaN;
+ end
+ end
+ end
+
+ %% API Functions
+ methods (Hidden, Access = protected)
+ function setupInit(obj)
+ obj.setAttributeRAW('voltage0-voltage1', 'sampling_frequency', num2str(obj.SampleRate), false);
+ end
+ end
+end
+
methods
%% Constructor
function obj = Rx(varargin)
--
2.39.5

Loading

0 comments on commit bb133b5

Please sign in to comment.