AWG + sampling using PS5442B

Post your MATLAB discussions here
Post Reply
GrahamP
Newbie
Posts: 0
Joined: Wed Jul 06, 2016 11:49 am

AWG + sampling using PS5442B

Post by GrahamP »

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 478 times

Hitesh

Re: AWG + sampling using PS5442B

Post by Hitesh »

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,

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

Re: AWG + sampling using PS5442B

Post by GrahamP »

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);
-->
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);