I'd like this EXT signal to trigger both the signal generator (sending out a number of sine shots) and the scope (recording a section of those shots).
The code below seems to be doing the job but when I call runBlock for the first time in the script, I get the Matlab error message "Error using privateExecuteMCode (line 44) runBlock: Error in ps5000aRunBlock call - code 51". In fact nothing seems to have gone wrong though. I can still step further and get the data with getBlockData. Even more strangely, once the error occurred, I can actually run through the whole for-loop without any problems and further errors. After disconnecting and running the script again from the beginning, the error will show up again, but just once.
Any ideas on how I can avoid/address/suppress this error? Thank you!
- Code: Select all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% connect to device
PS5000aConfig;
obj.deviceobject = icdevice('picotech_ps5000a_generic.mdd');
connect(obj.deviceobject);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% now start signal generator
freq = 1000;
set(obj.deviceobject, 'startFrequency', freq);
set(obj.deviceobject, 'stopFrequency', freq);
offsetMv = 0;
pkToPkMv = 1000;
waveType = ps5000aEnuminfo.enPS5000AWaveType.PS5000A_SINE;
increment = 0;
dewllTime = 0;
sweepType = 0;
operation = 0;
shots = 20;
sweeps = 0;
triggerType = ps5000aEnuminfo.enPS5000ASigGenTrigType.PS5000A_SIGGEN_RISING;
triggerSource = ps5000aEnuminfo.enPS5000ASigGenTrigSource.PS5000A_SIGGEN_EXT_IN;
extInThreshold = 4000;
[status] = invoke(obj.deviceobject, 'setSigGenBuiltIn', offsetMv, pkToPkMv, waveType, increment, dewllTime, sweepType, operation, shots, sweeps, triggerType, triggerSource, extInThreshold);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% now start the scope
triggerchannel = 4; % the ext trigger channel
threshold = 4000;
direction = 2; % rising
delay = 1000;
autotrigger = 0;
[status] = invoke(obj.deviceobject, 'setSimpleTrigger', triggerchannel, threshold, direction, delay, autotrigger);
resolution = 12
[status, resolution] = invoke(obj.deviceobject, 'ps5000aSetDeviceResolution', resolution);
thistimebase = 9
set(obj.deviceobject, 'timebase', thistimebase);
mynumsamples = 1e6
set(obj.deviceobject, 'numPostTriggerSamples', mynumsamples);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% catch data
h1 = figure;
for i = 1:10
% Capture a block of data: % segment index: 0
[status] = invoke(obj.deviceobject, 'runBlock', 0);
pause(0.1);
% 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(obj.deviceobject, 'getBlockData', 0, 0, 1, 0);
pause(1);
figure(h1);
plot(chB);
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% disconnect
invoke(obj.deviceobject, 'setSigGenOff');
disconnect(obj.deviceobject);