How to Create a 4-bit Counter Configuration

Last modified by Microchip on 2025/01/02 09:46

Overview

A digital counter is an electronic circuit that counts electrical pulses, representing the occurrence of specific events and displays the count in a digital format. As a fundamental component in digital systems, digital counters are essential for applications like timekeeping, frequency measurement, and event counting, where precision and reliability are critical. This counter operates unidirectionally and includes enable and reset functionality.

This design includes two inputs—reset and enable—and four outputs. The reset input connects to the reset pins of all D flip-flops, while the enable input connects to their enable pins. Each flip-flop's output is fed into an XOR gate and an AND gate, which then connect to the next XOR gate in the sequence. For the first XOR gate, a logic high is used instead of an input, creating a structure similar to a half-adder circuit.

MPLAB Melody 4-bit Counter Schematic

Figure 1

Requirements

Procedure

Implement the CLB Logic

Configure the CLB to implement the equivalent logic for the 4-bit counter. Refer to Figure 1 for guidance.

Information

Note: If using MPLAB® Code Configurator (MCC), use the CLB Synthesizer tool or download the pre-configured CLB file.

Back to Top


Select a Clock Source for the CLB

Any clock source can be used for the CLB, but it affects how fast the counter increments. Choose based on your application's timing needs.

Back to Top


Assign the Pins

Assign the input pins for the reset and enable signals and connect the output pins for the counter to the desired locations on your hardware.

Back to Top


Verify the Design

Confirm the counter functionality using a debugging tool to ensure proper operation.

Back to Top

Results

Figure 2 illustrates the operation of a 4-bit counter. The reset initializes the counter, enable activates counting, and the four bits (D2-D5) toggle at frequencies corresponding to their binary weight, forming the incremental count sequence.

4-bit Counter Waveforms

Figure 2

Back to Top

Learn More

Back to Top