This example is based on the following article by MathWorks and demonstrates how to count the number of rising and falling edges of a signal acquired from a PicoScope 2205A using the PicoScope 2000 Series MATLAB Instrument Driver:
PS2000Config;
%% DEVICE CONNECTION
% Create a device object.
ps2000DeviceObj = icdevice('picotech_ps2000_generic.mdd');
% Connect device object to hardware.
connect(ps2000DeviceObj);
The device channels settings, sampling interval and the number of samples to collect is then configured. A simple trigger set for a rising edge at 500mV is also set:
% Times returned in nanoseconds - convert to milliseconds
bufferTimesMs = bufferTimes / 1e6;
% Append to string
time_label = strcat('Time (ms)');
% Plot
figure;
plot(bufferTimesMs, bufferChA, 'b-');
title('Plot of Voltage vs. Time');
xlabel(time_label);
ylabel('Voltage (mv)');
legend('Channel A');
% Set the threshold to 0 V.
threshold = 0.0;
% Create the offset data. Need to append a NaN to the final sample since
% both vectors need to have the same length.
offsetData = [bufferChA(2:end); NaN];
% Find the rising edge(s).
risingEdge = find(bufferChA < threshold & offsetData > threshold);
% Find the falling edge(s).
fallingEdge = find(bufferChA > threshold & offsetData < threshold);
% Show the rising edges with red x's.
hold on
plot(bufferTimesMs(risingEdge), threshold, 'MarkerSize',8,'Marker','x', ...
'LineWidth', 2, 'LineStyle','none','Color',[1 0 0]);
% Show the falling edges with green o's.
plot(bufferTimesMs(fallingEdge), threshold, 'MarkerSize',8,'Marker','o', ...
'LineWidth', 2, 'LineStyle','none', 'Color',[0 1 0]);
hold off
fprintf(' Num. rising edges: %d\n', length(risingEdge));
fprintf('Num. falling edges: %d\n\n', length(fallingEdge));
The software does go through a formal testing process before being released as a stable version so it is likely to be a little while - you can set the PicoScope software to notify you of updates via the Tools -> Preferences dialog.
I am not really sure this is the right thread to post my question but it is kind of related.
I have a ps3404MSO at my disposal and I am currently trying to record the data from a rotary encoder. The encoder delivers a square signal of around 3kHz. The problem is that I need to detect with precision the edges of my signal (50ns) but over a longer period of time (20s at least).
Is there a way to only record the occurrence time of each rise/drop time instead of the huge amount of data that is generated by the high sampling rate (witch I actually don’t need)?
I hope you can tell me if there is a way to do it by writing my own program?
Thanks for your answer. I have tried the Mask Limit feature but this doesn’t really help me in this case. As far as I understand it, this feature is made to detect glitches in some waveforms. In my case the waveform shape is only changing in frequency. What I’m interested here is if there is a way just to get every single triggering time (rising edge) in an array.
I sadly don’t have access to matlab and I would be ready to use C code I guess (or Python). The point is just that I’m still quite a beginner in Programming and I don’t want to invest a lot of time in doing so if I’m not sure if it is even possible. From the API I could neither validate nor invalidate this assumption. I was just hoping to get this kind of answer from experience users!
You would need to be looking at the data and trying to find the mid signal crossing points, and then you need to count the number of samples to go from Up/Down/Up, ie one complete cycle. As you will already know the sample interval, you then have the the time taken for that single cycle, which gives you the frequency. Repeat this through the waveform for each cycle and you can then plot the frequency as it changes.
I was actually already using post processing to get to the edge times, I was just wondering if there was a way to do it internally in the Picoscope, but thank you very much for your response!