Code covered by the BSD License  

Highlights from
PicoScope® 2000 Series - MATLAB® Generic Instrument Driver

image thumbnail

PicoScope® 2000 Series - MATLAB® Generic Instrument Driver

by

 

01 Feb 2013 (Updated )

MATLAB Instrument Driver for use with PicoScope 2000 Series oscilloscopes (Beta Release)

PS2000_IC_Generic_Driver_GetBlock_SimpleTrig.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Filename:    PS2000_IC_Generic_Driver_GetBlock_SimpleTrig.m
%
% Copyright:   Pico Technology Limited 2013
%
% Author:      HSM
%
% Description:
%   This is a MATLAB script that demonstrates how to use the
%   PicoScope 2000 series Instrument Control Toobox driver to collect
%   a block of samples.
%
%   A part of this script was generated using the Test and Measurement
%   Tool.
%
% Example:
%    Collect a block of samples after setting the parameters for the
%    channels, sampling interval and simple trigger.
%
%	To run this application:
%		
%   Click 'Run' in the MATLAB Editor or see the generated comment block
%   below.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%PS2000_IC_GENERIC_DRIVER_GETBLOCK_SIMPLETRIG Code for communicating with an instrument. 
%  
%   This is the machine generated representation of an instrument control 
%   session using a device object. The instrument control session comprises  
%   all the steps you are likely to take when communicating with your  
%   instrument. These steps are:
%       
%       1. Create a device object   
%       2. Connect to the instrument 
%       3. Configure properties 
%       4. Invoke functions 
%       5. Disconnect from the instrument 
%  
%   To run the instrument control session, type the name of the file,
%   PS2000_IC_Generic_Driver_GetBlock_SimpleTrig, at the MATLAB command prompt.
% 
%   The file, PS2000_IC_GENERIC_DRIVER_GETBLOCK_SIMPLETRIG.M must be on your MATLAB PATH. For additional information
%   on setting your MATLAB PATH, type 'help addpath' at the MATLAB command
%   prompt.
%
%   Example:
%       PS2000_IC_Generic_Driver_GetBlock_SimpleTrig;
%
%   See also ICDEVICE.
%

%   Creation time: 04-Jan-2013 17:01:11 
%   Update 01-Nov-2013 for new PicoScope 2204A & 2205A

%% CLEAR WORKSPACE
clear all;
clc;

%% LOAD CONFIGURATION INFORMATION

PS2000Config;

%% DEVICE CONNECTION

% Create a device object. 
ps2000DeviceObj = icdevice('picotech_ps2000_generic.mdd');

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

%% CONFIGURE DEVICE

% Execute device object function(s).

% Channel     : 0 (PS2000_CHANNEL_A)
% Enabled     : 1 (True)
% DC          : 1 (DC Coupling)
% Range       : 6 (PS2000_1V)
[status.setChA] = invoke(ps2000DeviceObj, 'ps2000SetChannel', 0, 1, 1, 6);    % 1V range

% Channel     : 0 (PS2000_CHANNEL_A)
% Enabled     : 1 (True)
% DC          : 1 (DC Coupling)
% Range       : 7 (PS2000_2V)
[status.setChB] = invoke(ps2000DeviceObj, 'ps2000SetChannel', 1, 1, 1, 7);    % 2V range

[samplingIntervalUs, maxBlockSamples] = invoke(ps2000DeviceObj, 'setBlockIntervalUs', 100);

% Query property value(s).
timebaseIndex = get(ps2000DeviceObj, 'timebase'); % Confirm the timebase index selected

% Configure property value(s).
set(ps2000DeviceObj, 'numberOfSamples', 2048);

% Execute device object function(s).
% Parameters taken from config file loaded into workspace
[simpleTriggerStatus] = invoke(ps2000DeviceObj, 'setSimpleTrigger', ...
    simpleTrigger.source, simpleTrigger.threshold, simpleTrigger.direction, ... 
    simpleTrigger.delay, simpleTrigger.autoTriggerMs);

%% DATA COLLECTION

disp('Collecting block of data...');

[bufferTimes, bufferChA, bufferChB, numDataValues, timeIndisposedMs] = invoke(ps2000DeviceObj, 'getBlockData');

disp('Data collection complete.');

%% STOP THE DEVICE
% Additional blocks can be captured prior to stopping the device.

stopStatus = invoke(ps2000DeviceObj, 'ps2000Stop');

%% PROCESS DATA

disp('Processing data for plot...')

% Find the time units used by the driver
timesUnits = adcunits(get(ps2000DeviceObj, 'timeUnits'));

% Append to string
time_label = strcat('Time (', timesUnits, ')');

% Plot

figure;
plot(bufferTimes, bufferChA, 'b-', bufferTimes, bufferChB, 'r-');
title('Plot of Voltage vs. Time');
xlabel(time_label);
ylabel('Voltage (mv)');
legend('Channel A', 'Channel B');

%% DISCONNECT

% Disconnect device object from hardware.
disconnect(ps2000DeviceObj);

Contact us