Hi,
I have done a TB in Verilog with a selfcheck loop and I have 2 registers
where I compare the expected and actual output value:
reg [MODULES:0] count_comp(expected), count(actual value);
Because the output from the UUT is registered, I am expecting 1 Clock
PERIOD delay but from the simulation I got 2 PERIODS and Undefined
signal. The module is testing a "unsigned" adder with 4 bits
Any idea why I get the StX values after the Enable signal goes High?
And why there are 2 clock periods delay between the expected and actual
signal?
TB self-check coding below
always begin
for ( i=0; i < LOOP; i = i + 1 ) begin
for (b=0; b < LOOP; b = b + 1) begin
in1 = i;
in2 = b;
count_comp = in1 + in2;
#PERIOD;
count = {carry, sum};
if (count != count_comp) begin
$display ("Error at time %d", $time);
$display ("Expected value: %d, Value calculated:
%d", count_comp, count);
Sorry for having posted a sort piece of code before, I am a newbie with
Forums and posting.
Bellow is my full testbench in Verilog
The Adder is an unsigned adder in VHDL.
looking at the code, I would believe the only time the output values are
registered (s and cy_out) is at the "Funct_NbitsAdder" module. So that,
I was expecting to see 1 PERIOD delay between the calculated and the
actual output value.
In fact , the value "sum" from the TB which it is defined as a wire, has
the expected delay of a PERIOD ( this is the actual output from the
"Funct_NbitsAdder". When that value is concatenated in the reg "comp"
signal, the value has 2 PERIOD delay.
Is this due to the fact that reg definition works as a register and
updates the values at the next clokc period?
If so, I have also tried to define "reg [MODULES:0] count_comp, count;"
as a wires -> "wire [MODULES:0] count_comp, count;" but the tool gave me
an error during compilation.
Lothar M. wrote:> An addition is a completely combinatorial job. Why do you invoke a clock> there?
I agree.
Blas M. wrote:> Is this due to the fact that reg definition works as a register and> updates the values at the next clokc period?
No, it is not the definition as reg. It is the description of a clocked
(registered) process in the adder: "if (clk'event and clk='1') then"
The second clock cycle might be a race condition. After #PERIOD the
signals in1, in2 and clk are changing. But in which order? If clk
changes first, the adder is executed with the old values. After that the
new values are applied to the adder and the next wait-Period follows.
Change the testbench, that clk and the singlas are not changing in the
same moment!