diff --git a/+adi/+AD5529r/Tx.m b/+adi/+AD5529r/Tx.m new file mode 100644 index 0000000..c06e277 --- /dev/null +++ b/+adi/+AD5529r/Tx.m @@ -0,0 +1,31 @@ +classdef Tx < adi.AD552xr.Base & matlabshared.libiio.base & adi.common.Attribute + % AD5529r Precision voltage output DAC Class + % adi.AD5529r.Tx Transmits data to the AD5529r DAC + % The adi.AD5529r.Tx System object is a signal sink that can transmit + % data to the AD5529r. + % + % `tx = adi.AD5529r.Tx;` + % `tx = adi.AD5529r.Tx('uri','ip:192.168.2.1');` + % + % `AD5529r Datasheet `_ + + % Channel names + properties (Nontunable, Hidden) + channel_names = {'voltage0', 'voltage1', 'voltage2', 'voltage3', ... + 'voltage4', 'voltage5', 'voltage6', 'voltage7', ... + 'voltage8', 'voltage9', 'voltage10', 'voltage11', ... + 'voltage12', 'voltage13', 'voltage14', 'voltage15'} + end + + methods + + %% Constructor + function obj = Tx(varargin) + obj = obj@adi.AD552xr.Base('ad5529r', 'ad5529r', 'uint16', varargin{:}); + obj.enableExplicitPolling = false; + obj.uri = 'ip:analog.local'; + obj.DataSource = 'DMA'; + end + + end +end \ No newline at end of file diff --git a/+adi/+AD552xr/Base.m b/+adi/+AD552xr/Base.m new file mode 100644 index 0000000..2425b25 --- /dev/null +++ b/+adi/+AD552xr/Base.m @@ -0,0 +1,98 @@ +classdef Base < adi.common.Tx & adi.common.RxTx & ... + matlabshared.libiio.base & adi.common.Attribute & ... + adi.common.RegisterReadWrite & adi.common.Channel + % AD552xr is a family of Voltage output DAC + % AD5529r is 16-channel 16-bit DAC + + properties(Nontunable) + % SamplesPerFrame Samples Per Frame + % Number of samples per frame, specified as an even positive + % integer. + SamplesPerFrame = 400 + end + + properties + % SampleRate Sample Rate + % Baseband sampling rate in Hz, specified as a scalar + % in samples per second. + SampleRate = '1000000' + end + + properties (Hidden, Nontunable, Access = protected) + isOutput = true + end + + properties (Nontunable, Hidden, Constant) + Type = 'Tx' + end + + properties (Nontunable, Hidden) + Timeout = Inf + kernelBuffersCount = 1 + dataTypeStr = 'uint16' + phyDevName + devName + end + + properties (Hidden, Constant) + ComplexData = false + end + + methods + + %% Constructor + function obj = Base(phydev, dev, dtype, varargin) + coder.allowpcode('plain'); + obj = obj@matlabshared.libiio.base(varargin{:}); + obj.phyDevName = phydev; + obj.devName = dev; + obj.dataTypeStr = dtype; + end + + function set.SampleRate(obj, value) + % Set device sampling rate + obj.SampleRate = value; + if obj.ConnectedToDevice + obj.setDeviceAttributeRAW('sampling_frequency', num2str(value)); + end + end + + % Destructor + function delete(obj) + delete@adi.common.RxTx(obj); + 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 + + %% External Dependency Methods + methods (Hidden, Static) + + function tf = isSupportedContext(bldCfg) + tf = matlabshared.libiio.ExternalDependency.isSupportedContext(bldCfg); + end + + function updateBuildInfo(buildInfo, bldCfg) + % Call the matlabshared.libiio.method first + matlabshared.libiio.ExternalDependency.updateBuildInfo(buildInfo, bldCfg); + end + + function bName = getDescriptiveName(~) + bName = 'AD552xr DAC'; + end + + end +end \ No newline at end of file diff --git a/+adi/Contents.m b/+adi/Contents.m index c7baa15..eb945b3 100644 --- a/+adi/Contents.m +++ b/+adi/Contents.m @@ -79,4 +79,5 @@ % AD5710r - DAC % AD5706r - DAC % AD4134 - ADC -% AD4134 - ADC \ No newline at end of file +% AD4134 - ADC +% AD5529r - DAC \ No newline at end of file diff --git a/CI/gen_doc/docs/gen_sysobj_doc.m b/CI/gen_doc/docs/gen_sysobj_doc.m index 510399d..4e4a9f0 100644 --- a/CI/gen_doc/docs/gen_sysobj_doc.m +++ b/CI/gen_doc/docs/gen_sysobj_doc.m @@ -56,6 +56,7 @@ , {'AD5706r', {'Tx'}}... , {'AD7134', {'Rx'}}... , {'AD4134', {'Rx'}}... + , {'AD5529r', {'Tx'}}... %{'QuadMxFE',{'Rx','Tx'}}... }; diff --git a/docs/source/index.rst b/docs/source/index.rst index 3abb3ec..5df671a 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -92,4 +92,5 @@ The following have device-specific implementations in MATLAB and Simulink. In ge "AD5710r", "SDP-K1", "Yes", "No", "ADI (2021b)" "AD5706r", "SDP-K1", "Yes", "No", "ADI (2021b)", "AD7134", "SDP-K1", "Yes", "No", "ADI (2021b)", - "AD4134", "SDP-K1", "Yes", "No", "ADI (2021b)" \ No newline at end of file + "AD4134", "SDP-K1", "Yes", "No", "ADI (2021b)" + "AD5529r", "SDP-K1", "Yes", "No", "ADI (2021b)" \ No newline at end of file diff --git a/examples/ad5529r_DataStreaming.m b/examples/ad5529r_DataStreaming.m new file mode 100644 index 0000000..215504a --- /dev/null +++ b/examples/ad5529r_DataStreaming.m @@ -0,0 +1,34 @@ +%% Script for generating and transmitting a set of samples to a +%% connected AD5529r board + +%% Generate data +samplerate = 1000; +amplitude = 2^15 - 1; +frequency = 5; +sine_wave = dsp.SineWave(amplitude, frequency); +sine_wave.ComplexOutput = false; +sine_wave.SamplesPerFrame = 200; +sine_wave.SampleRate = samplerate; +data = sine_wave(); + +%% Data offset for unipolar DAC +data = data + 2^15; +data = uint16(data); + +%% Tx set up +% Instantiate the system object +tx = adi.AD5529r.Tx; +% Specify uri +tx.uri = 'serial:COM21,230400'; +tx.EnableCyclicBuffers = true; +tx.SampleRate = samplerate; +tx.EnabledChannels = 1; + +% 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