← ProblemsCircuits / Sequential Logic / Counters

12-hour clock

5%countersvectors

Build a 12-hour wall clock with an AM/PM indicator. Hours (hh), minutes (mm), and seconds (ss) are each two BCD digits packed in 8 bits:

  • hh counts 01–12 (BCD, so 8'h12 means 12)
  • mm and ss count 00–59
  • pm is 0 for AM, 1 for PM

ena advances the clock by one second whenever it is 1. reset is synchronous, active-high, has priority over ena, and sets the time to 12:00:00 AM (pm = 0).

Careful with the hour rollovers: 12 is followed by 01 (with no AM/PM change), and pm toggles on the transition 11:59:59 → 12:00:00.