Desktop Real-Time slow initialization

37 次查看(过去 30 天)
william
william 2024-7-2,16:56
评论: Manikanta Aditya 2024-7-9,1:26
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,8:05
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,13:31
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,1:26
  • 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 中查找有关 Development Computer Setup 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by