From WikiChip
Counter
Revision as of 23:30, 27 August 2017 by David (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

A counter is a device (i.e., digital circuit) that increments or decrements a stored value (e.g., in a register) upon the occurrence of a certain event or condition such as on a clock edge. Counters are used extensively in digital electronics for a plethora of reasons.

  • An "up counter" increments its value on each clock pulse.
  • A "down counter" decrements its value on each clock pulse.
  • An "up/down counter", also called a bidirectional counter, counts both up and down (but not at the same time).

Usually the program counter (PC) is implemented as an up counter, so that it can be incremented at the same time that data is being processed by the ALU.

Many modern CPUs have a variety of "performance counters" useful in profiling.

Most modern computer systems have a timer -- a counter driven by the main clock -- to generate regular timing pulses that interrupt the CPU for pre-emptive multitasking.

Many modern microcontrollers have a few "timer/counter" peripherals that can be set up to count pulses from some external peripheral, generate PWM waveforms, or similar tasks.

Many counter circuits are "binary counters" -- it counts in natural binary -- 0, 1, 10, 11, 100, ... up to an all-ones state, and then roll over back to 0. The decade counters, also called "binary coded decimal" counters, use the same sequence, but each block of 4 bits only counts up to 1001 (9) before rolling over to 0.

A few counters use a very different counting sequence -- a linear feedback shift register (LFSR) counter, a ring counter, a Johnson counter, a gray-code counter, etc.

A binary up-counter can be seen as a simplified adder (one data input hard-wired to +1), similar to the way an adder can be seen as a simplified arithmetic logic unit (the function control input hard-wired to addition).