diff --git a/+adi/+AD3530r/Tx.m b/+adi/+AD3530r/Tx.m new file mode 100644 index 0000000..aa5ce69 --- /dev/null +++ b/+adi/+AD3530r/Tx.m @@ -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 = 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 + + 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 \ No newline at end of file diff --git a/+adi/Contents.m b/+adi/Contents.m index 5752456..7a8090c 100644 --- a/+adi/Contents.m +++ b/+adi/Contents.m @@ -30,6 +30,7 @@ % AD7768 - ADC % AD7768-1 - ADC % AD2S1210 - Resolver-to-Digital Converter +% AD3530r - DAC % AD5760 - DAC % AD5780 - DAC % AD5781 - DAC diff --git a/docs/source/index.rst b/docs/source/index.rst index d52021c..6528538 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -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)" diff --git a/examples/ad3530r_DataStreaming.m b/examples/ad3530r_DataStreaming.m new file mode 100644 index 0000000..d985a45 --- /dev/null +++ b/examples/ad3530r_DataStreaming.m @@ -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(); \ No newline at end of file