Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions +adi/+AD5710r/Tx.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
classdef Tx < adi.common.Tx & matlabshared.libiio.base & adi.common.Attribute
% AD5710r 16-bit Configurable IDAC/VDAC Class
% adi.AD5710r.Rx Transmits data to the AD5710r DAC
% The adi.AD5710r.Tx System object is a signal sink that can transmit
% data to the AD5710r.
%
% tx = adi.AD5710r.Tx;
% tx = adi.AD5710r.Tx('uri','ip:192.168.2.1');
%
% <a href="https://www.analog.com/en/products/ad5710r.html"</a>

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

properties
% ChMode Channel Mode
% COnfigure the channel mode of the device channels.
% Options are 'VMODE', 'IMODE'.
ChMode = 'VMODE'
end

properties (Nontunable)
SamplesPerFrame
end

properties (Nontunable, Hidden, Constant)
Type = 'Tx'
end

properties (Constant, Hidden)
ChModeSet = matlab.system.StringSet([ ...
"V_MODE", "I_MODE"]);
end

% Channel names
properties (Nontunable, Hidden)
channel_names = {'voltage0', 'voltage1', 'voltage2', 'voltage3', ...
'voltage4', 'voltage5', 'voltage6', 'voltage7'}
end

properties (Hidden, Nontunable, Access = protected)
isOutput = true
end

properties (Nontunable, Hidden)
Timeout = Inf
kernelBuffersCount = 1
dataTypeStr = 'int16'
phyDevName = 'ad5710r'
devName = 'ad5710r'
end

properties (Hidden, Constant)
ComplexData = false
end

methods

%% Constructor
function obj = Tx(varargin)
obj = obj@matlabshared.libiio.base(varargin{:});
obj.enableExplicitPolling = false;
obj.EnabledChannels = 1;
obj.uri = 'ip:analog.local';
obj.DataSource = 'DMA';
end

function set.SampleRate(obj, value)
% Set device sampling rate
obj.SampleRate = value;
if obj.ConnectedToDevice
obj.setDeviceAttributeRAW('sampling_frequency', num2str(value));
end
end

function set.ChMode(obj, value)
% Set channel mode
obj.ChMode = value;
if obj.ConnectedToDevice
for i=1:length(obj.channel_names)
if (ismember(i, obj.EnabledChannels))
obj.setAttributeRAW(obj.channel_names{i}, 'ch_mode', num2str(value), true);
end
end
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))
obj.setDeviceAttributeRAW('all_ch_operating_mode', 'normal_operation')
for i=1:length(obj.channel_names)
if (ismember(i, obj.EnabledChannels))
obj.setAttributeRAW(obj.channel_names{i}, 'ch_mode', num2str(obj.ChMode), true);
end
end
end

end
end
3 changes: 2 additions & 1 deletion +adi/Contents.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@
% <a href="matlab:help adi.AD7124_8 ">AD7124_8</a> - ADC
% <a href="matlab:help adi.AD4080 ">AD4080</a> - ADC
% <a href="matlab:help adi.AD5592r ">AD5592r</a> - ADC
% <a href="matlab:help adi.AD5593r ">AD5593r</a> - ADC
% <a href="matlab:help adi.AD5593r ">AD5593r</a> - ADC
% <a href="matlab:help adi.AD5710r ">AD5710r</a> - DAC
1 change: 1 addition & 0 deletions CI/gen_doc/docs/gen_sysobj_doc.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
, {'AD4080', {'Rx'}}...
, {'AD5592r', {'Rx'}}...
, {'AD5593r', {'Rx'}}...
, {'AD5710r', {'Rx'}}...
%{'QuadMxFE',{'Rx','Tx'}}...
};

Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ The following have device-specific implementations in MATLAB and Simulink. In ge
"AD4190", "SDP-K1", "Yes", "No", "ADI (2021b)"
"AD5592r", "SDP-K1", "Yes", "No", "ADI (2021b)"
"AD5593r", "SDP-K1", "Yes", "No", "ADI (2021b)"
"AD5710rr", "SDP-K1", "Yes", "No", "ADI (2021b)"
36 changes: 36 additions & 0 deletions examples/ad5710r_DataStreaming.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
%% Script for generating and transmitting a set of samples to a
%% connected AD5710r board

%% Generate data
samplerate = 50000;
amplitude = 2^15;
frequency = 250;
sine_wave = dsp.SineWave(amplitude, frequency);
sine_wave.ComplexOutput = false;
sine_wave.SamplesPerFrame = 200;
sine_wave.SampleRate = samplerate;
sine_wave.PhaseOffset = [0 pi/2 pi];
data = sine_wave();

% Add offset for unipolar DAC
data = data+2^15;
data = uint16(data);

%% Tx set up
% Instantiate the system object
tx = adi.AD5710r.Tx;
% Specify uri
tx.uri = 'serial:COM18,230400';
tx.EnableCyclicBuffers = true;
tx.SampleRate = samplerate;
tx.ChMode = 'VMODE';
tx.EnabledChannels = [1 2 3];

% Stream data
tx(data)

% Pause the execution to see the ouput for 5 seconds
pause(5);

% Delete the system object
tx.release();