Engee documentation

Counter

Direct and reverse counting over a set range of numbers.

blockType: Counter

Path in the library:

/Signal Operations/Signal Management/Switches and Counters/Counter

Description

Block Counter performs forward and reverse counting according to a set range of numbers. The block includes the Inc port (addition) if for the parameter Count direction the value is set Up. If for the parameter Count direction the value is set Down, then the block includes the Dec port (decrease). If for the parameter Count event the value is set Free running, then the block disables the Inc/Dec ports and performs a count at a constant time interval. With any other parameter settings Count event The block increments or decreases the counter each time a trigger event occurs on the input port Inc/Dec. When a start event occurs on the additional port Rst, the block resets the counter to its initial state.

Ports

Output

# Cnt — current counter value
scalar | vector

Details

The current counter value, returned as a scalar or vector. If for the parameter Count event the value is set Free running, then the output of Cnt is a string vector on containing the account value in each of the consecutive sampling points, where — the value specified in the parameter Samples per output frame.

Dependencies

To use this port, set the parameter Output meaning Count or Count and Hit.

Data types

Float16, Float32, Float64, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Bool

Complex numbers support

No

# Hit — match status
scalar | vector

Details

The match status of the integer values specified in the parameter Hit values. When the specified value is found in the counter, the block outputs 1 to the port Hit.

Dependencies

To use this port, set the parameter Output meaning Count or Count and Hit.

Data types

Bool

Complex numbers support

No

Input

# Inc — the input signal for triggering the counting event
scalar | vector

Details

The input signal, specified as a real scalar or vector, is used to increment the counter. If the input signal is a vector, then the block treats the vector as a frame. Each time a trigger event occurs on the input port Inc, the block increments the counter. The type of trigger event is controlled using the parameter Count event.

Dependencies

To use this port, set the parameter Count direction meaning Up.

The block does not use the Inc and Dec ports and calculates at a constant time interval if for the parameter Count event the value is set Free running.

Data types

Float16, Float32, Float64, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Bool

Complex numbers support

No

# Rst — reset signal
scalar

Details

The input signal, set as a real scalar, is used to determine when the counter is reset by the block. The signal on the Rst port must have the same sampling time as the signals on the input ports Inc or Dec. Each time a startup event occurs on the Rst port, the block resets the counter to the initial value.

Dependencies

To use this port, check the box Reset input.

Data types

Float16, Float32, Float64, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Bool

Complex numbers support

No

# Max — maximum counter size
scalar

Details

The maximum size of the counter in the form of any unsigned integer that can represent the parameter Count data type. The counter values vary from 0 up to the value specified as the input to the Max port.

Dependencies

To use this port, set the parameter Counter size meaning Specify via input port.

Data types

Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128

Complex numbers support

No

# Dec — the input signal for triggering the counting event
scalar | vector

Details

The input signal, specified as a real scalar or vector, is used to reduce the counter. If the input signal is a vector, then the block treats the vector as a frame. Each time a trigger event occurs on the input port Dec, the block reduces the counter. The type of trigger event is controlled using the parameter Count event.

Dependencies

To use this port, set the parameter Count direction meaning Down.

The block does not use the Inc and Dec ports and calculates at a constant time interval if for the parameter Count event the value is set Free running.

Data types

Float16, Float32, Float64, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Bool

Complex numbers support

No

Parameters

Main

# Count direction — direct or reverse invoice
Up | Down

Details

Parameter Count direction determines which account will be carried out: direct or reverse. Depending on the value of this parameter, the port Inc (increment) or Dec (decrease) is used.

  • If for the parameter Count direction the value is set Up if the counter reaches the upper limit of the range, then at the next launch event on the Inc port, the block starts counting from zero.

  • If for the parameter Count direction the value is set Down if the counter reaches zero, then at the next launch event on the Dec port, the block starts counting from the maximum range value.

Values

Up | Down

Default value

Up

Program usage name

CountDirection

Tunable

Yes

Evaluatable

No

# Count event — type of launch event
Rising edge | Falling edge | Either edge | Non-zero sample | Free running

Details

Specify the type of event that triggers the block to increase, decrease, or reset the counter when received on ports Inc/Dec or Rst:

  • Rising edge — starts the counting or reset operation when the signal on the input ports Inc/Dec or Rst changes as follows:

    • Increases from the leading edge to positive or zero.

    • Increases from zero to the leading edge when the increase is not a continuation of the increase from the trailing edge to zero, as shown in the figure.

      counter 1

  • Falling edge — starts the counting or reset operation when the signal on the input ports Inc/Dec or Rst changes as follows:

    • It decreases from the leading edge to negative or to zero.

    • Decreases from zero to the trailing edge when the decrease is not a continuation of the decrease from the leading edge to zero, as shown in the figure.

      counter 2

  • Either edge — starts a counting or reset operation when a trigger event occurs on the input ports Inc/Dec or Rst Rising edge or Falling edge.

  • Non-zero sample — starts the counting or reset operation at each sampling clock cycle when the signal on the input ports Inc/Dec or Rst is not zero.

  • Free running — disables the Inc/Dec port and enables the block parameters Samples per output frame and Sample time. The block increments or decreases the counter at a constant interval , which is set using the parameter Sample time. In this mode, the block resets the counter whenever it receives a non-zero sample on the Rst port.

Dependencies

When the parameter Count event it matters Free running, the block disables the Inc/Dec port and increments or decreases the counter at a constant interval specified in the parameter Sample time.

Values

Rising edge | Falling edge | Either edge | Non-zero sample | Free running

Default value

Rising edge

Program usage name

CountEvent

Tunable

No

Evaluatable

No

# Counter size — range of integer values to count
8 bits | 16 bits | 32 bits | User defined | Specify via input port

Details

Specify the range of integer values that the block counts by. If the block counts the entire range of the counter, then the next time a launch event occurs on the Inc/Dec port, the block resets the counter as follows:

  • If for the parameter Count direction it matters Up When the counter reaches the upper limit of the counter range, the block starts counting from zero.

  • If for the parameter Count direction it matters Down when the counter reaches zero, the block starts counting from the maximum value of the range.

For the parameter Counter size you can set one of the following values:

  • 8 bits — sets a counter with a range from 0 before 255.

  • 16 bits — sets a counter with a range from 0 before 65535.

  • 32 bits — sets a counter with a range from 0 before 232-1.

  • User defined — enables the parameter Maximum count, which allows you to specify the upper limit of the count in the form of any arbitrary unsigned integer that can be represented by the parameter Count data type. The counter values vary from 0 before the parameter value Maximum count.

  • Specify via input port — includes the Max input port, which allows you to specify the upper limit of the bill in the form of an arbitrary unsigned integer, which can be represented by the parameter Count data type. The counter values vary from 0 up to the value specified as the input parameter of the Max port.

Values

8 bits | 16 bits | 32 bits | User defined | Specify via input port

Default value

User defined

Program usage name

CounterSize

Tunable

No

Evaluatable

No

# Maximum count — maximum counter value
Int64 integer

Details

Specify the maximum counter value as an arbitrary unsigned integer that can be represented by the parameter Count data type.

Dependencies

To use this parameter, set for the parameter Counter size meaning User defined.

Default value

255

Program usage name

MaximumCount

Tunable

Yes

Evaluatable

Yes

# Initial count — the initial value of the counter
Int64 integer

Details

Specify the initial value of the counter as any unsigned integer in the range defined by the parameter Counter size. The block uses the initial value of the counter at the beginning of the simulation and resets the counter back to this initial value each time a trigger event occurs on the Rst port.

Default value

0

Program usage name

InitialCount

Tunable

Yes

Evaluatable

Yes

# Output — score value, hit value, or both values
Count | Hit | Count and Hit

Details

Select which output ports to use. Acceptable parameter values for ports: Count, Hit or Count and Hit.

Values

Count | Hit | Count and Hit

Default value

Count and Hit

Program usage name

Output

Tunable

No

Evaluatable

No

# Hit values — counting values for tagging
Scalar / vector of Int64

Details

Specify the integer or vector of integers that should be marked in the counter. 1 on the output port Hit.

Dependencies

To use this parameter, set for the parameter Output meaning Hit or Count and Hit.

Default value

32

Program usage name

HitValues

Tunable

Yes

Evaluatable

Yes

# Reset input — enabling the Rst input port
Logical

Details

Select this option to enable the Rst input port. When the Rst port is turned on, the block resets the counter to the initial value each time a startup event occurs on the Rst port. The type of event that causes the counter reset is set in the parameter Count event. If you uncheck the box Reset input It will not be possible to reset the counter during simulation.

Default value

true (switched on)

Program usage name

ResetInput

Tunable

No

Evaluatable

No

# Samples per output frame — the number of samples in each output vector
Int64 integer

Details

Specify the number of samples in each output vector as a positive integer.

Dependencies

To use this parameter, set for the parameter Count event meaning Free running.

Default value

1

Program usage name

SamplesPerOutputFrame

Tunable

No

Evaluatable

Yes

# Sample time — sampling time in the mode Free running
Real number

Details

Specify a constant interval , through which the block increments or decreases the counter in the mode Free running. Acceptable parameter values:

  • a non-negative scalar — a scalar that is greater than or equal to zero.

  • -1 — inheritance of sampling time.

For example, so that the block increments the counter every 5 seconds, set for the parameter Count direction meaning Up, for the parameter Count event meaning Free running, and for the parameter Sample time specify the value 5. In the mode Free running the sampling time of the output ports is always equal to .

Dependencies

To use this parameter, set for the parameter Count event meaning Free running.

Default value

1.0

Program usage name

SampleTime

Tunable

No

Evaluatable

Yes

# Count data type — port data type Cnt
double | single | int8 | uint8 | int16 | uint16 | int32 | uint32

Details

Specify the type of data to output to the Cnt port.

Dependencies

To use this parameter, set for the parameter Output meaning Count or Count and Hit.

Values

double | single | int8 | uint8 | int16 | uint16 | int32 | uint32

Default value

double

Program usage name

CountDataType

Tunable

No

Evaluatable

No

Algorithms

Scalar input operation

If set for the parameter Count direction meaning Up, the trigger event on the input port Inc (increment) causes the block to increment the counter by one. If there are no reset events, the block continues to increase the counter value at an event on the Inc port until the counter value reaches the upper limit of the count. At the next startup event on the Inc port, the block restarts the counter with 0 and resumes incrementing the counter by one at each subsequent launch event on the Inc port.

If set for the parameter Count direction meaning Down, the trigger event on the input port Dec (decrease) causes the block to decrease the counter by one. If there are no reset events, the block continues to decrease the counter value when an event occurs on the port. Down, until the counter value reaches 0. At the next launch event on the Dec port, the block restarts the counter from the upper limit of the count and resumes decreasing the counter by one at each subsequent launch event on the Dec port.

Between startup events, the block holds the output at its last value. The block resets the counter to its initial state when a trigger event occurs on the additional input port Rst, specified by the parameter Count event. If ports Inc/Dec and Rst receive trigger events at the same time, the block first resets the counter, and then increases or decreases it accordingly. To disable counter reset during simulation, disable the Rst port by unchecking Reset input.

Parameter Output allows you to specify which values the block outputs.:

  • Count enables the Cnt output port on the unit. The Cnt port provides the current counter value as a scalar. The output port Cnt has the same sampling time as the input port Inc/Dec.

  • Hit enables the output port Hit on the block. Port Hit returns zeros if the counter value is not equal to any of the integers specified in the parameter. Hit values. For the parameter Hit values you can specify an integer or a vector of integers. When the counter value is equal to one or more values specified for the parameter Hit values, the block outputs the value 1 to the output port Hit. Output port Hit it has the same sampling time as the input port Inc/Dec.

  • Count and Hit enables both output ports Cnt and Hit.

Vector input operation

The block treats vector input data to the Inc/Dec port as a frame. Working with a vector is similar to working with a scalar, except that the block increments or decreases the counter by the total number of trigger events contained in the input vector Inc/Dec. Thus, the counter can be changed several times during the processing of a single input vector Inc/Dec.

If the block has a port Hit, it outputs the value 1 if any of the values Hit matches any of the counter values during processing of the input vector Inc/Dec.

If a trigger event occurs between two consecutive vectors, this event is counted in the vector that contains the completion of the event. When the Rst port receives a trigger event at the same time as the Inc/Dec port, the block first resets the counter. The block then increments or decrements the counter by the number of trigger events contained in the input vector Inc/Dec.

If the input signal of the Inc/Dec port is a vector string on , the sampling time of the input port Inc/Dec is equal to the frame period of the input signal or a multiple of the sampling time of the input signal. Port sampling time of the output ports Cnt and Hit is equal to the sampling time of the input port Inc/Dec.

Automatic billing

The block works in the automatic counting mode if for the parameter Count event the value is set Free running.

The input port Inc/Dec is disabled in this mode, and the unit increments or decreases the counter at a constant interval. , which is set in the parameter Sample time.

In this mode, the Rst port always behaves as if the parameter Count event was set to the value Non-zero sample. Thus, the block triggers a reset event at each sampling time when the input port Rst is not zero.

In this mode, the output of Cnt is a vector string. on containing the account value in each of the consecutive sampling points, where — the value set for the parameter Samples per output frame. Output port Hit — this is a vector string on , containing the match status (0 or 1) in each of the consecutive sampling points. Both output ports are Cnt and Hit have a port sampling time .