Desktop Real-Time slow initialization

조회 수: 4 (최근 30일)
william
william 2024년 7월 2일
댓글: Manikanta Aditya 2024년 7월 9일
I am using the input from an mcc usb-231 daq to feed data into my simulink model through a function block. The issue I am running into is that when the simulation first starts up. it takes almost an entire minute before my simulation begins simulating through the desktop realtime kernal.
Here is my function block.
function output = fcn()
coder.extrinsic('daq','read','addinput'); %lets simulink know to read commands as MATLAB commands
d = daq('mcc');
addinput(d,'Board0',0,'Voltage')
data = read(d,'OutputFormat','Matrix');
output = zeros(1,1);
output = data(1,1);
Is there a way to get rid of this initialization buffer at the start?

답변 (1개)

Manikanta Aditya
Manikanta Aditya 2024년 7월 5일
Hi,
To improve the initialization time and overall performance, you can try the following workaround approach:
  1. Initialize the DAQ session outside of the function block, perhaps in a MATLAB Function block that runs only once at the start of the simulation.
  2. Use a persistent variable in your function block to maintain the DAQ session across function calls.
Here's how you might modify your code:
  • Create a new MATLAB Function block for initialization:
function d = initDAQ()
coder.extrinsic('daq', 'addinput');
d = daq('mcc');
addinput(d, 'Board0', 0, 'Voltage');
  • Modify your existing function block:
function output = fcn(d)
coder.extrinsic('read');
persistent daqSession
if isempty(daqSession)
daqSession = d;
end
data = read(daqSession, 'OutputFormat', 'Matrix');
output = data(1,1);
  • In your Simulink model, use the initialization function to create the DAQ session, then pass it to your main function block.
This approach should significantly reduce the initialization time because you're setting up the DAQ session only once at the start of the simulation, rather than every time the function block is called.
I hope this helps!
  댓글 수: 2
william
william 2024년 7월 8일
I have incorporated persistance into my function block, but the biggest I learned is that with the data acquisition read is not syncing with the real time kernal and causing a bunch of miss ticks and slowing down the simulation.
Manikanta Aditya
Manikanta Aditya 2024년 7월 9일
  • Perform DAQ read operations in a separate MATLAB Function block that runs asynchronously from the real-time kernel. This will help prevent the DAQ read latency from affecting the real-time execution.
  • Implement a circular buffer to store the DAQ data. The DAQ read operation can write data to this buffer at its own pace, while the real-time kernel can read data from the buffer without waiting for the DAQ operation to complete.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Target Computer Setup에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by