← ProblemsCircuits / Sequential Logic / Counters
4-digit decimal counter
15%countersvectorsBuild a 4-digit BCD (binary-coded decimal) counter. Each decimal digit occupies one nibble of q:
q[3:0]— ones digitq[7:4]— tens digitq[11:8]— hundreds digitq[15:12]— thousands digit
The ones digit increments every clock cycle; each upper digit increments only when all digits below it wrap. Also output the increment enables for the upper three digits, derived combinationally from the current count:
ena[1] = 1when the ones digit equals 9ena[2] = 1when the ones and tens digits both equal 9ena[3] = 1when the ones, tens, and hundreds digits all equal 9
reset is synchronous, active-high, and clears the count to 0000.