
This design turns a 50/60 Hz AC tick into a stable HH:MM:SS clock with optional PPS (pulse-per-second) discipline. It drives six 7-segment digits statically using a shared {a,b,c,d,e,f,g} bus and six latch-enable strobes—ideal for simple external latches or 7-seg driver boards.
tt_um_willwhang)Inputs (ui_in)
ui_in[0] – PPS (optional). A rising edge realigns the second boundary (must be ≥ 1 AC tick wide).ui_in[1] – set_mode (1 = set/freeze, 0 = run). In set mode, time doesn’t advance and no cascades occur.ui_in[2] – inc_hours (debounced, edges only in set mode).ui_in[3] – inc_minutes (debounced, edges only in set mode).ui_in[4] – inc_seconds (debounced, edges only in set mode).ui_in[5] – ac50_sel (0 = 60 Hz, 1 = 50 Hz).ui_in[6] – hour_12h (0 = 24 h display, 1 = 12 h display, PM flag active).ui_in[7] – spare.Clock & reset
clk – AC tick: one clean logic pulse per mains cycle (50/60 Hz).
Provide a zero-cross or threshold detector that yields exactly one tick per cycle. If your detector produces 120 Hz (half-cycles, e.g., H11AA1), divide by 2 before feeding
clk.
rst_n – active-low reset.Outputs
uo_out[6:0] – shared 7-seg bus {a,b,c,d,e,f,g} (no decimal points).uo_out[7] – colon LED (toggles each second).uio_out[5:0] – 6 latch-enable strobes in this order: {Ht, Ho, Mt, Mo, St, So}uio_out[6] – PM indicator (1 = PM when hour_12h=1 and hour ≥ 12).uio_out[7] – 1 Hz pulse (one clk-tick wide each second boundary).uio_oe – all 1’s (we always drive uio_out).Segment polarity defaults to active-high (common-cathode). The RTL has parameters to flip polarity if needed.
sec_tick goes high on the very tick the divider hits its terminal count (or when PPS rises). This drives:
sec_tick immediately, aligning second boundaries to PPS.set_mode=1, the divider is frozen; inc_* buttons (debounced) directly wrap their field:
set_mode=0, normal cascades occur on rollovers.00:xx shows 12:xx AM13..23 map to 1..11 PMuio_out[6] (PM) = 1 when hour ≥ 12 in 12 h mode.{a..g} for the next digit,main.v and tb.v in the same directory.iverilog -o sim.vvp main.v tb.v
vvp sim.vvp
# Optional: gtkwave tb.vcd
| # | Input | Output | Bidirectional |
|---|---|---|---|
| 0 | pps input | 7-seg display a | Digit 1 |
| 1 | set mode | 7-seg display b | Digit 2 |
| 2 | increase hours | 7-seg display c | Digit 3 |
| 3 | increase minutes | 7-seg display d | Digit 4 |
| 4 | increase seconds | 7-seg display e | Digit 5 |
| 5 | 50/60Hz selection | 7-seg display f | Digit 6 |
| 6 | hours in 12h display | 7-seg display g | PM indicator |
| 7 | colon LED | PPS out |