PicoScope 7 Software
Available on Windows, Mac and Linux
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);