Creating a resettable timer in Simulink

39 次查看(过去 30 天)
Hi everybody.
I am trying to implement a timer in Simulink, which resets, whenever an external signal becomes true.
I came up with the simple structure below. The "Timer stop" pulse generator resets "Clock" by substracting "Clock1" from "Clock". This happens, when "Timer Stop" becomes zero (Pulse generator with period of 4s and 99.99% duty cycle):
When ever "ext.signal" becomes true (this is just an example) the timer should start from zero and go until the time is over (in this case 4s).
In this example "ext.signal" goes to high at 9s. The problem is, that "ext.signal" doesn't reset the "Timer stop" pulse generator. So I end up with this:
Does anybody have an Idea how I can get the expected result from the picture above? I have already tried: Enabled and resettable subsystems, with no success. This is the closest I have gotten so far.
Greetings and many thanks in advance!

回答(1 个)

Rajanya
Rajanya 2024-9-23
I understand that you are trying to build a resettable clock system which can reset itself and start counting whenever an external signal is triggered.
I’ve run the model developed by you and have been able to reproduce the same graph of the output signal as described. The reason, as stated by you correctly, is that the external signal is unable to reset the timer control and therefore, the timer control (Timer stop in the figure) runs for only the remaining time i.e. 4s – the time elapsed before the trigger got high, justifying the obtained output.
A simple solution to this would be to remove the timer stop block altogether (it is doing nothing apart from the desired action of keeping track of the 4s) and to add the timer control to a ‘Compare to Constant’ block as shown.
Here, as per the desired requirements, 4 has been set as the constant.
At each time step, check for the difference between the current simulation clock time and the time which was stored in the memory the last time the clock reset itself. Whenever the external signal gets high, the system should reset, therefore the ‘Ext.signal’ is connected with a NOT gate. The AND gate would ensure that the switch condition only gets true when both the ‘Ext.signal’ is false and the time difference is less than the desired period.
Simulating the same, we can get the desired output. The blue lines indicate the triggers.
’Ext.signal’ has been taken as a pulse generator with 0.01% duty cycle repeating after 10s.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by