Variable time on delay for dynamic variable assignment

2 次查看(过去 30 天)
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!

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by