|
| 1 | +%% PicoScope 6000 Series (A API) Instrument Driver Oscilloscope Signal Generator Example |
| 2 | +% This is an example of an instrument control session using a device |
| 3 | +% object. The instrument control session comprises all the steps you |
| 4 | +% are likely to take when communicating with your instrument. |
| 5 | +% |
| 6 | +% These steps are: |
| 7 | +% |
| 8 | +% # Create a device object |
| 9 | +% # Connect to the instrument |
| 10 | +% # Configure properties |
| 11 | +% # Invoke functions |
| 12 | +% # Disconnect from the instrument |
| 13 | +% |
| 14 | +% To run the instrument control session, type the name of the file, |
| 15 | +% PS6000A_ID_Signal_Generator_Example, at the MATLAB command prompt. |
| 16 | +% |
| 17 | +% The file, PS6000A_ID_SIGNAL_GENERATOR_EXAMPLE.M must be on your MATLAB PATH. For |
| 18 | +% additional information on setting your MATLAB PATH, type 'help addpath' |
| 19 | +% at the MATLAB command prompt. |
| 20 | +% |
| 21 | +% *Example:* |
| 22 | +% PS6000A_ID_Signal_Generator_Example; |
| 23 | +% |
| 24 | +% *Description:* |
| 25 | +% Demonstrates how to set properties and call functions in order to |
| 26 | +% output from the signal generator of a PicoScope 6000 (A API) Series Oscilloscope. |
| 27 | +% |
| 28 | +% *See also:* <matlab:doc('icdevice') |icdevice|> | <matlab:doc('instrument/invoke') |invoke|> |
| 29 | +% |
| 30 | +% *Copyright:* © 2020-2022 Pico Technology Ltd. See LICENSE file for terms. |
| 31 | + |
| 32 | +%% Clear Command Window and Close Figures |
| 33 | + |
| 34 | +clc; |
| 35 | +close all; |
| 36 | + |
| 37 | +%% Load Configuration Information |
| 38 | + |
| 39 | +[ps6000aStructs, ps6000aEnumInfo]=PS6000aSetConfig(); |
| 40 | + |
| 41 | +%% Device Connection |
| 42 | + |
| 43 | +% Check if an Instrument session using the device object 'ps6000DeviceObj' |
| 44 | +% is still open, and if so, disconnect if the User chooses 'Yes' when prompted. |
| 45 | +if (exist('ps6000aDeviceObj', 'var') && ps6000aDeviceObj.isvalid && strcmp(ps6000aDeviceObj.status, 'open')) |
| 46 | + |
| 47 | + openDevice = questionDialog(['Device object ps6000aDeviceObj has an open connection. ' ... |
| 48 | + 'Do you wish to close the connection and continue?'], ... |
| 49 | + 'Device Object Connection Open'); |
| 50 | + |
| 51 | + if (openDevice == PicoConstants.TRUE) |
| 52 | + |
| 53 | + % Close connection to device |
| 54 | + disconnect(ps6000aDeviceObj); |
| 55 | + delete(ps6000aDeviceObj); |
| 56 | + |
| 57 | + else |
| 58 | + |
| 59 | + % Exit script if User selects 'No' |
| 60 | + return; |
| 61 | + |
| 62 | + end |
| 63 | + |
| 64 | +end |
| 65 | + |
| 66 | +%% Create a device object. |
| 67 | +% The serial number can be specified as a second input parameter. |
| 68 | + |
| 69 | +ps6000aDeviceObj = icdevice('picotech_ps6000a_generic.mdd',''); |
| 70 | + |
| 71 | +%% Connect scope |
| 72 | + |
| 73 | +connect(ps6000aDeviceObj) |
| 74 | + |
| 75 | +%% Setup scope to output 2 Vpp 10 kHz Sine wave |
| 76 | + |
| 77 | +% set waveform type to sine wave |
| 78 | +waveType = ps6000aEnumInfo.enPicoWaveType.PICO_SINE; |
| 79 | + |
| 80 | +[status.sigGenWaveform] = invoke(ps6000aDeviceObj,'ps6000aSigGenWaveform',waveType, 0,0); |
| 81 | + |
| 82 | +% set output voltage to 2 V peak to peak with 0 V offset |
| 83 | + |
| 84 | +[status.sigGenRange] = invoke(ps6000aDeviceObj, 'ps6000aSigGenRange', 2,0); |
| 85 | + |
| 86 | +% set output frequency |
| 87 | +frequency = 10000; %Hz |
| 88 | + |
| 89 | +[status.sigGenFrequency] = invoke(ps6000aDeviceObj, 'ps6000aSigGenFrequency',frequency); |
| 90 | + |
| 91 | +% apply sign generator settings and start generation |
| 92 | + |
| 93 | +sigGenEnabled = 1; |
| 94 | +sweepEnabled = 0; |
| 95 | +triggerEnabled = 0; |
| 96 | +automaticClockOptimisationEnabled = 0; |
| 97 | +overrideAutomaticClockAndPrescale = 0; |
| 98 | +pFrequency = libpointer('doublePtr',frequency); |
| 99 | +stopFrequency = frequency; |
| 100 | +pStopFrequency = libpointer('doublePtr',stopFrequency); |
| 101 | +frequencyIncrement = 1; |
| 102 | +pFrequencyIncrement = libpointer('doublePtr',frequencyIncrement); |
| 103 | +dwellTime = 1; |
| 104 | +pDwellTime = libpointer('doublePtr',dwellTime); |
| 105 | + |
| 106 | +[status.sigGenApply] = invoke(ps6000aDeviceObj, 'ps6000aSigGenApply', sigGenEnabled, sweepEnabled, triggerEnabled, automaticClockOptimisationEnabled, overrideAutomaticClockAndPrescale, pFrequency, pStopFrequency, pFrequencyIncrement, pDwellTime); |
| 107 | + |
| 108 | +pause(5) |
| 109 | + |
| 110 | +%% change frequency to 100 kHz |
| 111 | + |
| 112 | +frequency = 100000; %Hz |
| 113 | +pFrequency = libpointer('doublePtr',frequency); |
| 114 | + |
| 115 | +[status.sigGenFrequency] = invoke(ps6000aDeviceObj, 'ps6000aSigGenFrequency',frequency); |
| 116 | + |
| 117 | +% apply changes |
| 118 | +[status.sigGenApply] = invoke(ps6000aDeviceObj, 'ps6000aSigGenApply', sigGenEnabled, sweepEnabled, triggerEnabled, automaticClockOptimisationEnabled, overrideAutomaticClockAndPrescale, pFrequency, pStopFrequency, pFrequencyIncrement, pDwellTime); |
| 119 | + |
| 120 | +pause(5) |
| 121 | + |
| 122 | +%% sweep frequency from 100 kHz to 1 mHz over ~1 s |
| 123 | + |
| 124 | +stopFrequency = 1000000; |
| 125 | +frequencyIncrement = 10000; |
| 126 | +dwellTime = 0.01; |
| 127 | +sweepType = ps6000aEnumInfo.enPicoSweepType.PICO_UPDOWN; |
| 128 | + |
| 129 | +[status.sigGenFrequencySweep] = invoke(ps6000aDeviceObj,'ps6000aSigGenFrequencySweep',stopFrequency,frequencyIncrement,dwellTime,sweepType); |
| 130 | + |
| 131 | +% apply changes |
| 132 | +sweepEnabled = 1; |
| 133 | +pStopFrequency = libpointer('doublePtr',stopFrequency); |
| 134 | +pFrequencyIncrement = libpointer('doublePtr',frequencyIncrement); |
| 135 | +pDwellTime = libpointer('doublePtr',dwellTime); |
| 136 | +[status.sigGenApply] = invoke(ps6000aDeviceObj, 'ps6000aSigGenApply', sigGenEnabled, sweepEnabled, triggerEnabled, automaticClockOptimisationEnabled, overrideAutomaticClockAndPrescale, pFrequency, pStopFrequency, pFrequencyIncrement, pDwellTime); |
| 137 | + |
| 138 | +pause(5) |
| 139 | + |
| 140 | +%% Disconnect scope |
| 141 | + |
| 142 | +disconnect(ps6000aDeviceObj); |
| 143 | + |
| 144 | +%% |
| 145 | +delete(ps6000aDeviceObj); |
0 commit comments