how to generate a pulse train of known frequency and visualize/count the pulses (NI USB 6211 DAQ)

16 views (last 30 days)
LO
LO on 16 Mar 2020
Commented: LO on 24 Mar 2022
Hi everyone
I am having trouble with some code to start a pulse generation from a device (NI USB-6211 DAQ) while counting it.
The pulse is generated by Dev1/ctr0 and should be detected by Dev1/ctr1. If I use the NI MAX software the process is flawless.
this is my code
daq.reset
d = daq.getDevices;
s = daq.createSession('ni');
s.Rate = 20000; % sample rate
ch3=addAnalogInputChannel(s,'Dev1','ai7','Voltage'); % this channels records the camera output (a pulse for each frame acquired)
ch3.TerminalConfig = 'SingleEnded';
ch1 = addCounterOutputChannel(s,'Dev1','ctr0','PulseGeneration'); % camera trigger
ch1.Frequency =40;
ch1.DutyCycle = 0.2;
ch2=addCounterInputChannel(s,'Dev1','ctr1','EdgeCount'); %
tic
dataIn = startForeground(s);
plot(dataIn)
pause(1);
s.stop
toc
resetCounters(s);
I am trying now to implement this in MATLAB but I have the following issues:
1) the pulse train has a pulse more than what it should (45 instead of 40)
2) the pulse train output is actually 45 instead of 40 (the pulse triggers a camera which acquires 45 frames instead of 40)
3) when I plot the data I can see the analog input (see attached picture) but the digital input is a flat line (red line on the bottom of the plot) which, even when magnified, does not show any pulse (perhaps I am wrong expecting to see pulses here but then I do not know how to visualize the readout of the digital-input "edge counter"
  3 Comments
LO
LO on 24 Mar 2022
not sure but somehow the error is always of a few frames (pulses) so for me is negligible. I can past the code later :)

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!