Triggering a PicoScope Signal Generator using the API

Post general discussions on using our drivers to write your own software here
Post Reply
Hitesh
Advanced User
Advanced User
Posts: 2856
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Triggering a PicoScope Signal Generator using the API

Post by Hitesh » Tue Apr 07, 2015 2:50 pm

Hi,

We have produced a document that provides an outline of how to set parameters in order to the trigger the signal generator output on a PicoScope where available:

https://www.picotech.com/download/manua ... ctions.pdf

Please post any questions in this thread.

Thanks,
Hitesh

Software Dev. Engineer

mblack
Newbie
Posts: 0
Joined: Fri Apr 06, 2018 7:05 pm

Re: Triggering a PicoScope Signal Generator using the API

Post by mblack » Fri Apr 06, 2018 7:16 pm

Hello,

I am using the ps2000a SDK with a model 2408B. I have the output of the AWG feeding into the input of channel D, and have set up a trigger with a threshold of +1V on channel D. Using an independent function generator and oscilloscope, I have verified that the 2408B is both producing the waveform I expect (without an AWG trigger), and receiving a known waveform.

My question is, where does the call to SigGenSoftwareControl need to be? Right now I have my code set up to call RunBlock, IsReady, SigGenSoftwareControl, SetDataBuffer, GetValues, SetDataBuffer (clear) in that order, but my waveform (a repeating pulse) is not being transmitted. I am calling SigGenSoftwareControl(handle,1), with the SetSigGenArbitrary taking in a trigger type of Rising (0), and a trigger source of Software Trigger (4). I was hoping to understand where my error is.

The behavior I am looking for is the following: 2408B initializes on system startup, then the AWG is triggered ONCE off a software flag, and channel D is triggered upon the AWG transmitted waveform crossing a threshold of +1V.

Thanks!

Hitesh
Advanced User
Advanced User
Posts: 2856
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Triggering a PicoScope Signal Generator using the API

Post by Hitesh » Tue Apr 10, 2018 9:39 am

Hi mblack,

The SigGenSoftwareControl() function should be called after RunBlock() is called and before you begin to check if the device has data available (i.e. if it is ready).

Are you using C# or another programming language?

Regards,
Hitesh

Software Dev. Engineer

mblack
Newbie
Posts: 0
Joined: Fri Apr 06, 2018 7:05 pm

Re: Triggering a PicoScope Signal Generator using the API

Post by mblack » Tue Apr 10, 2018 6:51 pm

I am using Python. Thank you, that fixed the issue.

Hitesh
Advanced User
Advanced User
Posts: 2856
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Triggering a PicoScope Signal Generator using the API

Post by Hitesh » Wed Apr 11, 2018 8:53 am

Glad to hear that fixed the issue :)

Regards,
Hitesh

Software Dev. Engineer

pantel
Newbie
Posts: 0
Joined: Wed Dec 04, 2019 3:40 pm

Re: Triggering a PicoScope Signal Generator using the API

Post by pantel » Wed Dec 04, 2019 4:16 pm

Hello,
I use python API to drive picoscope 4824.
In picosdk folder on github a simple data acquisition model using a trigger is implemented in ps4824BlockExample.py
On top of that, i would like to add ps4000aSetSigGenArbitrary function, in order to trigger the sig gen and, say, picoscope's channel A at the same time, i.e using the picoscope simultaneously as sig gen and as data acquisition unit.
I just added the ps4000aSetSigGenArbitrary function between ps4000aSetSimpleTrigger and ps4000aRunBlock, using channel A as a trigger source for ps4000aSetSimpleTrigger and ps4000aSetSigGenArbitrary.
Is that really the proper usage of its sig gen and its data acquisition channels?

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

Re: Triggering a PicoScope Signal Generator using the API

Post by beginnermna » Tue May 05, 2020 3:17 am

Hello
I have the same question as pantel. Also in the arbitrary signal generator setting I set shots=20 and sweeps=0 but I am just getting 8 cycles all the time. What should i do?

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

Re: Triggering a PicoScope Signal Generator using the API

Post by Martyn » Tue May 05, 2020 5:01 am

Can you post your code as we need to see how you have set everything up.
Martyn
Technical Support Manager

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

Re: Triggering a PicoScope Signal Generator using the API

Post by beginnermna » Fri May 08, 2020 2:07 am

Code: Select all

%%
clear all;
close all;
clc;
%% Load configuration information

PS5000aConfig;

%% Device connection

% Check if an Instrument session using the device object |ps5000aDeviceObj|
% is still open, and if so, disconnect if the User chooses 'Yes' when prompted.
if (exist('ps5000aDeviceObj', 'var') && ps5000aDeviceObj.isvalid && strcmp(ps5000aDeviceObj.status, 'open'))
    
    openDevice = questionDialog(['Device object ps5000aDeviceObj has an open connection. ' ...
        'Do you wish to close the connection and continue?'], ...
        'Device Object Connection Open');
    
    if (openDevice == PicoConstants.TRUE)
        
        % Close connection to device.
        disconnect(ps5000aDeviceObj);
        delete(ps5000aDeviceObj);
        
    else

        % Exit script if User selects 'No'.
        return;
        
    end
    
end

% Create a device object. 
ps5000aDeviceObj = icdevice('picotech_ps5000a_generic', ''); 

% Connect device object to hardware.
connect(ps5000aDeviceObj);

%% Set device resolution

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

%% Verify timebase index and maximum number of samples
% Use the |ps5000aGetTimebase2()| function to query the driver as to the
% suitability of using a particular timebase index and the maximum number
% of samples available in the segment selected, then set the |timebase|
% property if required.
%
% To use the fastest sampling interval possible, enable one analog
% channel and turn off all other channels.
%
% Use a while loop to query the function until the status indicates that a
% valid timebase index has been selected. In this example, the timebase
% index of 65 is valid.

% Initial call to ps5000aGetTimebase2() with parameters:
%
% timebase      : 65
% segment index : 0

status.getTimebase2 = PicoStatus.PICO_INVALID_TIMEBASE;
% timebaseIndex = get(ps5000aDeviceObj, 'timebase');
timebaseIndex=3;
while (status.getTimebase2 == PicoStatus.PICO_INVALID_TIMEBASE)
    
    [status.getTimebase2, timeIntervalNanoseconds, maxSamples] = invoke(ps5000aDeviceObj, ...
                                                                    'ps5000aGetTimebase2', timebaseIndex, 0);
    
    if (status.getTimebase2 == PicoStatus.PICO_OK)
       
        break;
        
    else
        
        timebaseIndex = timebaseIndex + 1;
        
    end    
    
end

fprintf('Timebase index: %d, sampling interval: %d ns\n', timebaseIndex, timeIntervalNanoseconds);

% Configure the device object's |timebase| property value.
set(ps5000aDeviceObj, 'timebase', timebaseIndex);

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

%% Obtain Signalgenerator group object
% Signal Generator properties and functions are located in the Instrument
% Driver's Signalgenerator group.

sigGenGroupObj = get(ps5000aDeviceObj, 'Signalgenerator');
sigGenGroupObj = sigGenGroupObj(1);
f = 1000;
t = linspace(0,1/f,Nsamples);
y = normalise(sin(2*pi*f*t));

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

[status.setSigGenArbitrary] = invoke(sigGenGroupObj, 'setSigGenArbitrary', increment, dwellTime, y, sweepType, ...
										operation, indexMode,shots, sweeps, triggerType, triggerSource, 0);


%%
blockGroupObj = get(ps5000aDeviceObj, 'Block');
blockGroupObj = blockGroupObj(1);
startIndex              = 0;
segmentIndex            = 0;
downsamplingRatio       = 1;
downsamplingRatioMode   = ps5000aEnuminfo.enPS5000ARatioMode.PS5000A_RATIO_MODE_NONE;
i=1;
[stopFig.h, stopFig.h] = stopButton();
flag = 1; % Use flag variable to indicate if stop button has been clicked (0).
setappdata(gcf, 'run', flag);
tstart=tic;
while (1)
                
flag = getappdata(gcf, 'run');
       drawnow;

       if (flag == 0)

            disp('STOP button clicked - aborting data collection.')
            break;

       end
[status.runBlock] = invoke(blockGroupObj, 'ps5000arunBlock', 0);
% [status.sigGenSoftwareControl] = invoke(sigGenGroupObj, 'ps5000aSigGenSoftwareControl', 1);
[numSamples, overflow, chA, chB] = invoke(blockGroupObj, 'getBlockData', startIndex, segmentIndex, ...
                                            downsamplingRatio, downsamplingRatioMode);
store(i,:)=chA;
i=i+1;
end                                     
tend=toc(tstart)                                     
%%
timeNs = double(timeIntervalNanoseconds) * downsamplingRatio * double(0:numSamples - 1);
timeMs = timeNs / 1e6;

% Channel A
axisHandleChA = subplot(2,1,1); 
plot(timeMs, store(30,:), 'b');
title(axisHandleChA, 'Channel A');
xlabel(axisHandleChA, 'Time (ms)');
ylabel(axisHandleChA, 'Voltage (mV)');
grid(axisHandleChA, 'on');


%% Stop the device

[status.stop] = invoke(ps5000aDeviceObj, 'ps5000aStop');

%% Disconnect device
% Disconnect device object from hardware.

disconnect(ps5000aDeviceObj);
delete(ps5000aDeviceObj);

Post Reply