10-27-2019 05:38 AM
Hi all
I'm trying to use the 6341 NI daq with MATLAB. Actually I need just to sampling the counter with differents high sampling rates. according to the MATLAB supporting I need to add an analog channel for clocking. I'm running this code:
s = daq.createSession('ni');
addCounterInputChannel(s,'Dev1', 0, 'EdgeCount');
addAnalogInputChannel(s,'Dev1', 0, 'Voltage');
s.Rate=500000;
[data, time] = s.startForeground();
plot(time, data);
And I get this error: "Timeout expired before operation could complete"
If I add manually an external clock it works but I can sample only with the sample rate of the clock - 100 kHz, this is the code for it:
s = daq.createSession('ni');
addCounterInputChannel(s,'Dev1', 0, 'EdgeCount');
addClockConnection(s,'external','Dev1/100kHzTimebase','ScanClock')
s.Rate=100000;
[data, time] = s.startForeground();
unfortunately, I need to be able to change the sample rate. I will glad if somebody can help me
Thank you!
10-29-2019 02:29 PM
I know nothing of the MATLAB toolbox or its API, I only use DAQmx via LabVIEW. That said, I'll take a shot anyway.
1. A counter task won't be able to derive its own sample clock from some other signal, including any of the internal timebases. It needs a signal it can use *directly* as a sample clock.
You found success using the 100 kHz timebase *directly*, but unfortunately you can't modify that rate as you'd like.
2. That's why MATLAB support suggested adding a dummy analog task. I'd probably make a dummy analog *output* task, and seed it with a bunch of 0.0 V values that it can regenerate on an AO channel I don't connect to anything. An AO task will regenerate by default so that once you start it, you don't need to do anything else but stop & clear it at the end of your entire app.
3. I'm not sure what distinguishes the "Session" you create (named 's') and a DAQmx task I'm used to. I *do* know that under DAQmx, you can't put Counter and Analog channels into the same task, you'd need distinct tasks for them.
4. The Counter task should use the Analog task's sample clock as its own. My *guess* at the syntax would be something like: addClockConnection(s,'external','/Dev1/ao/SampleClock','ScanClock')
5. Be sure to start the Counter task before you start the Analog task so it'll be ready to react to sample clock signals when they start.
-Kevin P