Error code 51 in ps5000aRunBlock call when using ext trigger

Post your MATLAB discussions here
Post Reply
furuian
Newbie
Posts: 0
Joined: Wed May 11, 2016 2:02 pm

Error code 51 in ps5000aRunBlock call when using ext trigger

Post by furuian »

Hi, I'm using an external trigger signal (EXT) that is LOW normally and goes HIGH for 10 ms every 1 second.

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

Martyn
Site Admin
Site Admin
Posts: 4483
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Error code 51 in ps5000aRunBlock call when using ext tri

Post by Martyn »

The error you are getting is just a warning

Code: Select all

#define PICO_WARNING_EXT_THRESHOLD_CONFLICT         0x00000033UL
However looking at your code both values are set to 4000, which should be OK, so it may be that you have a delay set in the channel trigger.

Can you try removing this and see if the error disappears.
Martyn
Technical Support Manager

furuian
Newbie
Posts: 0
Joined: Wed May 11, 2016 2:02 pm

Re: Error code 51 in ps5000aRunBlock call when using ext tri

Post by furuian »

Thanks! I changed the delay in setSimpleTrigger to 0 but the same issue persists.

I does appear to be an error, not a warning. It says "error" in the message and it shows up when I run Matlab's lasterror() function but not when I run Matlab's lastwarn() function. I know how to suppress warnings but not errors in Matlab.

What I understand from your reply is that the message is inconsequential and can be ignored, is that right? It still interrupts my code though, so it would be great to somehow suppress it, either on the driver side or on the Matlab side. Thank you for your advice.

Martyn
Site Admin
Site Admin
Posts: 4483
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Error code 51 in ps5000aRunBlock call when using ext tri

Post by Martyn »

Yes technically it is an error, but actually it is only a warning, hence the name of the error. It is saying that two different trigger setups have been selected, so it will chose one of them and run with that, which is why it operates successfully.

A colleague is going to check the MATLAB drivers as it may be an inconsistency in the lower level, between voltage levels and ADC counts, 4000 in one call and 4000 in the other call may not be the same thing. If you set both levels to 0 does the error still get reported ? I know 0 is not a useful level for you but it will be useful to prove a point.
Martyn
Technical Support Manager

furuian
Newbie
Posts: 0
Joined: Wed May 11, 2016 2:02 pm

Re: Error code 51 in ps5000aRunBlock call when using ext tri

Post by furuian »

Thanks, in the example folder of my Matlab SDK, I find the following code which implies that the threshold value for setSimpleTrigger is in mV (and not ADC counts):

Code: Select all

%% SET SIMPLE TRIGGER

% Channel     : 0 (PS5000A_CHANNEL_A)
% Threshold   : 1000 (mV)
% Direction   : 2 (Rising)
% Delay       : 0
% Auto trigger: 0 (wait indefinitely)

[status] = invoke(ps5000aDeviceObj, 'setSimpleTrigger', 0, 1000, 2, 0, 0);
If the siggen extinthreshold is in ADC counts and the setsimpletrigger threshold is in mV, then they may be hard to match due to rounding issues. A colleague of yours suggested that the ADC counts for the EXT channel can be converted as follows:

ADC count = mv*32,767 / 5000

So the ADC count setting of 4000 would correspond to a mV setting of 610.37. I tried setting the setsimpletrigger threshold to 610.37, 610, and 611 but none of it worked. I also tried setting the extinthreshold to 4004 counts while leaving the setsimpletrigger threshold at 611 but that also didn't work.

You could be on to something with the differences between those two functions but I don't know how to deal with rounding issues to make the two values equal.

Martyn
Site Admin
Site Admin
Posts: 4483
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Error code 51 in ps5000aRunBlock call when using ext tri

Post by Martyn »

Can you try with both levels set at 0.

If the error disappears then we are on the right track and just need to understand the levels, if not then I will need to get my colleague to debug further.
Martyn
Technical Support Manager

Hitesh

Re: Error code 51 in ps5000aRunBlock call when using ext tri

Post by Hitesh »

Hi furuian,

I have tested your code with a later version of the Instrument Driver and am unable to reproduce the issue. There was a fix made for using an external trigger in the setSimpleTrigger() function.

Could you please e-mail support@picotech.com and we can provide you with an updated Instrument Driver and associated files.

It would be helpful to know the version of MATLAB you are using and if it is pre-2016a, if it is 32-bit or 64-bit.

Regards,

beginnermna
Newbie
Posts: 0
Joined: Tue Feb 18, 2020 9:01 pm

Re: Error code 51 in ps5000aRunBlock call when using ext trigger

Post by beginnermna »

Hi
I tried to run the code given here but I am getting error code 37. Can anybody help?

Martyn
Site Admin
Site Admin
Posts: 4483
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Error code 51 in ps5000aRunBlock call when using ext trigger

Post by Martyn »

What function returns the error and is this a decimal or hex value ?
Martyn
Technical Support Manager

Post Reply