EmbDev.net

Forum: FPGA, VHDL & Verilog VHDL: Why the delay is 3 clk after synthesis?


Author: sean jee (seanjee)
Posted on:

Rate this post
0 useful
not useful
In VHDL, variable should make no delay between value assignment. But how 
about mix signal and variables? In code below, X and Y are variables and 
Z is output. Why the delay between Z and input A,B is 3 clocks? Why it's 
not 1 clock delay?
Thanks in advance.

==========================
process(clk)
variable X,Y:std_logic;
begin
  if(clk's event and clk='1') then
    Z<=Y;
    Y:=X;
    X:=A and B;
  end if;
end process;

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
> Why it's not 1 clock delay?
Becuase the variables are read before they are written, therefore they 
must be storing.
>  Why the delay between Z and input A,B is 3 clocks?
Its not called delay, its latency...

Play "FPGA" and do the process on your own:
  if(clk's event and clk='1') then
    Z<=Y;              -- with the clock Z becomes Y
    Y:=X;              -- AFTER THAT Y becomes X
    X:=A and B;        -- AFTER THAT X becomes A*B
  end if;
The two AFTER THAT are the two additional clock cycles...

If you would turn it around ther would be no additional latency:
  if(clk's event and clk='1') then
    X:=A and B;        -- FIRST X becomes A*B
    Y:=X;              -- THEN  Y becomes X
    Z<=Y;              -- AND FINALLY Z becomes Y
  end if;
Because then the variables are not storing...

Author: pek (Guest)
Posted on:

Rate this post
0 useful
not useful
- Variables are assignmed sequentially, so order of assignment matters
- Signals are assigned "all together" at the end of a time tick

so this is what happens after input A or B changes:

1st clock event

Z is marked not to change, as variable Y has still the old value
Y is assigned the old value of X (as it has not changed so far)
X is assigned the new "A and B"

2nd clock event

Z is marked not to change, as variable Y has still the old value
Y is assigned the value of X as from 1st clock event
X is assigned the new "A and B"

3rd clock event

Z is marked to get the value of Y at the end of the process
Y is assigned the value of X as from 2nd clock event
X is assigned the new "A and B"
Z is assigned the value of Y

Here we are...

Author: sean jee (seanjee)
Posted on:

Rate this post
0 useful
not useful
Very clear clarification.
Thank you all very much!

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.