Template: 4-Bit Binary Counter
Template: Template: 4-Bit Binary Counter - Interactive 4-bit binary counter with visual output lights. Learn binary counting sequences and clock-driven operation. Count from 0 to 15 in binary.
배울 내용
- Build a 4-bit counter that increments by 1 each clock edge.
- Cycle through 16 states from 0000 to 1111 then wrap.
- Distinguish synchronous (all bits clock together) from asynchronous (ripple) counters.
- Recognize that bit i toggles when all lower bits are 1.
- Apply 4-bit counters to timers, address generators, and frequency dividers.
작동 원리
A 4-bit binary counter counts clock pulses through values 0 to 15, incrementing by 1 each clock edge, then wrapping back to 0. The four flip-flops together hold the count; each new clock edge drives an adder (or toggle logic) that produces count+1.
In the synchronous form, all four flip-flops share the same clock — every bit updates simultaneously. The next-state logic for each bit i is: bit i toggles when all lower bits are 1 (i.e., AND of bits 0..i-1). This is the binary increment pattern.
In the asynchronous (ripple) form, each bit's toggle is clocked by the bit below it — simpler wiring but staggered timing.
The counter sequence: 0000 → 0001 → 0010 → ... → 1110 → 1111 → 0000 (wrap). One full cycle of bit 3 takes 16 clock pulses.
Counters are foundational to digital design — every timer, every program counter, every memory address generator is essentially a counter. Modern CPUs include dedicated counter cells in their standard libraries, often with parallel-load and reset for flexible initialization.
단계별로 시도해 보세요
위 임베드에서 입력을 설정한 후, 예상 결과를 읽고 직접 확인하세요.
- 1Clock = running예상:
Output cycles 0, 1, 2, ..., 15, 0, 1, ...관찰 포인트: Watch the binary lights and digit display. Each clock edge increments by 1; after 1111 (15) it wraps to 0000. - 2Clock = stopped at 0101예상:
Counter holds at 5관찰 포인트: Stop the clock — counter freezes at whatever value it had. Sequential logic needs a clock to evolve. - 3Clock = after 8 edges예상:
Bit 3 first lights up at the 8th edge관찰 포인트: Bit 3 (the MSB) only goes high when the count reaches 8 — the upper-half threshold. - 4Clock = after 16 edges예상:
Counter wraps to 0000관찰 포인트: 16 edges complete one full cycle. The counter rolls over from 1111 to 0000 with no special intervention.
사용된 구성 요소
실제 응용 사례
CPU program counter. The PC is essentially a counter that increments by the instruction width on each fetch.
Timer/counter peripherals. Microcontrollers have multiple hardware counters for precise timing of events, PWM generation, and pulse measurement.
Address generation in memory tests. ATE (test equipment) walks through memory addresses using a counter to write/read each cell during march tests.
Frequency divider chains. Cascading counters divide a master oscillator down to lower-frequency clocks for various subsystems.
Sequential state encoding. State machines with linearly progressing states often use a counter-based state register for simplicity.