← ProblemsCircuits / Sequential Logic / Counters
12-hour clock
5%countersvectorsBuild 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:
hhcounts 01–12 (BCD, so8'h12means 12)mmandsscount 00–59pmis 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.