Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# Counter Free-Running

Count up and overflow back to zero after reaching maximum value for specified number of bits

Sources

## Description

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.

## Data Type Support

The Counter Free-Running block outputs an unsigned integer.

## Parameters and Dialog Box

Number of Bits

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

Sample time

Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See Specify Sample Time in the Simulink documentation.

## Examples

### Bit Specification Using a Positive Integer

Suppose that you have the following modelmodel:

The block parameters are:

ParameterSetting
Number of Bits8
Sample time-1

The solver options for the model are:

ParameterSetting
Stop time255
TypeFixed-step
Solverdiscrete (no continuous states)
Fixed-step size1

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.

### Bit Specification Using an Unsigned Integer Expression

Suppose that you have the following modelmodel:

The block parameters are:

ParameterSetting
Number of Bitsuint8(8)
Sample time-1

The solver options for the model are:

ParameterSetting
Stop time254
TypeFixed-step
Solverdiscrete (no continuous states)
Fixed-step size1

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.

## Characteristics

 Sample Time Specified in the Sample time parameter Scalar Expansion No Zero-Crossing Detection No