Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adi: ad3530r: Add support for ad3530r #43

Merged
merged 1 commit into from
Jan 20, 2025
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
84 changes: 84 additions & 0 deletions +adi/+AD3530r/Tx.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
classdef Tx < adi.common.Tx & matlabshared.libiio.base & adi.common.Attribute
% AD3530r Precision voltage output DAC Class
% adi.AD3530r.Rx Transmits data to the AD3530r DAC
% The adi.AD3530r.Tx System object is a signal sink that can transmit
% data to the AD3530r.
%
% tx = adi.AD3530r.Tx;
% tx = adi.AD3530r.Tx('uri','ip:192.168.2.1');
%
% TODO: Add link to the data sheet

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

properties (Nontunable)
SamplesPerFrame
end

properties (Nontunable, Hidden, Constant)
Type = 'Tx'
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 = 'ad3530r'
devName = 'ad3530r'
end

properties (Hidden, Constant)
ComplexData = false
end

methods

%% Constructor
function obj = Tx(varargin)
obj = [email protected](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

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')
end

end
end
1 change: 1 addition & 0 deletions +adi/Contents.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
% <a href="matlab:help adi.AD7768 ">AD7768</a> - ADC
% <a href="matlab:help adi.AD7768_1 ">AD7768-1</a> - ADC
% <a href="matlab:help adi.AD2S1210 ">AD2S1210</a> - Resolver-to-Digital Converter
% <a href="matlab:help adi.AD3530r ">AD3530r</a> - DAC
% <a href="matlab:help adi.AD5760 ">AD5760</a> - DAC
% <a href="matlab:help adi.AD5780 ">AD5780</a> - DAC
% <a href="matlab:help adi.AD5781 ">AD5781</a> - DAC
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ 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)"
"AD3530r", "SDP-K1", "Yes", "No", "ADI (2021b)"
"AD4050", "SDP-K1", "Yes", "No", "ADI (2021b)"
"AD4052", "SDP-K1", "Yes", "No", "ADI (2021b)"
"AD4170", "SDP-K1", "Yes", "No", "ADI (2021b)"
Expand Down
35 changes: 35 additions & 0 deletions examples/ad3530r_DataStreaming.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
%% Script for generating and transmitting a set of samples to a
%% connected AD3530r 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.AD3530r.Tx;
% Specify uri
tx.uri = 'ip:analog.local';
tx.EnableCyclicBuffers = true;
tx.SampleRate = samplerate;
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();
Loading