delay in Simulink Matlab function block

Hi,
I want to do something very simple, but since I've failed to find a way, I turn to you :-)
I use a Matlab function block in a Simulink model.
I have an input (PumpOn) which switches on, and off (0-1) When it switches on, I want to wait (delay), then change the output to AirExDCInvO2.
I want to keep that output for the same time (delay), then set the output back to zero.
The time I want to wait, is simulated time, not real time.
The model should keep simulating, while the delay is active.
I have tried to use pause, but I think it only pauses simulation. I have tried a timer, but timer is not supported in the Matlab fcn code generation.
The code from the matlab function block is shown below.
Thanks for reading :-)
Hans
function y = InvalidO2Control(PumpOn, delay, AirExDCInvO2)
y = 0;
if PumpOn == 1 %pump is switched on
pause(delay) % Let the pump run for a while, before doing anything
y = AirExDCInvO2; % set the output (open valve)
pause(delay) % let the valve be open for a while, while pump is still running
y = 0; % close the valve ( pump continues to run)
end
end

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2018년 12월 6일

0 개 추천

It looks like the Delay block in Simulink could meet your need.

댓글 수: 3

Hans Jensen
Hans Jensen 2018년 12월 7일
편집: Hans Jensen 2018년 12월 7일
Hi,
I am not sure, that I can. The delay has to be executed inside the Matlab fcn block.
I have added some comments to the code above, so you can see what I want to do.
Fangjun Jiang
Fangjun Jiang 2018년 12월 7일
Keep in mind that MATLAB Function block is just like any other Simulink block. It is running at every simulation step. What you need is to have a persistent variable to serve as the timer/counter and then decide the output based on the timer/counter value.
Fangjun Jiang
Fangjun Jiang 2018년 12월 7일
Or, if you have the Stateflow toolbox, use absolute time temporal logic
web(fullfile(docroot, 'stateflow/examples/using-absolute-time-temporal-logic.html'))

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

카테고리

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

제품

릴리스

R2018a

질문:

2018년 12월 6일

댓글:

2018년 12월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by