dsp.Counter System object

Package: dsp

Count up or down through specified range of numbers

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. Define and set up your counter. See Construction.

  2. Call step to count up or down according to the properties of dsp.Counter. The behavior of step is specific to each object in the toolbox.

Construction

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

H = dsp.Counter('PropertyName',PropertyValue,...) returns a counter System object, H, with each specified property set to the specified value.

Properties

Direction

Count up or down

Specify the counter direction as Up or Down. The default is Up. This property is tunable.

CountEventInputPort

Add input to specify a count event

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 step method. The default is true.

CountEventCondition

Condition that increments, decrements, or resets internal counter

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. This property applies only when you set the CountEventInputPort property to true.

CounterSizeSource

Source of counter size data type

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

CounterSize

Range of integer values to count through

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

MaximumCount

Counter's maximum value

Specify the counter's maximum value as a numeric scalar value. This property applies only when you set the CounterSizeSource property to Property and the CounterSize property to Maximum. The default is 255. This property is tunable.

InitialCount

Counter initial value

Specify the initial value for the counter. The default is 0. This property is tunable.

CountOutputPort

Output count

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.

HitOutputPort

Output hit events

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. The default is true.

HitValues

Values whose occurrence in count produce a true hit output

Specify an integer scalar or a vector of integers, whose occurrences in the count you want flagged as a hit. This property applies only when you set the HitOutputPort property to true.

ResetInputPort

Add input to enable internal counter reset

When you set this property to true, specify a reset input to the step method. 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.

SamplesPerFrame

Number of samples in each output frame

Specify the number of samples in each output frame. This property applies only when you set the CountEventInputPort property to false, indicating a free-running counter. The default is 1.

CountOutputDataType

Data type of count output

Specify the data type of the count output, CNT, as double, single, int8, uint8, int16, uint16, int32 or uint32. This property applies when you set the CountOutputPort property to true. The default is double.

Methods

cloneCreate counter object with same property values
getNumInputsNumber of expected inputs to step method
getNumOutputsNumber of outputs of step method
isLockedLocked status for input attributes and nontunable properties
releaseAllow property value and input characteristics changes
resetReset internal states of Counter object
stepIncrement or decrement the internal counter

Examples

Use Counter System object for counting from 0 to 5:

     hcounter = dsp.Counter('MaximumCount', 5, ...
     'CountOutputPort', true, ... 
     'HitOutputPort', false, ... 
     'ResetInputPort', false);
      sgnl = [0 1 0 1 0 1 0 1 0 1 0 1 ];
        for ii = 1:length(sgnl)
      %count at every rising edge of the input signal.
      cnt(ii) = step(hcounter, sgnl(ii)); 
        end
        cnt 

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.)

Was this topic helpful?