diff --git a/+adi/+AD3530r/Tx.m b/+adi/+AD3530r/Tx.m index aa5ce699..703a9059 100644 --- a/+adi/+AD3530r/Tx.m +++ b/+adi/+AD3530r/Tx.m @@ -1,84 +1,27 @@ -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 +classdef Tx < adi.AD353xr.Base & matlabshared.libiio.base & adi.common.Attribute + /* AD3530r Precision voltage output DAC Class + * adi.AD3530r.Tx 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'); + * + * AD3530r Datasheet + */ methods %% Constructor function obj = Tx(varargin) - obj = obj@matlabshared.libiio.base(varargin{:}); + channels = {'voltage0', 'voltage1', 'voltage2', 'voltage3', ... + 'voltage4', 'voltage5', 'voltage6', 'voltage7'}; + obj = obj@adi.AD353xr.Base('ad3530r', 'ad3530r', 'int16', channels, 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 +end diff --git a/+adi/+AD3532r/Tx.m b/+adi/+AD3532r/Tx.m new file mode 100644 index 00000000..8063e11d --- /dev/null +++ b/+adi/+AD3532r/Tx.m @@ -0,0 +1,29 @@ +classdef Tx < adi.AD353xr.Base & matlabshared.libiio.base & adi.common.Attribute + /* AD3532r Precision voltage output DAC Class + * adi.AD3532r.Tx Transmits data to the AD3532r DAC + * The adi.AD3532r.Tx System object is a signal sink that can transmit + * data to the AD3532r. + * + * tx = adi.AD3532r.Tx; + * tx = adi.AD3532r.Tx('uri','ip:192.168.2.1'); + * + * AD3532r Datasheet + */ + + methods + + %% Constructor + function obj = Tx(varargin) + channels = {'voltage0', 'voltage1', 'voltage2', 'voltage3', ... + 'voltage4', 'voltage5', 'voltage6', 'voltage7', ... + 'voltage8', 'voltage9', 'voltage10', 'voltage11', ... + 'voltage12', 'voltage13', 'voltage14', 'voltage15'}; + obj = obj@adi.AD353xr.Base('ad3532r', 'ad3532r', 'int16', channels, varargin{:}); + obj.enableExplicitPolling = false; + obj.EnabledChannels = 1; + obj.uri = 'ip:analog.local'; + obj.DataSource = 'DMA'; + end + + end +end diff --git a/+adi/+AD353xr/Base.m b/+adi/+AD353xr/Base.m new file mode 100644 index 00000000..40ea2407 --- /dev/null +++ b/+adi/+AD353xr/Base.m @@ -0,0 +1,129 @@ +classdef Base < adi.common.Tx & adi.common.RxTx & ... + matlabshared.libiio.base & adi.common.Attribute & ... + adi.common.RegisterReadWrite & adi.common.Channel + /* AD353xr is a family of precision voltage output DACs + * AD3530r is 8-channel 16-bit DAC + * AD3532r 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 + /* SamplingFrequency Sampling Frequency + * Baseband sampling rate in Hz, specified as a scalar + * in samples per second. + */ + SamplingFrequency = '1000000' + + /* AllChOperatingMode All Channel Operating Mode + * Set operating mode for all channels + * Options: normal_operation, powerdown_1k, powerdown_100k, tristate + */ + AllChOperatingMode = 'normal_operation' + end + + /* Channel names */ + properties (Nontunable, Hidden) + channel_names + end + + properties (Hidden, Nontunable, Access = protected) + isOutput = true + end + + properties (Nontunable, Hidden, Constant) + Type = 'Tx' + end + + properties (Nontunable, Hidden) + Timeout = Inf + kernelBuffersCount = 1 + dataTypeStr + phyDevName + devName + end + + properties (Hidden, Constant) + ComplexData = false + end + + properties (Constant, Hidden) + AllChOperatingModeSet = matlab.system.StringSet([ ... + "normal_operation", "1kohm_to_gnd", "7.7kohm_to_gnd", "32kohm_to_gnd"]); + end + + methods + + %% Constructor + function obj = Base(phydev, dev, dtype, channels, varargin) + coder.allowpcode('plain'); + obj = obj@matlabshared.libiio.base(varargin{:}); + obj.phyDevName = phydev; + obj.devName = dev; + obj.dataTypeStr = dtype; + obj.channel_names = channels; + end + + function set.SamplingFrequency(obj, value) + /* Set device sampling frequency */ + obj.SamplingFrequency = value; + if obj.ConnectedToDevice + obj.setDeviceAttributeRAW('sampling_frequency', num2str(value)); + end + end + + function set.AllChOperatingMode(obj, value) + /* Set all channel operating mode */ + obj.AllChOperatingMode = value; + if obj.ConnectedToDevice + obj.setDeviceAttributeRAW('all_ch_operating_mode', 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.SamplingFrequency)); + obj.setDeviceAttributeRAW('all_ch_operating_mode', num2str(obj.AllChOperatingMode)); + 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 = 'AD353xr DAC'; + end + + end +end diff --git a/+adi/Contents.m b/+adi/Contents.m index eb945b37..306c11c5 100644 --- a/+adi/Contents.m +++ b/+adi/Contents.m @@ -80,4 +80,5 @@ % AD5706r - DAC % AD4134 - ADC % AD4134 - ADC -% AD5529r - DAC \ No newline at end of file +% AD5529r - DAC +% AD3532r - DAC \ No newline at end of file diff --git a/CI/gen_doc/docs/_pages/index.md b/CI/gen_doc/docs/_pages/index.md index 62f2f8ba..4a265fa8 100644 --- a/CI/gen_doc/docs/_pages/index.md +++ b/CI/gen_doc/docs/_pages/index.md @@ -68,4 +68,6 @@ The following have device-specific implementations in MATLAB and Simulink. If a | AD7124-4 | Zedboard | Yes | No | ADI (2021b) | | AD7124-8 | Zedboard | Yes | No | ADI (2021b) | | AD7134 | Zedboard | Yes | No | ADI (2021b) | -| AD4134 | Zedboard | Yes | No | ADI (2021b) | \ No newline at end of file +| AD4134 | Zedboard | Yes | No | ADI (2021b) | +| AD3530R | Zedboard | Yes | No | ADI (2021b) | +| AD3532R | Zedboard | Yes | No | ADI (2021b) | \ 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 4e4a9f0d..d1ce1f53 100644 --- a/CI/gen_doc/docs/gen_sysobj_doc.m +++ b/CI/gen_doc/docs/gen_sysobj_doc.m @@ -57,6 +57,8 @@ , {'AD7134', {'Rx'}}... , {'AD4134', {'Rx'}}... , {'AD5529r', {'Tx'}}... + , {'AD3530r', {'Tx'}}... + , {'AD3532r', {'Tx'}}... %{'QuadMxFE',{'Rx','Tx'}}... }; diff --git a/docs/source/index.rst b/docs/source/index.rst index 5df671a4..9e62c452 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -93,4 +93,5 @@ The following have device-specific implementations in MATLAB and Simulink. In ge "AD5706r", "SDP-K1", "Yes", "No", "ADI (2021b)", "AD7134", "SDP-K1", "Yes", "No", "ADI (2021b)", "AD4134", "SDP-K1", "Yes", "No", "ADI (2021b)" - "AD5529r", "SDP-K1", "Yes", "No", "ADI (2021b)" \ No newline at end of file + "AD5529r", "SDP-K1", "Yes", "No", "ADI (2021b)" + "AD3532r", "SDP-K1", "Yes", "No", "ADI (2021b)" \ No newline at end of file diff --git a/examples/ad3530r_DataStreaming.m b/examples/ad3530r_DataStreaming.m index d985a450..89b9c403 100644 --- a/examples/ad3530r_DataStreaming.m +++ b/examples/ad3530r_DataStreaming.m @@ -16,9 +16,18 @@ data = data+2^15; data = uint16(data); +% Select the device (uncomment the desired device) +device = 'AD3530R'; % 8-channel, 16-bit DAC +% device = 'AD3532R'; % 16-channel, 16-bit DAC + %% Tx set up % Instantiate the system object -tx = adi.AD3530r.Tx; +switch device + case 'AD3530R' + tx = adi.AD3530r.Tx(); + case 'AD3532R' + tx = adi.AD3532r.Tx(); +end % Specify uri tx.uri = 'ip:analog.local'; tx.EnableCyclicBuffers = true;