Variable time on delay for dynamic variable assignment

3 Ansichten (letzte 30 Tage)
Thomas Langley
Thomas Langley am 6 Jul. 2022
Bearbeitet: T.Nikhil kumar am 26 Okt. 2023
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 Kommentare
GandaBerunda
GandaBerunda am 6 Jul. 2022
In the example, does the output signal need to go high for 21 seconds or 12 seconds?
Thomas Langley
Thomas Langley am 6 Jul. 2022
My bad, either or. The time is dynamic which is what has been giving me issues.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

T.Nikhil kumar
T.Nikhil kumar am 26 Okt. 2023
Bearbeitet: T.Nikhil kumar am 26 Okt. 2023
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!

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by