Some questions

Post your MATLAB discussions here
Post Reply
francesc
Newbie
Posts: 1
Joined: Mon Oct 09, 2017 11:32 am

Some questions

Post by francesc »

Hi,

I need to buy a picoscope 6402C (because I need a sampling rate of 1 GSa/s for each channel in 4 channels), but before doing so, I have to be sure that it will be able to do what I need to do (I will explain it in a moment). Fortunately, I own a picoscope 5242A, so for the moment I can try to get data in Matlab using only 2 channels, and a lower sampling rate. But I have some problems. First I will explain what I need, then I will ask some questions.

What I need to do (using the picoscope 6402C that I will buy in the forthcoming days):
- I need to collect data in 4 channels, at 1 GSa/s (one value every 1 ns) for each channel, during 6 ms (hence I need 24 MSamples of data = 6MS each channel x 4 channels.). All the channels will be configured at a range of +-100 mV. I need a resolution of 1 mV so with 8 bits I am ok. After this data is collected in the scope's memory, I plan to transfer it to Matlab and cut the values that I am interested to work with. However, transfer the whole 24 MS of data can take quite a long time, and I only need "blocks" of the collected data. More concretely, I set the trigger (rise, 1V threshold) at t=0 to channel A. Then I need to collect 1000 samples of data from channel B (at t=100 us), 1000 sampes from channel A (at t=1100 us), 1000 samples from channel C (at t=4100 us) and 1000 samples from channel D (at t=5100 us). After that, I process this data and I repeat the operation every 1 s.

Questions:

Q: Is it possible to transfer a block (or "window") of 1 microsecond (1000 samples) of each channel (as described before) to Matlab for processing, thus avoiding to transfer the whole 24 MS (which can take a long time to transfer)?
I am asking this because if I collect 40MS of data using the pico software, I can get the data perfectly, but saving the data as a plain text file to the computer is very slow (around 1 minute using USB 2.0).

Q: How can I set each Channel properties, sample rate, and MS to capture using Matlab?

I am trying to modify the "PS5000A_ID_Block_Example.m" file, but I am only able to set the resolution using:

Code: Select all

[status, resolution] = invoke(ps5000aDeviceObj, 'ps5000aSetDeviceResolution', 12);
No idea how to change the range for each channel.

I can change the autotrigger time with the last value of the following line,

Code: Select all

[status] = invoke(ps5000aDeviceObj, 'setSimpleTrigger', 0, 1000, 2, 0, 500);
However, the scope does not trigger as it should, it waits for the autotrigger instead (why??).

I still don't know how to set the timebase. I need to set to capture data at the maximum sampling rate available, and to capture 6 ms of data, but I don't know how. I tried to change the "65" value of the following line

Code: Select all

[status, timeIntervalNanoSeconds, maxSamples] = invoke(ps5000aDeviceObj, 'ps5000aGetTimebase', 65, 0);
with no results.

I have read the picoscope 5000 API programmers guide but I still don't know how to proceed.

Any help would be much appreciated!

Last question (not so important):
Q: Is it possible to set the channel range to +-50mV, using a x10 probe? Using the picoscope software I can set +- 100 mV, but no lower values.

NeilH
PICO STAFF
PICO STAFF
Posts: 260
Joined: Tue Jul 18, 2017 8:28 am

Re: Some questions

Post by NeilH »

Hi

Do you need to sample at exactly 1 ns sample interval as the 6402C can sample at 800 ps or 1.6 ns but not exactly 1 ns?

It is not possible to transfer the windows of data you're talking about exclusively from the scope but it would be very easy to pick out these windows once the data is within matlab from the buffer.

To set up channels you use this command;

Code: Select all

[status.setChB] = invoke(ps6000DeviceObj, 'ps6000SetChannel', channel, enabled, coupling, voltageRangeIndex, anaglogue offset, bandwidth);
inserting the enumeration values or desired values to set up the channel according to the programmer guide.

To set the sample interval you use

Code: Select all

set(ps6000DeviceObj, 'timebase', timebaseIndex);
and for the number of samples you can use these command to set the pre and post trigger samples

Code: Select all

set(ps6000DeviceObj, 'numPreTriggerSamples', 0);
 set(ps6000DeviceObj, 'numPostTriggerSamples', 2e6);
For your trigger, if its waiting for the auto trigger it would indicate that the trigger condition is not being met in that time so either the auto trigger time would need to be extended or the trigger condition needs changing to better match your signal. To help with this more information would be needed.

For your final question you can set the channel range to be 50mV in the ps6000SetChannel command.

The examples and the programmer's guide can be helpful to find out what inputs each command takes.

I hope this helps but if you need more information let me know

Neil
Neil
Technical Support Engineer

francesc
Newbie
Posts: 1
Joined: Mon Oct 09, 2017 11:32 am

Re: Some questions

Post by francesc »

Many thanks NeilH for your quick answer.

800 ps is fine, even better than 1 ns!
once the data is within matlab from the buffer
This buffer is in the ram memory? I am asking because I don't want to write all the data to the hard drive, because its too slow.

Here I show a minimal example of the program that I am using (with the picoscope5242A that I currently own), and after that I will explain what works and what doesn't:

Code: Select all

close all;

PS5000aConfig;

ps5000aDeviceObj = icdevice('picotech_ps5000a_generic', ''); 
connect(ps5000aDeviceObj);

[status.setChA] = invoke(ps5000aDeviceObj, 'ps5000aSetChannel', 0, 1, 1, 8, 0.0);
[status.setChB] = invoke(ps5000aDeviceObj, 'ps5000aSetChannel', 1, 1, 1, 3, 0.0);

[status.resolution, resolution] = invoke(ps5000aDeviceObj, 'ps5000aSetDeviceResolution', 8);

[status.setSimpleTrigger] = invoke(ps5000aDeviceObj, 'setSimpleTrigger', 0, 1000, 2, 0, 1000);

[status.getTimebase2, timeIntervalNanoSeconds, maxSamples] = invoke(ps5000aDeviceObj, 'ps5000aGetTimebase2', 2, 0);

set(ps5000aDeviceObj, 'numPreTriggerSamples', 2000);
set(ps5000aDeviceObj, 'numPostTriggerSamples', 2000);

[status] = invoke(ps5000aDeviceObj, 'runBlock', 0);

[chA, chB, chC, chD, numSamples, overflow] = invoke(ps5000aDeviceObj, 'getBlockData', 0, 0, 1, 0);

[status] = invoke(ps5000aDeviceObj, 'ps5000aStop');

% Plot data values.
figure;
timeNs = double(timeIntervalNanoSeconds) * double([0:numSamples - 1]);

% Channel A
axisHandleChA = subplot(2,1,1); 
plot(timeNs, chA, 'b');
title('Channel A');
xlabel(axisHandleChA, 'Time (ns)');
ylabel(axisHandleChA, 'Voltage (units?)');

% Channel B

axisHandleChB = subplot(2,1,2); 
plot(timeNs, chB, 'r');
title('Channel B');
xlabel(axisHandleChB, 'Time (ns)');
ylabel(axisHandleChB, 'Voltage (units?)');

% Disconnect device object from hardware.
disconnect(ps5000aDeviceObj);
I can connect to the device, and I can set the resolution, the timebase, and the pre- and post-trigger samples correctly. However, I tried to set the trigger (1V at ChA, rising, zero delay and 1 s autotrigger), but it doesn't trigger as it should, it autotriggers at 1 s (the autotrigger time does work indeed).

I tried to set +-5V range for ChA and +-100mV for ChB (by changing the corresponding numbers to 8 and 3 in the ps5000aSetChannel arguments-9. However, I am not sure if it is ok now because the matlab figure autoscales and I see a lot of noise in both signals. If I can set the trigger to work, I will be completely sure that each channel ranges are correct.

I copied the program from the examples directory, but I can not find any information about the "getBlockdata" function anywhere.

Q: Is there any way to tell the scope that I am using x10 probes via matlab?
Q: Every time that I run the matlab program with an incorrect function, it gives me an error. If I correct the error, it says that no devices are connected. Unplugging and plugging again the usb cable doesn't work, I need to close matlab, unplug the cable, run matlab again and plug the cable again. Is there any way to do it better, or faster?

Any advices on how to set the trigger would be very welcome!
Thanks,
Fran

NeilH
PICO STAFF
PICO STAFF
Posts: 260
Joined: Tue Jul 18, 2017 8:28 am

Re: Some questions

Post by NeilH »

Hi Fran

The buffer is internal to the device where the data is stored before being transferred at the end of a block capture and then after the transfer it will be held in the Matlab workspace on the PC's ram rather than saved to the hard drive.

There isnt a way to tell the scope that you are using a x10 probe but you can always act on the data in matlab to apply the correct scaling.

If you get an error when running code the best thing to do is to run the device disconnect code before trying to run another script, as if an error causes the script to not reach the end the scope will be connected when you try to connect to it in the next script. This causes something in matlab to need a restart before it will correctly connect to the deivce again even if you try to disconnect after that and unplug and replug the scope in.

Code: Select all

%% Disconnect Device
% Disconnect device object from hardware.

disconnect(ps5000aDeviceObj);
delete(ps5000aDeviceObj);
For the trigger, the best way might be to experiment with setting it in Picoscope 6 to more easily get a feel for settings you need to use in matlab more quickly. If you're having trouble still if you let me know some more details about your input signal and exactly what you're trying to trigger on, I can give some more advise.


The getBlockData function can be found in the .mdd file, in which you can see what inputs and output the function involves.

Neil
Neil
Technical Support Engineer

francesc
Newbie
Posts: 1
Joined: Mon Oct 09, 2017 11:32 am

Re: Some questions

Post by francesc »

Thank you very much for your suggestions!

Using picoscope 6 software everything works as expected. I am trying to reproduce the following plot using matlab:
https://imgur.com/a/SEd6u
I apologize that it is in spanish, but the essential things are:
- 8 bits, ChA range: +- 5V, ChB range: +- 100mV, timescale: 1us/div
- trigger of 1V at ChA, rising, pretrigger: 50%

A pulse of 2.5 volts approximately and a width of 300 ns is driven through ChA. I set the trigger of ChA using

Code: Select all

[status.setSimpleTrigger] = invoke(ps5000aDeviceObj, 'setSimpleTrigger', 0, 1000, 2, 0, 5000);


I set the channel range using

Code: Select all

[status.setChA] = invoke(ps5000aDeviceObj, 'ps5000aSetChannel', 0, 1, 1, 8, 0.0);
I think that the "8" value corresponds to +-5V. I changed it from "0" to "10". If this value is 4 or less, the scope triggers as it should, but I obtain the following plot:
https://imgur.com/JSrf6jZ
However, if this value is 5 or more, the scope does not trigger, it waits for the autotrigger and I obtain this:
https://imgur.com/Ik5t86Y
(note that I am using 12 bits in matlab, but using picoscope with 8 bits is ok).

But I need to reproduce the plot from the picoscope software, that is the correct one. I don't know what I'm missing..

NeilH
PICO STAFF
PICO STAFF
Posts: 260
Joined: Tue Jul 18, 2017 8:28 am

Re: Some questions

Post by NeilH »

Would you be able to send your matlab script to support@picotech.com so I can run it myself and workout what needs altering to get the trigger working as you intend it to?
Neil
Technical Support Engineer

francesc
Newbie
Posts: 1
Joined: Mon Oct 09, 2017 11:32 am

Re: Some questions

Post by francesc »

Email sent!

Thank you

francesc
Newbie
Posts: 1
Joined: Mon Oct 09, 2017 11:32 am

Re: Some questions

Post by francesc »

The voltage range for each channel is more or less solved, I need to multiply by a factor of 10 (maybe because I am using x10 probes?) and the voltage range and values are correct.

I have the issues with the sampling rate. Using 1 channel, I applied a known signal using a function generator, and I obtained the following:

If I set the timebase index to "0", the timeIntervalNanoseconds becomes 1 ns (as it should), but the sampling rate is 2 MS/s (why? it should be 1GS/s) and I have to multiply the time by a factor 500 in order to get the correct timescale. Setting the timebase index to "1", the timeIntervalNanoseconds becomes 2 ns (as it should), but the sampling rate doesn't change, it still is 2 MS/s and I have to multiply the time by a factor 500/2=250 in order to get the correct timescale. And so on: timebase="2", factor=500/4=125; timebase="3", factor=500/8; timebase="4", factor=500/16; timebase="5", factor=500/24; timebase="6", factor=500/32; timebase="7", factor=500/40....

Maybe I am not understanding the timebase argument correctly.
With all these configuration I get the same plot. However, I am not able to change the actual sampling rate! It samples at 2MS/s, but I need 1GS/s.

Any ideas?

NeilH
PICO STAFF
PICO STAFF
Posts: 260
Joined: Tue Jul 18, 2017 8:28 am

Re: Some questions

Post by NeilH »

Are you using this line of code after you use the ps5000aGetTimebase,

Code: Select all

set(ps5000aDeviceObj, 'timebase', 4);
This line of code will set the timebase of the scope to the Timebase variable in the line.
We will be updating the documentation to make this clearer.
I hope this helps.
Neil
Technical Support Engineer

francesc
Newbie
Posts: 1
Joined: Mon Oct 09, 2017 11:32 am

Re: Some questions

Post by francesc »

Yes, this was the solution.

Now everything works as expected,

Many thanks!
Fran

Post Reply