This is an old revision of the document!
There are two methods that can be used to connect to a DPG from MATLAB. The second, newer method is more robust and can access all the features of a DPG.
To begin, use the MATLAB command actxserver to connect to the DPG Software Suite.
For the DPG2, use:
>> h = actxserver('AnalogDevices.DPG2');
Most of the commands found in the Programming Reference can then be used with the DPG. For example, the following code opens a DPG2, downloads an interleaved vector, and begins playback of the vector:
>> h = actxserver('AnalogDevices.DPG2'); >> devices = h.AttachedDevices; >> devices{1}.DownloadConfiguration('LVDS (DCO)') >> devices{1}.DownloadInterleavedVectorDouble2D(vector,2,true); >> devices{1}.PlayMode=0 >> dpg2devices{1}.StartPlayback;
Because of the above restrictions with MATLAB, only the following DownloadVector commands are valid:
int32 | double | |
---|---|---|
Independent Vectors | DownloadDataVectorInt2D | DownloadDataVectorDouble2D |
Interleaved Vectors | DownloadInterleavedVectorInt2D | DownloadInterleavedVectorDouble2D |
In versions of MATLAB starting with R2009a, a direct connection to the DPG libraries is now possible. To begin, follow these steps:
>> NET.addAssembly('AnalogDevices.DPG.Interfaces'); >> hpf = AnalogDevices.DPG.PluginFinder.HardwarePluginFinder; >> hardwarePlugins = hpf.FindPlugins;
The array hardwarePlugins now contains a list of all the hardware interfaces that you currently can connect to. The number of available interfaces will vary depending on what you have installed. For example, you may have the DPG2 Interface, and a DPGI/O Interface, and possibly others. These interfaces are software interfaces. They represent the different types of hardware you could connect to, if that hardware was connected to your computer. The interfaces will show up regardless of if the hardware is connected or not. To get a description of each interface, the FriendlyName function can be called:
>> hardwarePlugins(1).FriendlyName ans = DPG2 Interface
This example will connect to a DPG2:
>> dpg2_interface = hardwarePlugins(1);
Now you can query the interface to see if any hardware of this type (in this case, a DPG2) is actually connected:
>> devices = dpg2_interface.AttachedDevices;
The devices array now contains a reference to each physically attached pattern generator of the specified type (DPG2 in this example). We'll create a reference to the first device, to make the code afterwards cleaner:
>> dpg2 = devices(1);
The FPGA in the pattern generator can be setup for several different interface standards. Select the appropriate configuration for the evaluation board connected to the pattern generator, and configure the FPGA. In this example, an LVDS interface will be used:
>> dpg2.DownloadConfiguration('LVDS (DCO)')
The first step in loading a vector into a pattern generator is to convert the MATLAB array into a format recognizable by the DPG software:
>> dpg_array = NET.convertArray(original_array, 'System.Int32');
The new array can now be loaded into the pattern generator. There are numerous ways to load in the data (see the Programming Reference for the complete list). This example will load for a dual-port single DAC, such as the AD9739:
>> dpg2.DownloadInterleavedVectorInt1D(dpg_array,2,true);
Once the vector is loaded, the Play Mode should be set to Loop, followed by the command to begin vector playback:
>> dpg2.PlayMode = AnalogDevices.DPG.Interfaces.HardwareDeviceTypes.PlayModeE.Loop; >> dpg2.StartPlayback;
How the data is formatted in original_array will vary depending on what DAC the data is being sent to. The data itself is not interpreted by the download functions (bits in = bits out). Therefore, the data format (binary, two's compliment, etc) must match what the DAC is expecting.
The DPG has two LVDS buses, which become interleaved into one vector. The data must be inserted into the data array properly for it to be de-interleaved by the DPG.
For example, on an AD9739 (dual-port, single DAC), the data would look like this:
Sample 1 |
Sample 2 |
Sample 3 |
Sample 4 |
etc. |
On the AD9122 (dual DAC, single port), the data would look like:
I Sample 1 |
0 |
Q Sample 1 |
0 |
I Sample 2 |
0 |
Q Sample 2 |
0 |
% The first section is setting up the pattern generator NET.addAssembly('AnalogDevices.DPG.Interfaces'); hpf = AnalogDevices.DPG.PluginFinder.HardwarePluginFinder; hardwarePlugins = hpf.FindPlugins; for i=1:hardwarePlugins.Length if(strcmp(char(hardwarePlugins(i).FriendlyName),'DPG2 Interface') == true) dpg2_interface = hardwarePlugins(i); end end devices = dpg2_interface.AttachedDevices; dpg2 = devices(1); dpg2.DownloadConfiguration('LVDS (DCO)'); % This section would be repeated for loading in different vectors dpg_array = NET.convertArray(original_array, 'System.Int32'); dpg2.DownloadInterleavedVectorInt1D(dpg_array,2,true); dpg2.PlayMode = AnalogDevices.DPG.Interfaces.HardwareDeviceTypes.PlayModeE.Loop; dpg2.StartPlayback;
Sometimes it is advantageous to create a data file in MATLAB, save it to a file, and then download it with DPGDownloader. This example creates a Data File for use with DPGDownloader.
% Signed Example resolution = 16; desired = 1000000; % Output frequency in Hz FDAC = 10000000; % Data clock frequency in Hz samples = 65536; % Must be a multiple of 256 cycles=round(desired*samples/FDAC); actual=cycles*FDAC/samples x=[0:(2*cycles*pi/samples):2*cycles*pi-(2*cycles*pi/samples)]; Idata = round((2^(resolution-1)-1)*cos(x))'; % I data is a cosine wave Qdata = round((2^(resolution-1)-1)*sin(x))'; % Q data is a sine wave dlmwrite('QVector.txt', Qdata) dlmwrite('IVector.txt', Idata)