Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

COUNTER - Up/Down pulse counter

Each counter block, when enabled, can count up/down with user-defined step value on the rising edge on input trigger. The counters can also be initialised to a user-defined START value.

Fields

NameTypeDescription
ENABLEbit_muxHalt on falling edge, reset and enable on rising
TRIGbit_muxRising edge ticks the counter up/down by STEP
DIRbit_muxUp/Down direction (0 = Up, 1 = Down)
TRIG_EDGEparam enumINP trigger edge
OUT_MODEparam enumCounter OUT update mode (on internal counter value change or on ENABLE falling edge)
SETparam intset current value of a counter
STARTparam intCounter start value
STEPparamUp/Down step value
MAXparam intRollover value
MINparam intValue to which counter should rollover to
CARRYbit_outInternal counter overflow status
OUTpos_outCurrent counter value

Counting pulses

The most common use of a counter block is when you would like to track the number of trigger edges received while enabled:

Count Up only when enabled

The TRIG_EDGE field can be used to select the track on rising, falling, or both edges:

Setting trigger edge

You can also set the start value to be loaded on enable, and step up by a number other than one:

Non-zero start and step values

You can also set the direction that a pulse should apply step, so it becomes an up/down counter. The direction is sampled on the same clock tick as the pulse edge:

Setting direction

When the OUT_MODE is set to On-Disable, the OUT output will only be changed to the internal counter value on ENABLE’s falling edge:

On-Disable mode counting

Rollover

If the count goes higher than the max value for an int32 (2147483647) the CARRY output gets set high and the counter rolls. The CARRY output stays high for as long as the trigger input stays high.

Overflow

A similar thing happens for a negative overflow:

Overflow negative

When the OUT_MODE is set to On-Disable, the CARRY output will get set to high on ENABLE’s falling edge if any overflow produced while the counter was enabled:

On-Disable mode counting with overflow

Edge cases

If the Enable input goes low at the same time as a trigger, there will be no output value on the next clock tick.

Disable and trigger

If the step size is changed at the same time as a trigger input edge, the output value for that trigger will be the new step size.

Change step and trigger