| Contents | Index |
Sources
The Counter Free-Running block counts up until reaching the maximum value, 2Nbits – 1, where Nbits is the number of bits. Then the counter overflows to zero and begins counting up again.
After overflow, the counter always initializes to zero. However, if you select the global doubles override, the Counter Free-Running block does not wrap back to zero.
The Counter Free-Running block outputs an unsigned integer.
For more information, see Data Types Supported by Simulink in the Simulink documentation.

Specify the number of bits.
| When you use... | Such as... | The block counts up to... | Which is... |
|---|---|---|---|
A positive integer | 8 | 28 – 1 | 255 |
An unsigned integer expression | uint8(8) | uint8(2uint8(8) – 1) | 254 |
Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See How to Specify the Sample Time in the Simulink documentation.
Suppose that you have the following model:

The block parameters are:
| Parameter | Setting |
|---|---|
| Number of Bits | 8 |
| Sample time | -1 |
The solver options for the model are:
| Parameter | Setting |
|---|---|
| Stop time | 255 |
| Type | Fixed-step |
| Solver | discrete (no continuous states) |
| Fixed-step size | 1 |
At t = 255, the counter reaches the maximum value:
28 – 1
If you change the stop time of the simulation to 256, the counter wraps to zero.
Suppose that you have the following model:

The block parameters are:
| Parameter | Setting |
|---|---|
| Number of Bits | uint8(8) |
| Sample time | -1 |
The solver options for the model are:
| Parameter | Setting |
|---|---|
| Stop time | 254 |
| Type | Fixed-step |
| Solver | discrete (no continuous states) |
| Fixed-step size | 1 |
At t = 254, the counter reaches the maximum value:
uint8(2uint8(8) – 1)
If you change the stop time of the simulation to 255, the counter wraps to zero.
Sample Time | Specified in the Sample time parameter |
Scalar Expansion | No |
Zero-Crossing Detection | No |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |