Electronic – VHDL Clock Question

vhdl

What is the difference between these statements in VHDL:

  1. if (clk'event and clk='1') then
  2. if rising_edge(clk) then

Are they equivalent ? Do you produce the same behavior (outputs) ? Why would one be used versus the other ?

Also is one synthesizable versus the other ? Which is better for synthesis correct coding ?

Best Answer

No, they are not exactly equivalent. The first variation

if (clk'event and clk='1') then

only works correctly if the previous state of the clock was in fact '0'. This works fine in most cases, but won't catch unusual cases, such as when the previous state was 'U', 'W', 'X' or 'Z'.

The second variation uses rising_edge()1, which specifically checks whether the previous state was '0' or 'L' and the new state is '1' or 'H'.


1 You can see the actual definition on Stack Overflow