Consider this Verilog code snippet that causes a synthesis warning about inferred latches:
module latch_example(input wire clk, input wire d, output reg q);
always @(clk or d) begin
if (clk) q = d;
end
endmoduleWhat is the main issue causing the synthesis warning?
module latch_example(input wire clk, input wire d, output reg q); always @(clk or d) begin if (clk) q = d; end endmodule
Think about what happens to q when clk is low.
The always block does not assign q when clk is low, so the synthesis tool infers a latch to hold the previous value. Adding an else branch fixes this.
Look at this Verilog code snippet:
module unused_signal(input wire a, output wire b); wire temp; assign b = a; endmodule
What synthesis warning will most likely appear?
module unused_signal(input wire a, output wire b);
wire temp;
assign b = a;
endmoduleCheck if all declared signals are connected or used.
The wire 'temp' is declared but never used or connected, so synthesis tools warn about unused signals.
Given this Verilog snippet:
module multi_driver(input wire a, input wire b, output reg y);
always @(*) begin
y = a;
end
always @(*) begin
y = b;
end
endmoduleWhat synthesis warning will this code generate?
module multi_driver(input wire a, input wire b, output reg y); always @(*) begin y = a; end always @(*) begin y = b; end endmodule
Think about how many places assign to 'y'.
Two always blocks assign to the same reg 'y', causing multiple drivers warning because hardware cannot drive one signal from two sources simultaneously.
Consider this Verilog code:
module case_example(input wire [1:0] sel, output reg out);
always @(*) begin
case(sel)
2'b00: out = 0;
2'b01: out = 1;
2'b10: out = 0;
endcase
end
endmoduleWhich option fixes the synthesis warning about incomplete case statement?
module case_example(input wire [1:0] sel, output reg out); always @(*) begin case(sel) 2'b00: out = 0; 2'b01: out = 1; 2'b10: out = 0; endcase end endmodule
Think about what happens when sel is 2'b11.
Without a default case, the synthesis tool warns that some inputs are not covered, possibly inferring latches. Adding a default case assigns 'out' for all inputs.
Analyze this Verilog code snippet:
module comb_loop(input wire a, output reg y);
always @(*) begin
y = ~y & a;
end
endmoduleThis code causes a synthesis warning about a combinational loop. What is the best way to fix it?
module comb_loop(input wire a, output reg y);
always @(*) begin
y = ~y & a;
end
endmoduleThink about how to avoid feedback loops in combinational logic.
The code feeds back 'y' into its own combinational assignment, causing a loop. Using a clocked process to update 'y' breaks the loop and removes the warning.
