CodiodeCodiode
Home
Problem Solving
Skill Tracks
My Assignments
Contests
Leaderboard
Community
Settings
Codiode/Problems/Sequential Logic

4-Bit Up/Down Counter Using D Flip-Flops: K-Map Derivation

HardLogic CircuitBuild

Bi-directional state machines appear in PWM controllers, motor position trackers, and reversible timers. A 4-bit up/down counter built from D flip-flops requires full next-state derivation rather than the simple toggle conditions used in T flip-flop designs.

The circuit must track a 4-bit state Q consisting of Q3, Q2, Q1, and Q0. It increments by one on the rising clock edge when dir is 1, and decrements by one when dir is 0. A synchronous active-high rst signal forces the state to 0000.

Because the next state depends on the current state and the direction, the D flip-flop excitation equations require evaluating a 5-variable logic function. The table below outlines key state transitions.

| dir | Q3 | Q2 | Q1 | Q0 | D3 | D2 | D1 | D0 | |-------|------|------|------|------|------|------|------|------| | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 0 | | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |

Constraints

  • Use exactly four D flip-flops.
  • Implement the next-state logic using basic combinational gates (AND, OR, NOT, XOR).
  • Do not use pre-built counter modules or arithmetic adders.
  • Implement rst as a synchronous active-high reset.

Topics

sequentialk-mapcountersd-flip-flop

Solve this problem

Place the gates, wire them up and watch the signals settle. Every submission runs on the same simulation engine that grades it.

This problem is part of Codiode Pro. The statement above is free to read.

Sign in to solveSee what Pro unlocks

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Related problems

  • 3-bit Ripple Counter from Toggle Flip-FlopsEasy
  • D Latch from a 2:1 MUXEasy
  • 2-bit Ring CounterEasy
  • T Flip-Flop from a D Flip-FlopEasy
  • Handshake Deadlock Due to Early ResetHard
  • Reconvergence of Individually Synchronized BitsHard
  • Debug: Asynchronous Clear GlitchHard
  • Clock Gate Enable Crossing DomainsHard

Browse all problems · Learning tracks