how to generate a pulse train of known frequency and visualize/count the pulses (NI USB 6211 DAQ)
16 views (last 30 days)
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
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.DutyCycle = 0.2;
dataIn = startForeground(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"