-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add precision toolbox support for AD5760, AD5780, AD5781, AD5790, AD5791 DACs Signed-off-by: SGudla <Saikiran.Gudla@analog.com>
- Loading branch information
1 parent
366160e
commit 1c81beb
Showing
9 changed files
with
317 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
classdef Tx < adi.AD579x.Base & matlabshared.libiio.base & adi.common.Attribute | ||
% AD5760 Voltage output DAC Class | ||
% adi.AD5760.Tx Transmits data to the AD5760 DAC | ||
% The adi.AD5760.Tx System object is a signal sink that can transmit | ||
% data to the AD5760. | ||
% | ||
% tx = adi.AD5760.Tx; | ||
% tx = adi.AD5760.Tx('uri','ip:192.168.2.1'); | ||
% | ||
% <a href="https://www.analog.com/media/en/technical-documentation/data-sheets/ad5760.pdf">AD5760 Datasheet</a> | ||
|
||
methods | ||
|
||
%% Constructor | ||
function obj = Tx(varargin) | ||
obj = obj@adi.AD579x.Base('ad5760', 'ad5760', 'int16', varargin{:}); | ||
obj.enableExplicitPolling = false; | ||
obj.EnabledChannels = 1; | ||
obj.uri = 'ip:analog.local'; | ||
obj.DataSource = 'DMA'; | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
classdef Tx < adi.AD579x.Base & matlabshared.libiio.base & adi.common.Attribute | ||
% AD5780 Voltage output DAC Class | ||
% adi.AD5780.Tx Transmits data to the AD5780 DAC | ||
% The adi.AD5780.Tx System object is a signal sink that can transmit | ||
% data to the AD5780. | ||
% | ||
% tx = adi.AD5780.Tx; | ||
% tx = adi.AD5780.Tx('uri','ip:192.168.2.1'); | ||
% | ||
% <a href="https://www.analog.com/media/en/technical-documentation/data-sheets/ad5780.pdf">AD5780 Datasheet</a> | ||
|
||
methods | ||
|
||
%% Constructor | ||
function obj = Tx(varargin) | ||
obj = obj@adi.AD579x.Base('ad5780', 'ad5780', 'int32', varargin{:}); | ||
obj.enableExplicitPolling = false; | ||
obj.EnabledChannels = 1; | ||
obj.uri = 'ip:analog.local'; | ||
obj.DataSource = 'DMA'; | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
classdef Tx < adi.AD579x.Base & matlabshared.libiio.base & adi.common.Attribute | ||
% AD5781 Voltage output DAC Class | ||
% adi.AD5781.Tx Transmits data to the AD5781 DAC | ||
% The adi.AD5781.Tx System object is a signal sink that can transmit | ||
% data to the AD5781. | ||
% | ||
% tx = adi.AD5781.Tx; | ||
% tx = adi.AD5781.Tx('uri','ip:192.168.2.1'); | ||
% | ||
% <a href="https://www.analog.com/media/en/technical-documentation/data-sheets/ad5781.pdf">AD5781 Datasheet</a> | ||
|
||
methods | ||
|
||
%% Constructor | ||
function obj = Tx(varargin) | ||
obj = obj@adi.AD579x.Base('ad5781', 'ad5781', 'int32', varargin{:}); | ||
obj.enableExplicitPolling = false; | ||
obj.EnabledChannels = 1; | ||
obj.uri = 'ip:analog.local'; | ||
obj.DataSource = 'DMA'; | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
classdef Tx < adi.AD579x.Base & matlabshared.libiio.base & adi.common.Attribute | ||
% AD5790 Voltage output DAC Class | ||
% adi.AD5790.Tx Transmits data to the AD5790 DAC | ||
% The adi.AD5790.Tx System object is a signal sink that can transmit | ||
% data to the AD5790. | ||
% | ||
% tx = adi.AD5790.Tx; | ||
% tx = adi.AD5790.Tx('uri','ip:192.168.2.1'); | ||
% | ||
% <a href="https://www.analog.com/media/en/technical-documentation/data-sheets/ad5790.pdf">AD5790 Datasheet</a> | ||
|
||
methods | ||
|
||
%% Constructor | ||
function obj = Tx(varargin) | ||
obj = obj@adi.AD579x.Base('ad5790', 'ad5790', 'int32', varargin{:}); | ||
obj.enableExplicitPolling = false; | ||
obj.EnabledChannels = 1; | ||
obj.uri = 'ip:analog.local'; | ||
obj.DataSource = 'DMA'; | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
classdef Tx < adi.AD579x.Base & matlabshared.libiio.base & adi.common.Attribute | ||
% AD5791 Voltage output DAC Class | ||
% adi.AD5791.Tx Transmits data to the AD5791 DAC | ||
% The adi.AD5791.Tx System object is a signal sink that can transmit | ||
% data to the AD5791. | ||
% | ||
% tx = adi.AD5791.Tx; | ||
% tx = adi.AD5791.Tx('uri','ip:192.168.2.1'); | ||
% | ||
% <a href="https://www.analog.com/media/en/technical-documentation/data-sheets/ad5791.pdf">AD5791 Datasheet</a> | ||
|
||
methods | ||
|
||
%% Constructor | ||
function obj = Tx(varargin) | ||
obj = obj@adi.AD579x.Base('ad5791', 'ad5791', 'int32', varargin{:}); | ||
obj.enableExplicitPolling = false; | ||
obj.EnabledChannels = 1; | ||
obj.uri = 'ip:analog.local'; | ||
obj.DataSource = 'DMA'; | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
classdef Base < adi.common.Tx & adi.common.RxTx & ... | ||
matlabshared.libiio.base & adi.common.Attribute & ... | ||
adi.common.RegisterReadWrite & adi.common.Channel | ||
% AD579x is a family of Voltage output DAC | ||
% AD5790 is single channel 20bit DAC | ||
% AD5791 is single channel 20bit DAC | ||
% AD5780 is single channel 18bit DAC | ||
% AD5781 is single channel 18bit DAC | ||
% AD5760 is single channel 16bit 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 = '80000' | ||
|
||
% PowerDown Power Down | ||
% Set to true/false to power-up/power-down the device channels | ||
PowerDown (1,1) logical = false | ||
|
||
% Raw Channel Raw Value | ||
Raw = '65000' | ||
|
||
% CodeSelect Code Select | ||
% Set to 2s_complement/offset_binary | ||
CodeSelect = '2s_complement' | ||
end | ||
|
||
% Channel names | ||
properties (Nontunable, Hidden) | ||
channel_names = {'voltage0'} | ||
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) | ||
CodeSelectSet = matlab.system.StringSet([ ... | ||
"2s_complement", "binary_offset"]); | ||
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 | ||
|
||
function set.CodeSelect(obj, value) | ||
% Set code select option | ||
obj.CodeSelect = value; | ||
if obj.ConnectedToDevice | ||
id = 'voltage0'; | ||
obj.setDeviceAttributeRAW(id, 'code_select', num2str(value), true) | ||
end | ||
end | ||
|
||
function set.PowerDown(obj, value) | ||
% Set channel power down value | ||
obj.PowerDown = value; | ||
if obj.ConnectedToDevice | ||
id = 'voltage0'; | ||
obj.setAttributeRAW(id, 'powerdown', num2str(value), true) | ||
end | ||
end | ||
|
||
function set.Raw(obj, value) | ||
% Set channel raw value | ||
obj.Raw = value; | ||
if obj.ConnectedToDevice | ||
id = 'voltage0'; | ||
obj.setAttributeRAW(id, 'raw', num2str(value), true) | ||
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 | ||
|
||
id = 'voltage0'; | ||
|
||
obj.setDeviceAttributeRAW('sampling_frequency', num2str(obj.SampleRate)); | ||
obj.setDeviceAttributeRAW('code_select', num2str(obj.CodeSelect)); | ||
obj.setAttributeRAW(id, 'powerdown', num2str(obj.PowerDown), true); | ||
obj.setAttributeRAW(id, 'raw', num2str(obj.Raw), true); | ||
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 = 'AD579x DAC'; | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
%% Script for generating and transmitting a set of samples to a | ||
%% connected AD579x board | ||
|
||
%% Generate data | ||
samplerate = 50000; | ||
amplitude = 2^17-1; | ||
frequency = 250; | ||
sine_wave = dsp.SineWave(amplitude, frequency); | ||
sine_wave.ComplexOutput = false; | ||
sine_wave.SamplesPerFrame = 200; | ||
sine_wave.SampleRate = samplerate; | ||
data = sine_wave(); | ||
|
||
%% Tx set up | ||
% Instantiate the system object | ||
tx = adi.AD5780.Tx; | ||
% Specify uri | ||
tx.uri = 'serial:COM39,230400'; | ||
tx.EnableCyclicBuffers = true; | ||
tx.SampleRate = samplerate; | ||
% Power up the channel | ||
tx.PowerDown = 0; | ||
tx.CodeSelect = "2s_complement"; | ||
|
||
% Stream data | ||
tx(data) | ||
|
||
%Pause the execution to see the ouput for 5 seconds | ||
pause(5); | ||
|
||
% Delete the system object | ||
tx.release(); |