Lab 2
Lab 2
1. Design description
);
always @(posedge clk or negedge reset_n) begin if (!reset_n) begin digit0 <= 0; digit1
<= 0; digit2 <= 0; end else if (enable)
begin // count units if
(digit0 == 9) begin
digit0 <= 0;
end
end else begin digit0 <=
digit0 + 1;
end
end
end
end module
1
Machine Translated by Google
always @(posedge clk or negedge reset_n) begin if (!reset_n) begin count <=
26'd0; enable <= 0; end else
begin if (count ==
26'd49_999_999)
begin
end
end
end
end module
end case
end
endmodule
2
Machine Translated by Google
);
// BCD counter
bcd_counter
// HEX display
hex_decoder h0(.bcd(d0), .seg(HEX0)); hex_decoder
h1(.bcd(d1), .seg(HEX1)); hex_decoder h2(.bcd(d2), .seg(HEX2));
end module
In always @(posedge clk) blocks, <= should be used to describe the register behavior.
3
Machine Translated by Google
2.2 Describe how you design the BCD counting logic? Does it detect
when a digit reaches 9?
Yes. When the digit reaches 9, reset to 0 and activate the next digit.
end
end else begin digit0 <=
digit0 + 1;
end
2.4 Output from Quartus II compile report: How many flip-flops are there?
used?
Based on the compilation report from Quartus II, the total number of flip-flops (registers)
used is 2, including:
• clock_divider: 1 flip-flop
• bcd_counter: 1 flip-flop
4
Machine Translated by Google
2.5 What is Metastability? Why should we care when using discordant signals?
set like reset?
a. What is Metastability?
Metastability is a phenomenon that occurs when a flip-flop receives an input signal that
changes too close to the clock edge, causing the flip-flop to not be able to stabilize in time at the
logic 0 or 1. Instead, it falls into an intermediate (undefined) state for a short period of
This is especially serious when dealing with asynchronous signals, such as reset
buttons, signals from peripheral devices, etc. These signals are not synchronized with the
system clock and can easily cause metastability when fed directly to the flip-flop.
b. Why care?
• Introduce asynchronous signals into the clock domain through intermediate processing mechanisms.