The circuit stores each triplet of decimals in a 10-bit vector encoded as densely packed decimals. An index vector selects the current digits to be output to the 7-segment display. It consists of an upper part index[11:2]
that selects the triplet and a lower part index[1:0]
that specifies the digit within the triplet. First, the upper part decides on the triplet, which is then decoded into three decimals. Afterwards, the lower part selects one of the three decimals to be decoded into 7-segment display logic and applied to the outputs. The index is incremented at each primary clock edge. However, when the lower part equals three, i.e., index[1:0]==1'b10
, two is added, as the triplet consists of three (not four) digits.
index == 'b0000000000|00
: triplet[0], digit 0 within tripletindex == 'b0000000000|01
: triplet[0], digit 1 within tripletindex == 'b0000000000|10
: triplet[0], digit 2 within tripletindex == 'b0000000001|00
: triplet[1], digit 0 within tripletindex == 'b0000000001|01
: triplet[1], digit 1 within tripletindex == 'b0000000001|10
: triplet[1], digit 2 within tripletThere is one exception to the rule above: the decimal point. Another multiplexer at the input of the 7-segment decoder can either forward a digit from the decoded tripled or a constant – the decimal point. Once the lower part of the index counter, i.e., index[1:0]
reaches 2'b10
for the first time, the multiplexer selects the decimal point and pauses incrementing the index for one clock cycle.
index == 'b0000000000|00
: triplet[0], digit 0 within tripletindex == 'b0000000000|01
: triplet[0], decimal pointindex == 'b0000000000|01
: triplet[0], digit 1 within tripletindex == 'b0000000000|10
: triplet[0], digit 2 within tripletindex == 'b0000000001|00
: triplet[1], digit 0 within tripletFor simulation, please use the provided testbench and Makefile. It is important to run the genmux.py
Python script first, as it generates the test vectors required by the Verilog testbench. For testing the physical chip, release the reset and compare the digits of Pi against a reference.
# | Input | Output |
---|---|---|
0 | clk | segment a |
1 | reset | segment b |
2 | none | segment c |
3 | none | segment d |
4 | none | segment e |
5 | none | segment f |
6 | none | segment g |
7 | none | decimal LED |