PS5000

Post your MATLAB discussions here
Post Reply
Renaat
Newbie
Posts: 0
Joined: Mon Dec 03, 2012 10:28 am

PS5000

Post by Renaat »

Hello,

I have a Picoscope 5204 and i want to measure a signal on channel A and plot this data into matlab.
I found some examples here on the forum for the 3000 and 4000 series but nothing for the 5000 series.
Is there somebody who got a simple solution to make this examples also running on the 5000 series ?

thx in advance

Renaat

Hitesh

Re: PS5000

Post by Hitesh »

Hi Renaat,

We are in the process of creating generic Instrument Drivers for our PicoScope product ranges but we currently don't have one for the PicoScope 5000 series.

One Customer has created an application to generate signals - you can use this as a basis to see how to call functions from MATLAB:

http://www.picoapps.com/coders-corner/

You will need to make sure that you download the latest Software Development Kit from http://www.picotech.com/software.html and refer to the Programmer's Guide. There is also a brief guide which I hope you have seen in this Forum area.

Hope this helps.

Renaat
Newbie
Posts: 0
Joined: Mon Dec 03, 2012 10:28 am

Re: PS5000

Post by Renaat »

Hi,

Code: Select all


clc;

clear all;

close all;

loadlibrary 'PS5000.dll' 'ps5000Api.h' addheader 'picoStatus.h' mfilename 'PS5000MFile';

if ~libisloaded('PS5000')

error('library PS5000.dll or PS5000.h not found') %check if the library is loaded

end

Buffer = zeros(1,1000000);

[methodinfo,structs,enuminfo] = PS5000MFile; % Data and method structure for the ps5000 api.

unithandle = 0; % Handle to the opened unit.

offsetVoltage = 0; % Offset in microvolt (±1 V).

pkToPk = 500000; % Peak-to-peak amplitude in microvolt (±250 mV to ±2 V).

waveType = enuminfo.enWaveType.PS5000_SINE; % Type of Wave. See commentsection at the bottom of this file for a full list.

%waveType = 'PS5000_SINE'; % Type of Wave. See commentsection at the bottom of this file for a full list.

startFrequency = 1000; % Hz (must be lower than or equal to stopfrequency).

stopFrequency = 1000; % Hz.

increment = 0; % Increment in frequency for sweepmode.

dwellTime = 0; % Time (sec) spent in each frequency for sweepmode.

sweepType = 'UP'; % Type of sweep. See commentsection at the bottom of this file for a full list.

whiteNoise = 0; % TRUE or FALSE.

shots = 0; % Number of shots if not in sweepmode.

sweeps = 0; % Number of sweeps if in sweepmode.

triggerType = 'SIGGEN_RISING'; % Trigger type. See commentsection at the bottom of this file for a full list.

triggerSource = 'SIGGEN_NONE'; % Trigger source. See commentsection at the bottom of this file for a full list.

extInThreshold = 0; % Threshold for trigger on external in.

[status_open,unithandle] = calllib('PS5000','ps5000OpenUnit',unithandle);

status_ps5000SetChannel = calllib('PS5000','ps5000SetChannel',unithandle,'PS5000_CHANNEL_A',true,true,'PS5000_500MV');

status_ps5000GetTimebase = calllib('PS5000','ps5000GetTimebase',unithandle,2500002,1000000,0,1,0,0);

status_SetSigGenBuiltIn = calllib('PS5000','ps5000SetSigGenBuiltIn',unithandle,...

offsetVoltage,pkToPk,waveType,startFrequency,stopFrequency,increment,dwellTime,...

sweepType,whiteNoise,shots,sweeps,triggerType,triggerSource,extInThreshold);

status_ps5000RunBlock = calllib('PS5000','ps5000RunBlock',unithandle,0,0,2500002,1,0,10000,0,0);

pause(0.5);

status_ps5000SetDataBuffer = calllib('PS5000','ps5000SetDataBuffer',unithandle,'PS5000_CHANNEL_A',Buffer,1000000);

status_ps5000GetValues = calllib('PS5000','ps5000GetValues',unithandle,0,1000000,0,1,10000,0);

plot(status_ps5000GetValues)

status_close = calllib('PS5000','ps5000CloseUnit',unithandle);

unloadlibrary('PS5000');
[/codeclc;

clear all;

close all;

loadlibrary 'PS5000.dll' 'ps5000Api.h' addheader 'picoStatus.h' mfilename 'PS5000MFile';

if ~libisloaded('PS5000')

error('library PS5000.dll or PS5000.h not found') %check if the library is loaded

end

Buffer = zeros(1,1000000);

[methodinfo,structs,enuminfo] = PS5000MFile; % Data and method structure for the ps5000 api.

unithandle = 0; % Handle to the opened unit.

offsetVoltage = 0; % Offset in microvolt (±1 V).

pkToPk = 500000; % Peak-to-peak amplitude in microvolt (±250 mV to ±2 V).

waveType = enuminfo.enWaveType.PS5000_SINE; % Type of Wave. See commentsection at the bottom of this file for a full list.

%waveType = 'PS5000_SINE'; % Type of Wave. See commentsection at the bottom of this file for a full list.

startFrequency = 1000; % Hz (must be lower than or equal to stopfrequency).

stopFrequency = 1000; % Hz.

increment = 0; % Increment in frequency for sweepmode.

dwellTime = 0; % Time (sec) spent in each frequency for sweepmode.

sweepType = 'UP'; % Type of sweep. See commentsection at the bottom of this file for a full list.

whiteNoise = 0; % TRUE or FALSE.

shots = 0; % Number of shots if not in sweepmode.

sweeps = 0; % Number of sweeps if in sweepmode.

triggerType = 'SIGGEN_RISING'; % Trigger type. See commentsection at the bottom of this file for a full list.

triggerSource = 'SIGGEN_NONE'; % Trigger source. See commentsection at the bottom of this file for a full list.

extInThreshold = 0; % Threshold for trigger on external in.

[status_open,unithandle] = calllib('PS5000','ps5000OpenUnit',unithandle);

status_ps5000SetChannel = calllib('PS5000','ps5000SetChannel',unithandle,'PS5000_CHANNEL_A',true,true,'PS5000_500MV');

status_ps5000GetTimebase = calllib('PS5000','ps5000GetTimebase',unithandle,2500002,1000000,0,1,0,0);

status_SetSigGenBuiltIn = calllib('PS5000','ps5000SetSigGenBuiltIn',unithandle,...

offsetVoltage,pkToPk,waveType,startFrequency,stopFrequency,increment,dwellTime,...

sweepType,whiteNoise,shots,sweeps,triggerType,triggerSource,extInThreshold);

status_ps5000RunBlock = calllib('PS5000','ps5000RunBlock',unithandle,0,0,2500002,1,0,10000,0,0);

pause(0.5);

status_ps5000SetDataBuffer = calllib('PS5000','ps5000SetDataBuffer',unithandle,'PS5000_CHANNEL_A',Buffer,1000000);

status_ps5000GetValues = calllib('PS5000','ps5000GetValues',unithandle,0,1000000,0,1,10000,0);

status_close = calllib('PS5000','ps5000CloseUnit',unithandle);

unloadlibrary('PS5000');

If i look into the programmers guide i don't know what i need to do with the pointers and the callbacks.
Can anybody help me what i do wrong and help me further so i can measure a signal on channel A ?

Thx

Renaat

Hitesh

Re: PS5000

Post by Hitesh »

Hi Renaat,

Just to clarify, are you looking to use the signal generator and capture a single block of data?

One tip is that once you have loaded the library use the following command to see the functions and the data types of the parameters:

Code: Select all

libfunctionsview('PS5000');
MATLAB will convert data types for you when passed to a function call and those parameters defined as pointers will be returned as an output of the function on the left hand side along with the values for status. The exception is when libpointers are used - you do not need to return anything in the output.

For more information on libpointers please visit http://www.mathworks.co.uk/help/matlab/ ... nters.html

(Note: Pico Technology is not responsible for the content of external sites.)

I recommend using a libpointer to define your buffer e.g.

Code: Select all

pBufferChA = libpointer('int16Ptr', zeros(1000000, 1));
Can I confirm that you are using a timebase of 2500002 - 20ms?

If you are capturing data in block mode, there is no need to use callback functions - you can pass the null matrix argument - and you will also need to poll the driver until it has captured data. If you need to capture data in streaming mode then you will need to create a 'c' header file for the ps5000wrap.dll file.

I noticed that you haven't set any pre or post-trigger samples which is necessary according to the Programmer's Guide:
The number of samples is determined by noOfPreTriggerSamples and noOfPostTriggerSamples

Code: Select all

noOfPreTriggerSamples = 0;
noOfPostTriggerSamples = 1000000;
timebase = 2500002;
oversample = 1;
timeIndisposedMs = [];
segmentIndex = 0; % Leave set to 0 unless the data is being captured in a specific segment on the device.
lpReady = []; % Callback not used
pParameter = [];

status_ps5000RunBlock = calllib('PS5000','ps5000RunBlock',unithandle, noOfPreTriggerSamples, noOfPostTriggerSamples, timebase, oversample, timeIndisposedMs, segmentIndex, lpReady, pParameter);

ready = 0;

% Poll the driver until it has captured some data
while(ready == 0)

[status_read, ready] = calllib('PS5000', 'ps5000IsReady', unithandle, ready);

pause(0.1);

end

When you call the ps5000SetDataBuffer function, you pass the pBufferChA libpointer for the buffer argument.

When you call the ps5000GetValues function, set the segmentIndex to 0 (you have not divided up the memory into segments for your appication).

Once you have called the above function you can retrieve the data (in ADC counts) by retrieving the data from the libpointer:

Code: Select all

bufferChA = get(pBufferChA, 'Value');
You will need to convert the values in the buffer using the adc2mv function file which was provided to the Customer who wrote the signal generator code if you want to convert the data to milliVolts. You can then plot this data.

It appears that your code has been pasted twice, is that meant to be that way?

Hope this helps.

Renaat
Newbie
Posts: 0
Joined: Mon Dec 03, 2012 10:28 am

Re: PS5000

Post by Renaat »

Hello,

Thx for your response Hitesh.

I always get an error in GetValues. Matlab say always parameter must be a scalar.
If i change 'RATIO_MODE_NONE' to 0, it works but i always get 0 in my bufferChA.
What do i wrong ?

Thx in advance

Renaat

Code: Select all

clc;
clear all;
close all;

loadlibrary 'PS5000.dll' 'ps5000Api.h' addheader 'picoStatus.h' mfilename 'PS5000MFile';
if ~libisloaded('PS5000')
error('library PS5000.dll or PS5000.h not found') %check if the library is loaded
end

pBufferChA = libpointer('int16Ptr', zeros(1000000, 1));
[methodinfo,structs,enuminfo] = PS5000MFile; % Data and method structure for the ps5000 api.

unithandle = 0; % Handle to the opened unit.
offsetVoltage = 0; % Offset in microvolt (±1 V).
pkToPk = 500000; % Peak-to-peak amplitude in microvolt (±250 mV to ±2 V).
waveType = enuminfo.enWaveType.PS5000_SINE; % Type of Wave. See commentsection at the bottom of this file for a full list.
%waveType = 'PS5000_SINE'; % Type of Wave. See commentsection at the bottom of this file for a full list.
startFrequency = 1000; % Hz (must be lower than or equal to stopfrequency).
stopFrequency = 1000; % Hz.
increment = 0; % Increment in frequency for sweepmode.
dwellTime = 0; % Time (sec) spent in each frequency for sweepmode.
sweepType = 'UP'; % Type of sweep. See commentsection at the bottom of this file for a full list.
whiteNoise = 0; % TRUE or FALSE.
shots = 0; % Number of shots if not in sweepmode.
sweeps = 0; % Number of sweeps if in sweepmode.
triggerType = 'SIGGEN_RISING'; % Trigger type. See commentsection at the bottom of this file for a full list.
triggerSource = 'SIGGEN_NONE'; % Trigger source. See commentsection at the bottom of this file for a full list.
extInThreshold = 0; % Threshold for trigger on external in.

noOfPreTriggerSamples = 0;
noOfPostTriggerSamples = 1000000;
timebase = 2500002;
oversample = 1;
timeIndisposedMs = [];
segmentIndex = 0; % Leave set to 0 unless the data is being captured in a specific segment on the device.
lpReady = []; % Callback not used
pParameter = [];

[status_open,unithandle] = calllib('PS5000','ps5000OpenUnit',unithandle);

status_ps5000SetChannel = calllib('PS5000','ps5000SetChannel',unithandle,'PS5000_CHANNEL_A',true,true,'PS5000_500MV');

status_ps5000GetTimebase = calllib('PS5000','ps5000GetTimebase',unithandle,2500002,1000000,0,1,0,0);

status_SetSigGenBuiltIn = calllib('PS5000','ps5000SetSigGenBuiltIn',unithandle,...
    offsetVoltage,pkToPk,waveType,startFrequency,stopFrequency,increment,dwellTime,...
    sweepType,whiteNoise,shots,sweeps,triggerType,triggerSource,extInThreshold);

status_ps5000RunBlock = calllib('PS5000','ps5000RunBlock',unithandle, noOfPreTriggerSamples,...
    noOfPostTriggerSamples, timebase, oversample, timeIndisposedMs, segmentIndex, lpReady, pParameter);

status_ps5000SetDataBuffer = calllib('PS5000','ps5000SetDataBuffer',unithandle,'PS5000_CHANNEL_A',pBufferChA,1000000);

status_ps5000GetValues = calllib('PS5000','ps5000GetValues',unithandle,0,1000000,0,'RATIO_MODE_NONE',0,0);

bufferChA = get(pBufferChA, 'Value')

status_close = calllib('PS5000','ps5000CloseUnit',unithandle);

unloadlibrary('PS5000');

Hitesh

Re: PS5000

Post by Hitesh »

Hi Renaat,

The issue you are having with 'RATIO_MODE_NONE' is that it is an enumeration and you need to pass a value in.

You have already loaded in the enumerations from the PS5000MFile so you can access the enumerations from the command line - try typing enuminfo. and press the 'tab' key to see the enumeration groups. The 'enuminfo' output is a structure of structures containing the enumerations.

You might need to do the same for the channel A entry as well in the setChannel and setDataBuffer function calls. It's possible this could be linked to the values being zero. What are the status values coming back from the function calls.

Hope this helps.

Renaat
Newbie
Posts: 0
Joined: Mon Dec 03, 2012 10:28 am

Re: PS5000

Post by Renaat »

Hi,

I just changed the things u said, but i still don't get any data (always 0 in buffer).
We created a signal on signal_out with amplitude 500 mV peak-to-peak and frequency 1000 Hz, and now we want to measure that signal on channel A.
I don't understand what i do wrong. U got some suggestions ?

Thx

Renaat

Code: Select all

clc;
clear all;
close all;

loadlibrary 'PS5000.dll' 'ps5000Api.h' addheader 'picoStatus.h' mfilename 'PS5000MFile';
if ~libisloaded('PS5000')
error('library PS5000.dll or PS5000.h not found') %check if the library is loaded
end

pBufferChA = libpointer('int16Ptr', zeros(1000000, 1));
[methodinfo,structs,enuminfo] = PS5000MFile; % Data and method structure for the ps5000 api.

unithandle = 0; % Handle to the opened unit.
offsetVoltage = 0; % Offset in microvolt (±1 V).
pkToPk = 500000; % Peak-to-peak amplitude in microvolt (±250 mV to ±2 V).
waveType = enuminfo.enWaveType.PS5000_SINE; % Type of Wave. See commentsection at the bottom of this file for a full list.
%waveType = 'PS5000_SINE'; % Type of Wave. See commentsection at the bottom of this file for a full list.
startFrequency = 1000; % Hz (must be lower than or equal to stopfrequency).
stopFrequency = 1000; % Hz.
increment = 0; % Increment in frequency for sweepmode.
dwellTime = 0; % Time (sec) spent in each frequency for sweepmode.
sweepType = 'UP'; % Type of sweep. See commentsection at the bottom of this file for a full list.
whiteNoise = 0; % TRUE or FALSE.
shots = 0; % Number of shots if not in sweepmode.
sweeps = 0; % Number of sweeps if in sweepmode.
triggerType = 'SIGGEN_RISING'; % Trigger type. See commentsection at the bottom of this file for a full list.
triggerSource = 'SIGGEN_NONE'; % Trigger source. See commentsection at the bottom of this file for a full list.
extInThreshold = 0; % Threshold for trigger on external in.

noOfPreTriggerSamples = 0;
noOfPostTriggerSamples = 1000000;
timebase = 2500002;
oversample = 1;
timeIndisposedMs = [];
segmentIndex = 0; % Leave set to 0 unless the data is being captured in a specific segment on the device.
lpReady = []; % Callback not used
pParameter = [];
overflow = [];
channelA = enuminfo.enPS5000Channel.PS5000_CHANNEL_A;
range = enuminfo.enPS5000Range.PS5000_500MV;
downSampleRatioMode = enuminfo.enRatioMode.RATIO_MODE_NONE;
true = enuminfo.enTriggerState.CONDITION_TRUE;

[status_open,unithandle] = calllib('PS5000','ps5000OpenUnit',unithandle);

status_ps5000SetChannel = calllib('PS5000','ps5000SetChannel',unithandle,channelA,true,true,range);

status_ps5000GetTimebase = calllib('PS5000','ps5000GetTimebase',unithandle,2500002,1000000,0,oversample,1000000,0);

status_SetSigGenBuiltIn = calllib('PS5000','ps5000SetSigGenBuiltIn',unithandle,...
    offsetVoltage,pkToPk,waveType,startFrequency,stopFrequency,increment,dwellTime,...
    sweepType,whiteNoise,shots,sweeps,triggerType,triggerSource,extInThreshold);

status_ps5000RunBlock = calllib('PS5000','ps5000RunBlock',unithandle, noOfPreTriggerSamples,...
    noOfPostTriggerSamples, timebase, oversample, timeIndisposedMs, segmentIndex, lpReady, pParameter);

status_ps5000SetDataBuffer = calllib('PS5000','ps5000SetDataBuffer',unithandle,channelA,pBufferChA,1000000);

status_ps5000GetValues = calllib('PS5000','ps5000GetValues',unithandle,0,1000000,0,downSampleRatioMode,0,overflow);

bufferChA = get(pBufferChA, 'Value')

status_close = calllib('PS5000','ps5000CloseUnit',unithandle);

unloadlibrary('PS5000');


Hitesh

Re: PS5000

Post by Hitesh »

Hi Rennat,

I've run your code and the status value from the get values call is returning a non-zero value. You can find out what the error refers to in the Programmer's Guide (hint: use dec2hex() to convert the value).

This error will show you what is going wrong - part of it is that you are not waiting for the device to become ready as I suggested in my code snippet.

Have you checked your parameters to see if they are correct - I am seeing a collection of 1000000 samples at an interval of 20 milliseconds which will take around 5.5 hours. Do you want to capture in block mode or streaming mode?

Please refer to the Programmer's Guide for further information on timebases and the process for collecting data in block mode e.g.:
1. Open the oscilloscope using ps5000OpenUnit .
2. Select channel ranges and AC/DC coupling using ps5000SetChannel .
3. Using ps5000GetTimebase , select timebases until the required nanoseconds
per sample is located.
4. If you require ETS mode, set it up using ps5000SetEts .
5. If you are using ETS mode, allocate timing information buffers and tell the driver
about them using ps5000SetEtsTimeBuffer .
6. Use the trigger setup functions to set up the trigger if required.
7. If required, set the signal generator using ps5000SetSigGen .
8. Start the oscilloscope running using ps5000RunBlock .
9. Wait until the oscilloscope is ready [...].
10. Use ps5000SetDataBuffer to tell the driver where your memory buffer is.
11. Transfer the block of data from the oscilloscope using ps5000GetValues .
12. Display the data.
13. Repeat steps 8 to 12.
14. Stop the oscilloscope using ps5000Stop
Hope this helps,

Renaat
Newbie
Posts: 0
Joined: Mon Dec 03, 2012 10:28 am

Re: PS5000

Post by Renaat »

Hello,

Thx Hitesh, my program works fine now.
Thx for your help.

Grtz

Renaat

Post Reply