Count Down Through Range of Numbers
This example shows how to use the Counter block to count down through a range of numbers. The Pulse Generator block drives the Dec port of the Counter block, and the N-Sample Enable block triggers the Rst port. All inputs to and outputs from the Counter block are multiplexed into a single To Workspace block using a 4-port Mux block.
The following figure shows the first 22 samples of the four-column output,
You can see that the seventh input sample to both the Dec and Rst ports of the Counter block represent trigger events (rising edges). When this occurs, the block first resets the counter to its initial value of
5, and then immediately decrements the counter to
4. When the counter reaches its minimum value of
0, the block restarts the counter at its maximum value of
20 the next time a trigger event occurs at the Dec port.