For using Sfunction, how can I make simulation stay in while loop until break condition taking place?

For example I have an input x and an output y, the pseudo code is like
while(true){
y=1; // this will activate some other blocks in the plant model
if (x==1){
break;
}
}
I suppose in Simulink the simulation will be stuck in the infinite loop because the solver tries to finish while loop within one time step. But in reality, while loop is commonly used in software to wait the hardware response, and then to break the loop when break condition satisfied and to implement interruption. Thus, I'm thinking whether there is a method to make the simulation stay in while loop and just run the while loop code once each time step. Thanks.

댓글 수: 2

Are you looking for some kind of triggered subsystem?
I was thinking about triggered subsystem as well. I'm actually trying to keep the simulation code and software code having the same architecture. Triggered subsystem can be used in simulation, however in terms of code generation, you will never see while loop in the generated code but sth like
y=1;
enable_subfun=1;
if (x==1){
...
}
void subfun(void){
if (enable_subfun==1){
...
}
}

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Embedded Coder에 대해 자세히 알아보기

질문:

2015년 5월 5일

댓글:

2015년 5월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by