How to improve the time cost of 'putvalue' in DAQ toolbox

1 回表示 (過去 30 日間)
Alberich Qi
Alberich Qi 2012 年 1 月 23 日
編集済み: Thomas Carpenter 2013 年 10 月 7 日
I am using NI DAQ card USB6008 for data input and output, and the 'putvalue' and 'getvalue' commond in DAQ toolbox cost 4~5 milliseconds in average. However, in my experiment, a commond time cost below 1 ms is prefered.
How can I improve it?
I have considered using C++ in matlab, but 'create task' and 'start task' is needed every time when we call the C function, thus it still cost 2~3 ms.
Create a task using C++ in the beggining and keep it alive in the whole matlab process might be a possible idea, but the memory address of the task is always deleted automatically when the c function completes, and I don't know how to solve this problem.
Do anyone have any idea ?
Thanks!

回答 (3 件)

Manisha
Manisha 2012 年 1 月 31 日
Hi Alberich,
Have you tried the Session-based interface? 4-5 ms sounds reasonable. Could you explain why you need it to be below 1 ms.
Another thing you could try is the direct driver access provided by the Data Acquisition Toolbox ( introduced with Session-based interface ) to get minimum time cost for these operation using the same task handle. See this fileexhange for an example on how to use that interface.
Your code could look something like this:
% Create the Task
[status,taskHandle] = daq.ni.NIDAQmx.DAQmxCreateTask (char(0),uint64(0));
[status] = daq.ni.NIDAQmx.DAQmxCreateAIVoltageChan (...
taskHandle,... % The task handle
'Dev1/ai0',... % physicalChannel
char(0),... % nameToAssignToChannel
niTerminalConfig,... % terminalConfig
range.Min,... % minVal
range.Max,... % maxVal
daq.ni.NIDAQmx.DAQmx_Val_Volts,... % units
char(0)); % customScaleName
..More code to read the channel and destroy at the end
This way you can use the same task handle again without needing to recreate it.
Hope that helps,
Manisha

Walter Roberson
Walter Roberson 2012 年 1 月 31 日
Which release are you using? If you are using R14SP2 through R2006A, then please see http://www.mathworks.com/support/solutions/en/data/1-2KRVG0/index.html?solution=1-2KRVG0
  1 件のコメント
Alberich Qi
Alberich Qi 2012 年 2 月 10 日
I use matlab R2007b, so maybe it is not the problem.

サインインしてコメントする。


Alberich Qi
Alberich Qi 2012 年 2 月 15 日
Thanks very much, it is really the way I want. However, I find that it does not support digital I/O from the information in this page http://www.mathworks.co.jp/help/toolbox/daq/bsvjl59-1.html Is there any way to apply it on digital I/O?
The reason I need it to be below 1ms : I want to produce a animation in my experiment. I have to output a rising-edge as a sign of each frame, then show the frame immediately after the sign, and then generate the next frame. The output and other process (show frame and generate the next frame) has to be complete in 16ms (1 frame). As a sign of the frame, we need an accuracy about 1ms. However, the time lag it not fixed, and the variation is about 2~3ms. This is unacceptable for a sign. Also, generating frame need some time, thus this process won't be completed if the NI output takes much time.

カテゴリ

Help Center および File ExchangeData Acquisition Toolbox Supported Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by