MATLAB Answers

Data Acquisition Toolbox with Simulink: Counter Input Channel

12 views (last 30 days)
Axton Isaly
Axton Isaly on 26 Oct 2019
Commented: Rutvik Shete on 11 Aug 2020
Hi,
We are trying to use an NI USB-6009 device to conduct I/O within a Simulink model. The model is already well developed and running on Simulink Real Time with another DAQ, and so we want to change the structure as little as possible. From my understanding, there is no support for the NI device with the Real Time package. Instead, we are trying to implement the data aquisition with the Data Aquisition Toolbox. This will be acceptable as we don't need hard real time and can run the model from a computer with MATLAB/Simulink running.
I need to count pulses from an encoder using the USB-6009 counter channel. I can do this in MATLAB using the following code:
s = daq.createSession('ni');
addCounterInputChannel(s,'Dev1', 'ctr0', 'EdgeCount');
s.inputSingleScan()
What is the equivalent to this in Simulink? The Data Acquisition Toolbox in Simulink does not include a counter input/output block. I find it strange that such a simple function would be available in MATLAB but not implemented in Simulink. When running the first line of the above code in Simulink through a MATLAB function blocks I get the following error:
Function 'createSession' not supported for code generation.
Function 'MATLAB Function' (#35.23.46), line 2, column 5:
"daq.createSession('ni')"

  0 Comments

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 7 Aug 2020
Edited: Walter Roberson on 10 Aug 2020
turn off rapid acceleration. You can have normal acceleration but you will probably need to mark a number of functions as external. If you turn off acceleration completely you can call normal matlab functions from a matlab function block.

Rutvik Shete
Rutvik Shete on 7 Aug 2020
facing same issue with NI USB 6251. Cant use commands when I code using Function block in Simulink.
Error is "Function 'daq' not supported for code generation. "

  2 Comments

Walter Roberson
Walter Roberson on 10 Aug 2020
This is correct. The Data Acquisition Toolbox is not supported for Code Generation.
It is supported by MATLAB Compiler.
I am not clear as to whether it is supported by Simulink Coder.
If you happened to be trying to use it from MATLAB Function Blocks, then you could use No Acceleration, or Normal Acceleration, and use coder.extrinsic() to have the interpreted engine invoke the functions. You might not be able to use Rapid Acceleration. There are probably a series of alternatives to use with Real Time Workshop.
Rutvik Shete
Rutvik Shete on 11 Aug 2020
Well that helped me use external functions with sacrifice of simulation speed. Thanx a lot.

Sign in to comment.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by