Complete the code to declare a D flip-flop with asynchronous reset.
always @(posedge clk or posedge rst) begin if ([1]) q <= 0; else q <= d; end
The asynchronous reset signal is checked first to clear the output.
Complete the code to instantiate a 2-stage synchronizer for an asynchronous input signal.
reg sync_0, sync_1;
always @(posedge clk) begin
sync_0 <= async_in;
[1] <= sync_0;
endThe second stage register 'sync_1' captures the output of the first stage 'sync_0'.
Fix the error in the synchronizer code to avoid combinational loop.
always @(posedge clk) begin
sync_0 <= async_in;
sync_1 <= [1];
endThe second register must capture the first register's value to avoid combinational loops.
Fill both blanks to complete the metastability flag logic in a synchronizer.
reg meta_flag; always @(posedge clk) begin meta_flag <= ([1] != [2]); end
The flag detects when the first and second stage differ, indicating possible metastability.
Fill all three blanks to complete the code for a 3-stage synchronizer with metastability detection.
reg sync_0, sync_1, sync_2; reg meta_flag; always @(posedge clk) begin sync_0 <= [1]; sync_1 <= [2]; sync_2 <= [3]; meta_flag <= (sync_0 != sync_1) || (sync_1 != sync_2); end
The first stage captures the async input, the second captures the first, and the third captures the second to reduce metastability risk.
