Test and Measurement Forum

AWG + sampling using PS5442B

Post your MATLAB discussions here

AWG + sampling using PS5442B

Postby GrahamP » Sat Sep 24, 2016 1:38 pm

Hello,

I am trying to produce an arbitrary waveform (frequency around 2.5MHz) from the AWG and then read it directly back into channel A, and then plot the original vs recorded signals.

I have attempted to code this in Matlab (see below), but am having trouble with the following.

(1) Triggering - I have to output at least 1e6 shots for it to record anything, and then it just starts sampling at a random point. Otherwise, if I use one shot, it just hangs with "runBlock: Waiting for device to become ready..."
I want only a single shot, and the recording should begin as the AWG starts producing the waveform and ends when the AWG stops. I don't want it to trigger at a particular voltage level.

(2) To set the DAC sample rate to 10MHz, do I use the following commands?
Code: Select all
set(ps5000aDeviceObj, 'startFrequency', 10e6); 
set(ps5000aDeviceObj, 'stopFrequency', 10e6);


(3) After running the code below, I get the attached figure, but there is a mismatch between time scales. I think it has to do with the number of post-trigger samples. How do I correct this? I'm expecting a period of 400ns.

The code below uses an arbitrary sine wave. In reality, I will be using a non-stationary signal.

Many thanks

Code: Select all
%% LOAD CONFIGURATION INFORMATION

PS5000aConfig;

%% DEVICE CONNECTION
% Create a device object.
ps5000aDeviceObj = icdevice('picotech_ps5000a_generic.mdd');
% Connect device object to hardware.
connect(ps5000aDeviceObj);

%% SET CHANNELS

% Default driver settings used - use ps5000aSetChannel to turn channels on
% or off and set voltage ranges, coupling, as well as analogue offset.

%% SET DEVICE RESOLUTION

% Max. resolution with 2 channels enabled is 15 bits.
[status, resolution] = invoke(ps5000aDeviceObj, 'ps5000aSetDeviceResolution', 14);

%% SET SIMPLE TRIGGER
% Channel     : 0 (PS5000A_CHANNEL_A)
% Threshold   : 1 (mV)
% Direction   : 2 (Rising)
% Delay       : 0
% Auto trigger: 0 (wait indefinitely)

[status] = invoke(ps5000aDeviceObj, 'setSimpleTrigger', 0, 0, 2, 0, 0);

%% GET TIMEBASE
% Driver default timebase index used - use ps5000aGetTimebase or
% ps5000aGetTimebase2 to query the driver as to suitability of using a
% particular timebase index then set the 'timebase' property if required.
% timebase     : 14 == 10MHz (time interval 100ns)
% segment index: 0

[status, timeIntervalNanoSeconds, maxSamples] = invoke(ps5000aDeviceObj, 'ps5000aGetTimebase', 14.5, 0);

%% SET BLOCK PARAMETERS
Nsamples = 1024;
samplingRate = 1/(double(timeIntervalNanoSeconds)*1e-9);
% Set pre-trigger samples.
set(ps5000aDeviceObj, 'numPreTriggerSamples', 0);
set(ps5000aDeviceObj, 'numPostTriggerSamples', Nsamples);  %% Samples to record after trigger

%% Start the AWG
% Configure property value(s).
% awgBufferSize = get(ps5000aDeviceObj, 'awgBufferSize');
f = 2.5e6;
t = linspace(0,1/f,Nsamples);
y = normalise(sin(2*pi*f*t));
% load('RF_test_sig.mat');
% y = normalise(RF_test_sig);

% Set parameters
% Set the frequency in the Instrument Driver
set(ps5000aDeviceObj, 'startFrequency', 4*f); 
set(ps5000aDeviceObj, 'stopFrequency', 4*f);

offsetMv = 0;
pkToPkMv = 2000;
increment = 0; % Hz
dwellTime = 1; % seconds
sweepType = ps5000aEnuminfo.enPS5000ASweepType.PS5000A_UP;
operation = PicoConstants.FALSE;
sweepType = ps5000aEnuminfo.enPS5000AIndexMode.PS5000A_SINGLE;
shots = 1000000;
sweeps = 0;
triggerType = ps5000aEnuminfo.enPS5000ASigGenTrigType.PS5000A_SIGGEN_RISING;
triggerSource = ps5000aEnuminfo.enPS5000ASigGenTrigSource.PS5000A_SIGGEN_SOFT_TRIG;
extInThresholdMv = 0;

% Call function
invoke(ps5000aDeviceObj, 'setSigGenArbitrary', offsetMv, pkToPkMv, increment, dwellTime, ...
    y, sweepType, operation, sweepType, shots, sweeps, triggerType, triggerSource, extInThresholdMv);

% Software trigger the AWG to output a single cycle of the waveform
invoke(ps5000aDeviceObj, 'ps5000aSigGenSoftwareControl', 1);

%% CAPTURE DATA
% Capture a block of data:
% segment index: 0

[status] = invoke(ps5000aDeviceObj, 'runBlock', 0);

% Retrieve data values:
%
% start index       : 0
% segment index     : 0
% downsampling ratio: 1
% downsampling mode : 0 (PS5000A_RATIO_MODE_NONE)

[chA, chB, chC, chD, numSamples, overflow] = invoke(ps5000aDeviceObj, 'getBlockData', 0, 0, 1, 0);


% Stop the device
[status] = invoke(ps5000aDeviceObj, 'ps5000aStop');
invoke(ps5000aDeviceObj, 'setSigGenOff');

%% PROCESS DATA
% Plot data values.
figure;

% Calculate time (nanoseconds) and convert to milliseconds
% Use timeIntervalNanoSeconds output from ps5000aGetTimebase or
% ps5000aGetTimebase2 or calculate from Programmer's Guide.

timeNs = double(timeIntervalNanoSeconds) * double([0:numSamples - 1]);
timeus = timeNs / 1e3;

% Channel A
axisHandleChA = subplot(2,1,1);
plot(timeus, normalise(chA), 'b');
title('Channel A');
xlabel(axisHandleChA, 'Time (us)');
ylabel(axisHandleChA, 'Voltage (mV)');

% original Signal
axisHandleOrig = subplot(2,1,2);
plot(t.*1e6, y, 'r');
title('Original Signal');
xlabel(axisHandleOrig, 'Time (us)');
ylabel(axisHandleOrig, 'Voltage (mV)');

%% DEVICE DISCONNECTION
samplingRate
% Disconnect device object from hardware.
disconnect(ps5000aDeviceObj);
Attachments
Graphs.pdf
(28.05 KiB) Downloaded 20 times
GrahamP
Newbie
 
Posts: 0
Joined: Wed Jul 06, 2016 11:49 am

Re: AWG + sampling using PS5442B

Postby Hitesh » Mon Sep 26, 2016 4:49 pm

Hi GrahamP,

The signal generator can only be configured to output shots of a waveform when a trigger is set on it.

You will need to call the setSigGenArbitrary() function and configure it for a trigger. You can specify the external trigger input if you have a signal that you can use to trigger the device or use the ps5000aSigGenSoftwareControl() to trigger the signal generator output.

If you choose the latter option, you will need to use the ps5000aRunBlock() function, call the ps5000aSigGenSoftwareControl() and poll the ps5000aIsReady() function until the device is ready.

To change the sampling interval, you need to set the timebase property of the Instrument Driver - please refer to the Timebases section in the Programmer's Guide.

Use the set() function to do this e.g:

Code: Select all
set(ps5000aDeviceObj, 'timebase', 4);

Once you have changed the sampling interval based on the appropriate formula in the Timebases section, you can then set the number of samples to collect. It might be an idea to set a trigger on the input channel as well so that it will collect the correct portion of the waveform.

Hope this helps,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2063
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: AWG + sampling using PS5442B

Postby GrahamP » Tue Sep 27, 2016 4:02 pm

Hi Hitesh,

Thanks for your reply. I am using a software trigger. I'm still having trouble with the code (attached below). I tried to use runblock --> ps5000aSigGenSoftwareControl --> poll ps5000aIsReady. However, the code hangs on
Code: Select all
[status] = invoke(ps5000aDeviceObj, 'runBlock', 0);
with "runBlock: Waiting for device to become ready..."

Any ideas?

Thanks,

Graham

Code: Select all
%% LOAD CONFIGURATION INFORMATION

PS5000aConfig;

%% DEVICE CONNECTION
% Create a device object.
ps5000aDeviceObj = icdevice('picotech_ps5000a_generic.mdd');
% Connect device object to hardware.
connect(ps5000aDeviceObj);

%% SET CHANNELS

% Default driver settings used - use ps5000aSetChannel to turn channels on
% or off and set voltage ranges, coupling, as well as analogue offset.

%% SET DEVICE RESOLUTION

% Max. resolution with 2 channels enabled is 15 bits.
[status, resolution] = invoke(ps5000aDeviceObj, 'ps5000aSetDeviceResolution', 14);

%% SET SIMPLE TRIGGER
% Enable      : 0 Disable - any non-zero value will trigger
% Channel     : 0 (PS5000A_CHANNEL_A)
% Threshold   : 0 (mV)
% Direction   : 2 (Rising)
% Delay       : 0
% Auto trigger: 0 (wait indefinitely)

[status] = invoke(ps5000aDeviceObj, 'setSimpleTrigger', 0, 0, 0, 2, 0, 0);

%% GET TIMEBASE
% Driver default timebase index used - use ps5000aGetTimebase or
% ps5000aGetTimebase2 to query the driver as to suitability of using a
% particular timebase index then set the 'timebase' property if required.
% timebase     : 14 == 10MHz (time interval 100ns)
% segment index: 0

[status, timeIntervalNanoSeconds, maxSamples] = invoke(ps5000aDeviceObj, 'ps5000aGetTimebase', 14.5, 0);

%% SET BLOCK PARAMETERS
Nsamples = 1024;
samplingRate = 1/(double(timeIntervalNanoSeconds)*1e-9);
% Set pre-trigger samples.
set(ps5000aDeviceObj, 'numPreTriggerSamples', 0);
set(ps5000aDeviceObj, 'numPostTriggerSamples', Nsamples);  %% Samples to record after trigger

%% Start the AWG
% Configure property value(s).
% awgBufferSize = get(ps5000aDeviceObj, 'awgBufferSize');
f = 2.5e6;
t = linspace(0,1/f,Nsamples);
y = normalise(sin(2*pi*f*t));
% load('RF_test_sig.mat');
% y = normalise(RF_test_sig);

% % Set parameters
% % Set the frequency in the Instrument Driver
% set(ps5000aDeviceObj, 'startFrequency', 4*f); 
% set(ps5000aDeviceObj, 'stopFrequency', 4*f);

offsetMv = 0;
pkToPkMv = 2000;
increment = 0; % Hz
dwellTime = 1; % seconds
sweepType = ps5000aEnuminfo.enPS5000ASweepType.PS5000A_UP;
operation = PicoConstants.FALSE;
sweepType = ps5000aEnuminfo.enPS5000AIndexMode.PS5000A_SINGLE;
shots = 1;
sweeps = 0;
triggerType = ps5000aEnuminfo.enPS5000ASigGenTrigType.PS5000A_SIGGEN_RISING;
triggerSource = ps5000aEnuminfo.enPS5000ASigGenTrigSource.PS5000A_SIGGEN_SOFT_TRIG;
extInThresholdMv = 0;

% Call function
invoke(ps5000aDeviceObj, 'setSigGenArbitrary', offsetMv, pkToPkMv, increment, dwellTime, ...
    y, sweepType, operation, sweepType, shots, sweeps, triggerType, triggerSource, extInThresholdMv);

%% CAPTURE DATA
% Capture a block of data:
% segment index: 0
[status] = invoke(ps5000aDeviceObj, 'runBlock', 0);

% Software trigger the AWG to output a single cycle of the waveform
invoke(ps5000aDeviceObj, 'ps5000aSigGenSoftwareControl', 1);

data_ready = 0;
while(data_ready == 0)
    % Wait for data to be collected
    fprintf('Waiting for data...................\n');
    invoke(ps5000aDeviceObj, 'ps5000aIsReady', data_ready);
end

% Retrieve data values:
%
% start index       : 0
% segment index     : 0
% downsampling ratio: 1
% downsampling mode : 0 (PS5000A_RATIO_MODE_NONE)

[chA, chB, chC, chD, numSamples, overflow] = invoke(ps5000aDeviceObj, 'getBlockData', 0, 0, 1, 0);

% Stop the device
[status] = invoke(ps5000aDeviceObj, 'ps5000aStop');
invoke(ps5000aDeviceObj, 'setSigGenOff');

%% PROCESS DATA
% Plot data values.
figure;

% Calculate time (nanoseconds) and convert to milliseconds
% Use timeIntervalNanoSeconds output from ps5000aGetTimebase or
% ps5000aGetTimebase2 or calculate from Programmer's Guide.

timeNs = double(timeIntervalNanoSeconds) * double([0:numSamples - 1]);
timeus = timeNs / 1e3;

% Channel A
axisHandleChA = subplot(2,1,1);
plot(timeus, normalise(chA), 'b');
title('Channel A');
xlabel(axisHandleChA, 'Time (us)');
ylabel(axisHandleChA, 'Voltage (mV)');

% original Signal
axisHandleOrig = subplot(2,1,2);
plot(t.*1e6, y, 'r');
title('Original Signal');
xlabel(axisHandleOrig, 'Time (us)');
ylabel(axisHandleOrig, 'Voltage (mV)');

%% DEVICE DISCONNECTION
samplingRate
% Disconnect device object from hardware.
disconnect(ps5000aDeviceObj);
GrahamP
Newbie
 
Posts: 0
Joined: Wed Jul 06, 2016 11:49 am

Re: AWG + sampling using PS5442B

Postby Hitesh » Wed Sep 28, 2016 8:42 am

Hi Graham,

Please use the ps5000aRunBlock() function instead of the runBlock() function. This takes the same arguments as the runBlock function.

The runBlock function combines the ps5000aRunBlock() and ps5000aIsReady() functions to simplify calling code if you do not need to call any functions inbetween.

Hope this helps,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2063
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: AWG + sampling using PS5442B

Postby GrahamP » Wed Sep 28, 2016 11:27 am

Hi Hitesh,

I changed the code to include ps5000aRunBlock.

Code: Select all
[status] = invoke(ps5000aDeviceObj, 'ps5000aRunBlock', 0, Nsamples, 14.5, 0, 0, 0, 0);

invoke(ps5000aDeviceObj, 'ps5000aSigGenSoftwareControl', 1);

while(data_ready == 0)
    fprintf('Waiting for data...................\n');
    invoke(ps5000aDeviceObj, 'ps5000aIsReady', data_ready);
end


The program gets stuck in the while loop, and data_ready never changes. How do I correctly poll this bit? Also, I don't think lpReady is set correctly, but am not sure how to do so. Please advise.

Thanks,

Graham
GrahamP
Newbie
 
Posts: 0
Joined: Wed Jul 06, 2016 11:49 am

Re: AWG + sampling using PS5442B

Postby Hitesh » Wed Sep 28, 2016 1:22 pm

Hi Graham,

The ps5000aRunBlock() function only takes the driver object and segment index as input parameters so please try:

Code: Select all
[status] = invoke(ps5000aDeviceObj, 'ps5000aRunBlock', 0);

The Instrument Driver handles the remaining parameters (the pre- and post-trigger samples and timebase are properties that you set, and the last two remaining parameters for the underlying function call are set to []).

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2063
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: AWG + sampling using PS5442B

Postby GrahamP » Sat Oct 01, 2016 1:28 pm

Hi Hitesh,

The code still doesn't work - I changed the line as you said, but it gets stuck in the while loop, "Waiting for data..." I've attached the code below. Please advise?

Code: Select all
%% LOAD CONFIGURATION INFORMATION

PS5000aConfig;

%% DEVICE CONNECTION
% Create a device object.
ps5000aDeviceObj = icdevice('picotech_ps5000a_generic.mdd');
% Connect device object to hardware.
connect(ps5000aDeviceObj);

%% SET CHANNELS

% Default driver settings used - use ps5000aSetChannel to turn channels on
% or off and set voltage ranges, coupling, as well as analogue offset.

%% SET DEVICE RESOLUTION

% Max. resolution with 2 channels enabled is 15 bits.
[status, resolution] = invoke(ps5000aDeviceObj, 'ps5000aSetDeviceResolution', 14);

%% SET SIMPLE TRIGGER
% Enable      : 0 Disable - any non-zero value will trigger
% Channel     : 0 (PS5000A_CHANNEL_A)
% Threshold   : 0 (mV)
% Direction   : 2 (Rising)
% Delay       : 0
% Auto trigger: 0 (wait indefinitely)

[status] = invoke(ps5000aDeviceObj, 'setSimpleTrigger', 0, 0, 0, 2, 0, 0);

%% GET TIMEBASE
% Driver default timebase index used - use ps5000aGetTimebase or
% ps5000aGetTimebase2 to query the driver as to suitability of using a
% particular timebase index then set the 'timebase' property if required.
% timebase     : 14 == 10MHz (time interval 100ns)
% segment index: 0

[status, timeIntervalNanoSeconds, maxSamples] = invoke(ps5000aDeviceObj, 'ps5000aGetTimebase', 14.5, 0);

%% SET BLOCK PARAMETERS
Nsamples = 1024;
samplingRate = 1/(double(timeIntervalNanoSeconds)*1e-9);
% Set pre-trigger samples.
set(ps5000aDeviceObj, 'numPreTriggerSamples', 0);
set(ps5000aDeviceObj, 'numPostTriggerSamples', Nsamples);  %% Samples to record after trigger

%% Start the AWG
% Configure property value(s).
% awgBufferSize = get(ps5000aDeviceObj, 'awgBufferSize');
f = 2.5e6;
t = linspace(0,1/f,Nsamples);
y = normalise(sin(2*pi*f*t));
% load('RF_test_sig.mat');
% y = normalise(RF_test_sig);

% % Set parameters
% % Set the frequency in the Instrument Driver
% set(ps5000aDeviceObj, 'startFrequency', 4*f); 
% set(ps5000aDeviceObj, 'stopFrequency', 4*f);

offsetMv = 0;
pkToPkMv = 2000;
increment = 0; % Hz
dwellTime = 1; % seconds
sweepType = ps5000aEnuminfo.enPS5000ASweepType.PS5000A_UP;
operation = PicoConstants.FALSE;
sweepType = ps5000aEnuminfo.enPS5000AIndexMode.PS5000A_SINGLE;
shots = 1;
sweeps = 0;
triggerType = ps5000aEnuminfo.enPS5000ASigGenTrigType.PS5000A_SIGGEN_RISING;
triggerSource = ps5000aEnuminfo.enPS5000ASigGenTrigSource.PS5000A_SIGGEN_SOFT_TRIG;
extInThresholdMv = 0;

% Call function
invoke(ps5000aDeviceObj, 'setSigGenArbitrary', offsetMv, pkToPkMv, increment, dwellTime, ...
    y, sweepType, operation, sweepType, shots, sweeps, triggerType, triggerSource, extInThresholdMv);

%% CAPTURE DATA
% Capture a block of data:
% segment index: 0
[status] = invoke(ps5000aDeviceObj, 'ps5000aRunBlock', 0);

% Software trigger the AWG to output a single cycle of the waveform
invoke(ps5000aDeviceObj, 'ps5000aSigGenSoftwareControl', 1);

data_ready = 0;
while(data_ready == 0)
    % Wait for data to be collected
    fprintf('Waiting for data...................\n');
    invoke(ps5000aDeviceObj, 'ps5000aIsReady', data_ready);
end

% Retrieve data values:
%
% start index       : 0
% segment index     : 0
% downsampling ratio: 1
% downsampling mode : 0 (PS5000A_RATIO_MODE_NONE)

[chA, chB, chC, chD, numSamples, overflow] = invoke(ps5000aDeviceObj, 'getBlockData', 0, 0, 1, 0);

% Stop the device
[status] = invoke(ps5000aDeviceObj, 'ps5000aStop');
invoke(ps5000aDeviceObj, 'setSigGenOff');

%% PROCESS DATA
% Plot data values.
figure;

% Calculate time (nanoseconds) and convert to milliseconds
% Use timeIntervalNanoSeconds output from ps5000aGetTimebase or
% ps5000aGetTimebase2 or calculate from Programmer's Guide.

timeNs = double(timeIntervalNanoSeconds) * double([0:numSamples - 1]);
timeus = timeNs / 1e3;

% Channel A
axisHandleChA = subplot(2,1,1);
plot(timeus, normalise(chA), 'b');
title('Channel A');
xlabel(axisHandleChA, 'Time (us)');
ylabel(axisHandleChA, 'Voltage (mV)');

% original Signal
axisHandleOrig = subplot(2,1,2);
plot(t.*1e6, y, 'r');
title('Original Signal');
xlabel(axisHandleOrig, 'Time (us)');
ylabel(axisHandleOrig, 'Voltage (mV)');

%% DEVICE DISCONNECTION
samplingRate
% Disconnect device object from hardware.
disconnect(ps5000aDeviceObj);


Many thanks,

Graham
GrahamP
Newbie
 
Posts: 0
Joined: Wed Jul 06, 2016 11:49 am

Re: AWG + sampling using PS5442B

Postby Hitesh » Mon Oct 03, 2016 11:45 am

Hi Graham,

Thanks for the code. I've run some tests here and it looks as though you will need to setup a trigger on the input channel in order to use the software trigger to activate the output of the signal generator.

I did notice in your code that although the ps5000aGetTimebase() function was called to validate the timebase index, the timebase index was not set. Please note that the timebase index is an integer so an index of 14 will give you a sampling interval of 96 ns.

Code: Select all
[status, timeIntervalNanoSeconds, maxSamples] = invoke(ps5000aDeviceObj, 'ps5000aGetTimebase', 14, 0);

set(ps5000aDeviceObj, 'timebase', 14);

You will need to adjust the number of samples to collect based on the sampling interval.

Please e-mail support@picotech.com and I can provide you with an updated Instrument Driver and a modified version of your script.
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2063
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire


Return to MATLAB

Who is online

Users browsing this forum: No registered users and 0 guests