Main Content

dsp.Counter

(Removed) Count up or down through specified range of numbers

dsp.Counter has been removed. Alternatively, you can create a variable in MATLAB® and increment the variable by 1.

Description

The Counter object counts up or down through a specified range of numbers.

To count up or down through a specified range of numbers:

  1. Create the dsp.Counter object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

Creation

Description

count = dsp.Counter returns a counter System object™, count, that counts up when the input is nonzero.

example

count = dsp.Counter(Name,Value) returns a counter System object, count, with each specified property set to the specified value.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Specify the counter direction as Up or Down.

Tunable: Yes

Set this property to true to enable a count event input for the internal counter. The internal counter increments or decrements whenever the count event input satisfies the condition you specify in the CountEventCondition property. When you set this property to false, the internal counter is free running, that is, the counter increments or decrements on every call to the object algorithm.

Specify the event at the count event input that increments or decrements the counter as Rising edge, Falling edge, Either edge or Non-zero.

If you set the ResetInputPort and CountEventInputPort properties to true, the counter is reset when the event you specify for the CountEventCondition occurs.

Dependencies

This property applies only when you set the CountEventInputPort property to true.

Specify the source of the counter size data type as Property or Input port.

Specify the range of integer values to count through before recycling to zero as 8 bits, 16 bits, 32 bits or Maximum.

Specify the counter's maximum value as a numeric scalar value.

Tunable: Yes

Dependencies

This property applies only when you set the CounterSizeSource property to Property and the CounterSize property to Maximum.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Specify the initial value for the counter.

Tunable: Yes

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Set this property to true to enable output of the internal count. The default is true. You cannot set both CountOutputPort and HitOutputPort to false at the same time.

Set this property to true to enable output of the hit events. You cannot set both CountOutputPort and HitOutputPort to false at the same time.

Specify an integer scalar or a vector of integers, whose occurrences in the count you want flagged as a hit.

Dependencies

This property applies only when you set the HitOutputPort property to true.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

When you set this property to true, specify a reset input to the object algorithm. When the reset input receives the event you specify for the CountEventCondition property, the counter resets. If you set the CountEventInputPort property to false, the counter resets whenever the reset input is not zero.

Specify the number of samples in each output frame.

Dependencies

This property applies only when you set the CountEventInputPort property to false, indicating a free-running counter.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Specify the data type of the count output, cnt, as double, single, int8, uint8, int16, uint16, int32 or uint32.

Dependencies

This property applies when you set the CountOutputPort property to true.

Usage

Description

[cnt,hit] = count(event,reset) increments, decrements, or resets the internal counter as specified by the values of the event and reset inputs. The output argument cnt denotes the present value of the counter. A trigger event at the event input causes the counter to increment or decrement. A trigger event at the reset input resets the counter to its initial state.

cnt = count(event,reset) returns the current value of the count when you set the CountOutputPort property to true and the HitOutputPort property to false.

hit = count(event,reset) returns a Boolean value indicating whether the count has reached any of the values specified by the HitValues property. This condition applies when you set the HitOutputPort property to true and the CountOutputPort property to false.

[___] = count() increments or decrements the free-running internal counter when you set the CountEventInputPort property to false and the ResetInputPort property to false.

example

[___] = count(event) increments or decrements the internal counter when the event input matches the event you specify for the CountEventCondition property and you set the ResetInputPort property to false.

Input Arguments

expand all

Event that causes the counter to increment or decrement, specified as a scalar. The CountEventCondition property specifies the event under which the counter value changes.

Dependencies

This input is valid only when CountEventInputPort is set to true.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

A trigger event at the reset input resets the counter to the initial state.

Dependencies

This input is valid only when ResetInputPort is set to true.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

Output Arguments

expand all

Current value of the count, returned as a scalar. The data type of this output is set by the CountOutputDataType property. If CountEventInputPort is false, the number of elements in this output vector is determined by the value you specify in the SamplesPerFrame property.

Dependencies

This output is enabled only when you set the CountOutputPort property to true.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Boolean value indicating whether the count has reached any of the values specified by the HitValues property. If CountEventInputPort is false, the number of elements in this output vector is determined by the value you specify in the SamplesPerFrame property.

Dependencies

This output is enabled when you set the HitOutputPort property to true.

Data Types: logical

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

Use dsp.Counter System object to count at every rising edge of the input signal.

count = dsp.Counter('MaximumCount', 5, ...
    'CountOutputPort', true, ...
    'HitOutputPort', false, ...
    'ResetInputPort', false);
sgnl = [0 1 0 1 0 1 0 1 0 1 0 1 ];
cnt = zeros(1,12);
for ii = 1:length(sgnl)
    cnt(ii) = count(sgnl(ii));
end
disp(cnt);
     0     1     1     2     2     3     3     4     4     5     5     0

Algorithms

This object implements the algorithm, inputs, and outputs described on the Counter block reference page. The object properties correspond to the block parameters.

  • The CountEventCondition object property does not have a free-running option. Set the CountEventInputPort property to false to obtain the free-running option.

  • The CounterSizeSource and CounterSize object properties correspond to the Counter size block parameter.

  • The CountOutputPort and HitOutputPort correspond to the Output block parameter.

  • There is no object property that corresponds to the Hit data type block parameter. The output type is logical in MATLAB. (This logical is different from the popup logical in the block. For the object, logical corresponds to Boolean in the block.)

Extended Capabilities

Version History

Introduced in R2012a

expand all

R2023a: dsp.Counter System object has been removed

The dsp.Counter System object has been removed. Alternatively, you can create a variable in MATLAB and increment the variable by 1.