G6.5.1 Up/Down Seconds Counter with Carry

MediumImplementIcarus Verilog + Yosys · serverReview the topic

Build a BCD seconds counter that counts up or down, with a carry that marks each wrap.

Hardware context: A kitchen timer's BCD seconds counter that counts up or down with a carry, and a display line counter with clear, load and enable that loses a line every frame. Build a 00 to 59 BCD seconds counter that counts both ways, with a combinational carry.

A kitchen timer shows seconds as two digits, 00 to 59. Each digit drives its own display, so the count is BCD. The user sets the time by counting up, then the timer counts down. The minutes counter needs a carry in the cycle where the seconds are about to wrap, either way.

This is an Implement problem. The starter counts up only and has no carry. Complete sec60. The check runs 72 edges per case, with en and up changing, and records the count every ninth edge.

Signals in the Timeline

SignalWidthRole
script80input of each check
Full specification
The module (keep the name and the ports)
module sec60 (
  input  logic       clk,
  input  logic       clr,     // synchronous clear: 00
  input  logic       en,      // 1: count one second at this edge
  input  logic       up,      // 1: count up, 0: count down
  output logic [3:0] ones,    // 0 to 9
  output logic [2:0] tens,    // 0 to 5
  output logic       tc       // 1 while en = 1 and the next edge wraps (59 going up, 00 going down)
);
  ...
endmodule
At a rising edgeEffect
clr = 1ones = 0, tens = 0
otherwise, en = 1 and up = 1the count goes up one second: 09 to 10, 59 to 00
otherwise, en = 1 and up = 0the count goes down one second: 10 to 09, 00 to 59
otherwisehold

tc is combinational: 1 while en = 1 and the next edge wraps, at 59 going up or at 00 going down. tc ignores clr. The result shows the count after edges 9, 18, ..., 72. It also counts the edges with tc = 1 just before them, and names the first.

Examples

Example 1

Every Edge Enabled, Up: 00 To 59 and the Wrap
Input
72 enabled edges of 72; up 1-72
Output
count_after_edge9 = 0x9, count_after_edge18 = 0x18, count_after_edge27 = 0x27, count_after_edge36 = 0x36, count_after_edge45 = 0x45, count_after_edge54 = 0x54, count_after_edge63 = 0x3, count_after_edge72 = 0x12, cycles_with_tc = 1, first_edge_with_tc = 60

The count reads 09, 18, 27, ... (BCD, shown as hex digits). tc is 1 once, just before edge 60, where 59 wraps to 00.

Example 2

Down from 00: The Borrow and 59
Input
72 enabled edges of 72; down 1-72
Output
count_after_edge9 = 0x51, count_after_edge18 = 0x42, count_after_edge27 = 0x33, count_after_edge36 = 0x24, count_after_edge45 = 0x15, count_after_edge54 = 0x6, count_after_edge63 = 0x57, count_after_edge72 = 0x48, cycles_with_tc = 2, first_edge_with_tc = 1

Counting down from 00, the first edge wraps to 59, so tc is 1 before edge 1. After 9 edges the count is 51.

Example 3

Up for 12 Seconds, Then Down Past 00
Input
72 enabled edges of 72; up 1-12, down 13-72
Output
count_after_edge9 = 0x9, count_after_edge18 = 0x6, count_after_edge27 = 0x57, count_after_edge36 = 0x48, count_after_edge45 = 0x39, count_after_edge54 = 0x30, count_after_edge63 = 0x21, count_after_edge72 = 0x12, cycles_with_tc = 1, first_edge_with_tc = 25

Up to 12, then down: 12 edges later the count is back at 00. The next edge wraps to 59 with tc = 1.

Constraints and Contract

  • All inputs are known 0/1 values and change only between edges.
  • Keep the module name and the ports. The design must synthesize with no latches.

Hints

Hint 1

Each digit has a last value that depends on the direction: 9 or 0 for ones, 5 or 0 for tens.

Hint 2

The tens digit moves only on an enabled edge where the ones digit leaves its last value, in either direction.

Hint 3

Going down, a digit that leaves its last value reloads its top value. tc must include en, and it must not be a flip-flop.

What the grader checks: Ten directed and ten seeded scripts of 72 edges, with direction changes, stalls and clears (one at 59 with en = 1). The count after every ninth edge is compared with a JavaScript model, and so are the cycles with tc = 1. Synthesis must report no latches.

The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.

20 checks on Icarus Verilog + Yosys · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 3 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Every Edge Enabled, Up: 00 To 59 and the Wrap

Input
72 enabled edges of 72; up 1-72
Expected output
count_after_edge9 = 0x9, count_after_edge18 = 0x18, count_after_edge27 = 0x27, count_after_edge36 = 0x36, count_after_edge45 = 0x45, count_after_edge54 = 0x54, count_after_edge63 = 0x3, count_after_edge72 = 0x12, cycles_with_tc = 1, first_edge_with_tc = 60

The count reads 09, 18, 27, ... (BCD, shown as hex digits). tc is 1 once, just before edge 60, where 59 wraps to 00.

Run samples executes all 3 public checks. Check all tests runs 20 checks on the server.

Icarus Verilog + Yosys · server