Variable time on delay for dynamic variable assignment

조회 수: 4 (최근 30일)
Thomas Langley
Thomas Langley 2022년 7월 6일
편집: T.Nikhil kumar 2023년 10월 26일
Hi everyone. I'm working on a project which requires a variable time on delay. I have a variable time anywhere from 0-45 seconds and I need an output signal to go high for that specified period of time. For example, if the time period was 12 seconds, I would need the output signal to go high (1) for 12 seconds then revert back to 0. Thanks for the help.
  댓글 수: 2
GandaBerunda
GandaBerunda 2022년 7월 6일
In the example, does the output signal need to go high for 21 seconds or 12 seconds?
Thomas Langley
Thomas Langley 2022년 7월 6일
My bad, either or. The time is dynamic which is what has been giving me issues.

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

답변 (1개)

T.Nikhil kumar
T.Nikhil kumar 2023년 10월 26일
편집: T.Nikhil kumar 2023년 10월 26일
Hello Thomas,
I understand that you want an output signal to have a value of 1 for a specific time interval and then drop back to 0 after this period.
You can implement this is Simulink directly using the ‘Pulse Generator’ Block. You can set suitable period time and pulse width according to the value of your variable time delay. The Amplitude can be set to 1.
You might also achieve this using the ‘pause’ function. You can specify the variable time as an argument to this ‘pause’ function and maintain the output signal’s value as 1 for this period. Refer to the below mentioned code for a rough idea of the function’s usage:
% Define the time delay in seconds (between 0 and 45 seconds)
delayTime = 12; % Generate a random delay between 0 and 45 seconds
% Set the output signal high for the specified delay time
outputSignal = 1;
disp('Output signal is high.');
pause(delayTime);
% Set the output signal back to 0
outputSignal = 0;
disp('Output signal is low.');
Refer to the following documentation to understand more about ‘Pulse Generator’ block.
Refer to the following documentation to understand more about ‘pause’ function.
Hope this helps!

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by