BitFlow

7-segment decoder

A 7-segment digit is seven LEDs named a to g. seg0[0] is segment a (the top), going clockwise to f, and seg0[6] is g, the middle bar.

A decoder maps each value 0–15 to the segments that draw it. A case statement inside always @(*) is the natural way to write a lookup table like this. Show 10–15 as A, b, C, d, E and F.

lab.v
drag to turn · scroll to zoom

Loading the board…

Press Run on the board: your Verilog is turned into gates in this browser and runs here, cycle by cycle.

Goals

  • ○Digits 0–9 are drawn right
  • ○A–F are drawn right
Hints
  1. The digit 1 lights segments b and c: 7'b0000110.
  2. 0 is 7'b0111111, 8 is 7'b1111111.
  3. Declare the output as output reg [6:0] seg0 so you can set it in always @(*).

Pin log

Run the design to see its outputs change.

Put it on a real board

  • The Sipeed Tang Nano 9K (Gowin GW1NR-9) has no switches or a 7-segment display: those ports go to header pins, where you can wire them.
  • The clock is set to the board's 27 MHz, and its active-low buttons and LEDs are flipped for you.
Waveform