Triggering a PicoScope Signal Generator using the API

Post general discussions on using our drivers to write your own software here
Post Reply
Hitesh

Triggering a PicoScope Signal Generator using the API

Post by Hitesh »

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,

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

Re: Triggering a PicoScope Signal Generator using the API

Post by mblack »

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

Re: Triggering a PicoScope Signal Generator using the API

Post by Hitesh »

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,

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

Re: Triggering a PicoScope Signal Generator using the API

Post by mblack »

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

Hitesh

Re: Triggering a PicoScope Signal Generator using the API

Post by Hitesh »

Glad to hear that fixed the issue :)

Regards,

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

Re: Triggering a PicoScope Signal Generator using the API

Post by pantel »

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 »

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: 4483
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Triggering a PicoScope Signal Generator using the API

Post by Martyn »

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 »

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

picoUser2021
Newbie
Posts: 0
Joined: Wed Feb 03, 2021 11:17 am

Re: Triggering a PicoScope Signal Generator using the API

Post by picoUser2021 »

Hi,

I recently got a 3403D Pico and I am trying to use the Sig Gen (both the simple and Arbitrary ones) through the examples in python (I am coding in Python).

Focusing on the simple Sig Gen, as a test I trying to created a 4-cycle sinusoidal at 650Hz. The parameters I am using are as follows:

offsetVoltage = 0
pkToPk = 2000000
waveType = 0
startFrequency = 650
stopFrequency = 650
increment = 0
dwellTime = 0
sweepType = 0
shots = 4
sweeps = 0
operation = 0
triggerType = 1
triggerSource = 4
extInThreshold = 0

I am using a soft trigger and it seems to run, however the captured waveform (collected on a separate Oscilloscope) is not constantly a single cycle sinusoidal.
I gave tried creating sth similar using the Picoscope GUI and it works fine.

Any ideas how I can fix this?

Thanks

Post Reply