G4.1.1 Seven-Segment Decoder

EasyImplementIcarus Verilog + Yosys · serverReview the topic

Decode a 4-bit status code onto an active-low seven-segment display, with a lamp test and no latch.

Hardware context: A common-anode seven-segment digit on a washing machine, driven by a 4-bit status code. Decode digits, four letters and two blank codes in one always_comb block with no latch.

A washing machine shows its state on one seven-segment digit. The digit counts down the minutes, and a few letters report faults. The display is common-anode: a segment lights when its line is driven to 0.

This is an Implement problem. Write status7 as one always_comb block. Each code from 0 to 9 shows its digit. Codes 10 to 13 show the letters E, r, a dash and L. Codes 14 and 15 show nothing. When lamp_test is 1, every segment lights, whatever the code.

The check applies eight inputs, one per nanosecond, and records seg_n after each. The check also synthesizes the module on the site's flow and rejects any latch.

Signals in the Timeline

SignalWidthRole
script40input of each check
Full specification
The module (keep the name and the ports)
module status7 (
  input  logic [3:0] code,       // 0-9 digits, 10 E, 11 r, 12 -, 13 L, 14 and 15 blank
  input  logic       lamp_test,  // 1: light every segment
  output logic [6:0] seg_n       // {g, f, e, d, c, b, a}; a 0 lights the segment
);
  // your design
endmodule
codeshowslit segments
0the digit 0a b c d e f
1the digit 1b c
2the digit 2a b d e g
3the digit 3a b c d g
4the digit 4b c f g
5the digit 5a c d f g
6the digit 6a c d e f g
7the digit 7a b c
8the digit 8a b c d e f g
9the digit 9a b c d f g
10the letter Ea d e f g
11the letter re g
12a dashg
13the letter Ld e f
14nothingnone
15nothingnone
SegmentPositionBit of seg_n
atop bar0
bupper right1
clower right2
dbottom bar3
elower left4
fupper left5
gmiddle bar6

The result fields are named seg_n_step0 to seg_n_step7, shown in binary as {g, f, e, d, c, b, a}. Remember: 0 means lit.

Examples

Example 1

The Digits 0 to 7
Input
code 0; code 1; code 2; code 3; code 4; code 5; code 6; code 7
Output
seg_n_step0 = 'b1000000, seg_n_step1 = 'b1111001, seg_n_step2 = 'b0100100, seg_n_step3 = 'b0110000, seg_n_step4 = 'b0011001, seg_n_step5 = 'b0010010, seg_n_step6 = 'b0000010, seg_n_step7 = 'b1111000

Each digit lights the segments of its table row. The display is active-low, so every lit segment is a 0. The digit 1 lights b and c only: 1111001.

Example 2

The Digits 8 and 9 Between Others
Input
code 8; code 9; code 0; code 9; code 8; code 1; code 7; code 4
Output
seg_n_step0 = 'b0000000, seg_n_step1 = 'b0010000, seg_n_step2 = 'b1000000, seg_n_step3 = 'b0010000, seg_n_step4 = 'b0000000, seg_n_step5 = 'b1111001, seg_n_step6 = 'b1111000, seg_n_step7 = 'b0011001

The digit 8 lights all seven segments, so seg_n is all zeros. The digit 9 is the 8 without segment e.

Example 3

Lamp Test over Two Digits
Input
code 3; code 3 with lamp test; code 3; code 6 with lamp test; code 6; code 1 with lamp test; code 1; code 0
Output
seg_n_step0 = 'b0110000, seg_n_step1 = 'b0000000, seg_n_step2 = 'b0110000, seg_n_step3 = 'b0000000, seg_n_step4 = 'b0000010, seg_n_step5 = 'b0000000, seg_n_step6 = 'b1111001, seg_n_step7 = 'b1000000

While lamp_test is 1, every segment lights whatever the code. When it returns to 0, the digit shows again.

Constraints and Contract

  • Inputs are known 0/1 values. Each input is held for one nanosecond and seg_n is sampled at its end.
  • Keep the module name and the ports. The design is combinational: it must not remember an earlier code.

Hints

Hint 1

Write the lit segments of one code as seven bits, g f e d c b a, with 1 for lit. Then invert every bit, because the display is active-low.

Hint 2

Codes 14 and 15 need a value too. If no arm assigns seg_n for them, the output keeps the last pattern, and that needs a latch.

Hint 3

Test lamp_test first, in an if. Put the case statement in the else branch.

What the grader checks: Eight directed and eight seeded cases of eight steps each cover every code, with and without lamp test. Each output is compared with a model written in JavaScript after every step. A blank code right after a lit one catches an output that remembers. The synthesis check rejects a latch.

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.

16 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 1 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

The Digits 0 to 7

Input
code 0; code 1; code 2; code 3; code 4; code 5; code 6; code 7
Expected output
seg_n_step0 = 'b1000000, seg_n_step1 = 'b1111001, seg_n_step2 = 'b0100100, seg_n_step3 = 'b0110000, seg_n_step4 = 'b0011001, seg_n_step5 = 'b0010010, seg_n_step6 = 'b0000010, seg_n_step7 = 'b1111000

Each digit lights the segments of its table row. The display is active-low, so every lit segment is a 0. The digit 1 lights b and c only: 1111001.

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

Icarus Verilog + Yosys · server