Engee documentation

Counter

Forward and backward counting over a given range of numbers.

counter

Description

The Counter block performs forward and backward counting over a specified range of numbers. The block enables the Inc port (addition) if the Count direction parameter is set to Up. If the Count direction parameter is set to Down', the block enables the Dec (decrease) port. If the Count event parameter is set to `Free running, the block disables the Inc/Dec ports and counts at a constant time interval. With any other setting of the Count event parameter, the block increments or decrements the count each time a startup event occurs on the Inc/Dec input port. When a start event occurs on the Rst auxiliary port, the unit resets the counter to its initial state.

Ports

Input

Inc/Dec - input signal to trigger a counting event
scalar | vector

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

Dependencies

  • The block enables the Inc (add) port when the Count direction parameter is set to Up.

  • The unit enables the Dec (decrease) port when the Count direction is set to `Down'.

  • The unit does not use the Inc and Dec ports and counts at a constant time interval if the Count event parameter is set to `Free running'.

Data types: Float16, Float32, Float64, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Bool.

Rst - reset signal
scalar

The input signal, specified as a real scalar, is used to determine when the counter is reset by the block. The Rst port must have the same sample time as the Inc/Dec input port. Each time a start event occurs on the Rst port, the block resets the counter to the initial value.

Dependencies

To enable this port, select the Reset input checkbox.

Data types: Float16, Float32, Float64, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Bool.

Max - maximum counter size
scalar

The maximum size of the counter as any unsigned integer that the Count data type parameter can represent. The counter values range from 0 to the value that is specified as an input to the Max port.

Dependencies

To enable this port, set the Counter size parameter to Specify via input port.

Data types: Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128.

Output

Cnt - current value of the counter
scalar | vector

The current value of the counter, specified as a scalar or vector. If the Count event parameter is set to Free running, the output signal Cnt is a vector string M by 1 containing the count value at each of M consecutive sampling moments, where M is the value specified in the Samples per output frame parameter.

Dependencies

To enable this port, set the Output parameter to Count or Count and Hit.

Data types: Float16, Float32, Float64, Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128, Bool.

Hit - match status
scalar | vector

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

Dependencies

To enable this port, set the Output parameter to Count or Count and Hit.

Data types: Bool.

Parameters

Count direction - forward or reverse counting
Up (by default) | Down

The Count direction parameter determines whether the count is forward or reverse. Depending on the value of the parameter, the port label on the block changes to Inc (increment) or Dec (decrement).

  • If Count direction is set to Up and the counter reaches the upper limit of the range, the block starts counting from zero at the next start event on the Inc port.

  • If Count direction is set to `Down' and the counter reaches zero, the next start event on the Dec port will cause the unit to start counting from the maximum value of the range.

Count event - type of trigger event
Rising edge (by default) | Falling edge | Either edge | Non-zero sample | Free running.

Specify the type of event that triggers the unit to increment, decrement or reset the counter when Inc/Dec or Rst is received on the Inc or Rst ports:

  • Rising edge - triggers a count up or reset operation when the signal on the Inc/Dec or Rst input ports changes as follows:

    • Rises from rising edge to positive or zero.

    • Rises from zero to rising edge when the rise is not a continuation of the rise from trailing edge to zero as shown.

counter 1

  • Falling edge - Starts a count or reset operation when the signal at the Inc/Dec or Rst input ports changes as follows:

    • Decreases from the rising edge to negative or 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.

counter 2

  • Either edge - Triggers a count or reset operation when a Rising edge or Falling edge trigger event occurs on the Inc/Dec or Rst input ports.

  • Non-zero sample - starts a count or reset operation at each sample clock when the signal at the Inc/Dec or Rst input ports is not zero.

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

Dependencies

When the Count event parameter is set to Free running, the block disables the Inc/Dec port and increments or decrements the counter at the constant interval specified by the Sample time parameter.

Counter size is the range of integer values to be counted
8 bits (by default) | 16 bits | 32 bits | User defined | Specify via input port.

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

  • If Up is set for the Count direction parameter and the counter reaches the upper limit of the counter range, the block starts counting from zero.

  • If Count direction is set to Down and the counter reaches zero, the block starts counting from the maximum value of the range.

The Counter size parameter can be set to one of the following values:

  • 8 bits - sets the counter with a range from 0 to 255.

  • 16 bits - sets the counter with the range from 0 to 65535.

  • 32 bits - specifies a counter with a range from 0 to 232-1.

  • User defined - includes the Maximum count parameter, which allows you to specify an upper count limit in the form of any arbitrary unsigned integer, which can be represented by the Count data type parameter. The count values range from 0 to the value of the Maximum count parameter.

  • Specify via input port - enables the Max input port, which allows you to specify the upper count limit as an unsigned arbitrary integer, which can be represented by the Count data type parameter. The count values range from 0 to the value specified as the Max input port parameter.

Maximum count is the maximum value of the counter
255 (by default) | positive integer.

Specify the maximum count value as an unsigned arbitrary integer, which can be represented by the Count data type parameter.

Dependencies

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

Initial count is the initial value of the counter
0 (by default) | non-negative integer.

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

Output is the count value, the hit value, or both values
Count (by default) | Hit | Count and Hit

Select which output ports to activate (or enable). Valid parameter values for the ports are Count, Hit or Count and Hit.

Hit values - counting values for marking
32 (by default) | scalar | vector.

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

Dependencies

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

Reset input - Enable input port Rst
enabled (by default) | disabled.

Select this checkbox to enable the Rst input port. When the Rst port is enabled, 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 to reset is set in the Count event parameter. If Reset input is unchecked, the counter cannot be reset during simulation.

Samples per output frame - number of samples in each output vector
1 (by default) | positive integer.

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

Dependencies

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

Sample time - sampling time in Free Running mode
1 (by default) | -1 | non-negative scalar

Specify a constant interval , at which the block increments or decrements the counter in Free Running mode. Valid values of the parameter:

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

  • -1 - sampling time inheritance.

For example, to have the block increment the counter every 5 seconds, set the Count direction parameter to Up, the Count event parameter to Free running, and the Sample time parameter to 5. In the Free Running mode, the sampling time of the output ports is always equal to .

Dependencies

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

Count data type - Port data type Cnt
double (default) | single | int8 | uint8 | int16 | uint16 | int32 | uint32

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

Dependencies

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

Hit data type - Hit port data type
Logical (By default) | Bool.

Algorithms

Scalar input operation

When Count direction is set to Up, a start event on the Inc input port (addition) causes the block to increment the counter by one. Provided there are no reset events, the block continues to increment the counter value with an event on the Inc port until the counter value reaches the upper count limit. On the next start event on the Inc port, the block restarts the counter from 0 and resumes incrementing the counter by one on each subsequent start event on the Inc port.

If the Count direction parameter is set to Down, a startup event on the Dec (decrease) input port causes the block to decrease the counter by one. Provided there are no reset events, the block continues to decrease the counter value on a Down port event until the counter value reaches the value 0. On the next start event on the Dec port, the block restarts the counter from the upper count limit and resumes decrementing the counter by one on each subsequent start 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 the startup event specified by the Count event parameter occurs on the optional Rst input port. If the Inc/Dec and Rst ports receive trigger events at the same time, the block resets the counter first and then increments or decrements it accordingly. To disable resetting the counter during simulation, you must disable the Rst port by unchecking Reset input.

The Output parameter allows you to specify what values the block outputs:

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

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

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

Vector input operation

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

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

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

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

Automatic counting

The unit operates in automatic counting mode if the Count event parameter is set to Free running.

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

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

In this mode, the Cnt output is a vector string by 1 containing the count value at each of consecutive sample moments, where is the value set for the Samples per output frame parameter. The Hit output port is a vector string by 1 containing the match status (0 or 1) at each of consecutive sampling moments. Both output ports Cnt and Hit have a port sampling time of .