How can I design a model button counter in Simulink?

10 views (last 30 days)
Hello Everyone,
I want to create a basic application with push button, When I hold push button the system will start counting the timer and giving a boolean output true when 10 seconds pass system on if i click again push button system output will be false and timer will be 0. How can i design the system with simulink I created some of counters but it doesn't work, like I wanted

Answers (1)

Rahul
Rahul on 6 Sep 2024
Edited: Rahul on 6 Sep 2024
Hi @none:
I understand you’re trying to build a Simulink model involving a switching logic, consisting of a push button which provides a Boolean true output when pressed/activated for more than 10 seconds, and resets the timer and provides a Boolean false output when pressed again.
  • Simulation Time: You can use the ‘clock’ Block (Simulink>Simulink Environment Fundamentals>Block Libraries>Sources>Clock), to display and record the elapsed simulation time, instead of using a unit delay feedback loop to count the timer.
  • Switching: You can use ‘Manual Switch’ block as a manually controlled push button, connected to desired Boolean outputs. Further, using Debug Toolstrip > Pause Time you can observe the switching behavior from on to reset or pause, by adding and switching during pause times.
  • Simulation Pace & Observation: Moreover, to decrease model’s simulation pace, you can modify the Model’s simulation pace to match a real-world time second with one second of simulation time, which could make it easier to observe the switching logic while using our button, using the instructions mentioned in the following link:
  • https://www.mathworks.com/help/simulink/slref/simulationpacingoptions.html
Here is how the model output looks like for initial conditions at t = 0 (start = 1, pause = 0, reset = 0), and then manually switching reset or pause at t = 15, with the clock acting as timer and not the timer control subsystem connected to the switching logic:
  • Timer Control Subsystem: For implementing a timer with pause and reset, you can use triggered subsystems to capture simulation time at switching time of pause or reset, and then subtract it from time when pause/reset are switched back to false, to either pause and resume time from the last recorded value or start timer from 0 again.
I have attached the shown model in the answer, feel free to take a look.
For more information on usage of ‘clock’ blocks or triggered subsystems, refer to the documentation links mentioned below:

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!