How to design an increasing and decreasing toggle counter in Simulink – MATLAB R2019a?

This video shows the steps to design a increasing and decreasing counter which toggles after reaching a certain threshold value in Simulink MATLAB – R2019a.

In this video basically it toggles to decreasing counter after reaching to the MAX value and reverts to increasing counter once it reaches to MIN value. In this video, MAX values is assumed to be 5 and MIN value is assumed to be 0. The key concept in designing this counter is to ensure that between the MIN and MAX value the counter retains its flow (i.e. basically the slope of counter is retained). So, if a counter is increasing it will continue with increasing part unless it reaches to MAX value. Similarly, if a counter is decreasing it will continue the decreasing order until it reaches the MIN value. To get the increasing or decreasing information a derivative block is used in the model which gives the slope of the model.

In this video only Simulink blocks are used to implement the concept and no other features of MATLAB like Stateflow or MATLAB code has been used.


Y = output

MAX = 5

Y > MAX   => Decreasing Counter

Y < MIN => Increasing Counter

Change in Y (dY/dt) => Follow the trend


Some of the other counter videos created by me on YouTube can be found in the below links:

How to design variable step increasing and decreasing counter in Simulink?
How to design a Decreasing Counter and reset counter in Simulink?
How to design counter in App Designer using MATLAB function and global variables and Simulink Model?

We will be glad to hear from you regarding any query, suggestions or appreciations at:

Leave a Reply