Digital Signal Processing Reference
In-Depth Information
out_b = 2
'
b10;
end
else
out_a = 2
'
b01;
end
As
out_b
is not assigned any value under
else
, the synthesis tool will infer a latch for storing
the previous value of
out_b
in cases where an
else
condition is TRUE. To avoid this latch the
programmer should either assign some value to
out_b
in the
else
block, or assign default values
to all variables outside a conditional block. This is shown in the following code:
input [1:0] sel;
reg [1:0] out_a, out_b;
always @(*)
begin
out_a = 2
'
b00;
out_b = 2
'
b00;
if (sel=2
'
b00)
begin
out_a = 2
'
b01;
out_b = 2
'
b10;
end
else
out_a = 2
'
b01;
end
The syntheses tool will also infer a latch when conditional code in the combinational blockmisses
any one or more conditions. This scenario is depicted in the following code:.
input [1:0] sel;
reg [1:0] out_a, out_b;
always @*
begin
out_a = 2
'
b00;
out_b = 2
'
b00;
if (sel==2
'
b00)
begin
out_a = 2
'
b01;
out_b = 2
'
b10;
end
else if (sel == 2
'
b01)
out_a = 2
'
b01;
end
This code misses some possible values of
sel
and checks for only two listed values,
2
'
b01
and
2
'
b00
. The synthesis tool will infer a latch for
out_a
and
out_b
to retain previous values in case
any one of the conditions not covered occurs. This stype of codingmust be avoided. In an
if, else
if, else
block, the block must come with an
else
statement; and in scenarios where the
case
statement is used, either all conditions must be specified, and for each condition values should be
Search WWH ::
Custom Search