- Joined
- Sep 10, 2013
- Messages
- 7,945
- Helped
- 1,823
- Reputation
- 3,656
- Reaction score
- 1,809
- Trophy points
- 1,393
- Location
- USA
- Activity points
- 60,214
Given the exact same two files above with the change of the entity name of the 2nd to lat_reg. I got the following consistent results from two different synthesis tools: XST and Vivado synthesis (I believe for both of these, the core synthesis technology was purchased by Xilinx).I must confess, I never noticed this before. In both Quartus versions, I get the below results by including or excluding the data input in the sensitivity list. I don't think that the behaviour corresponds to the VHDL LRM. I'm also not yet aware of a synthesis attribute controlling the automatic latch to dff conversion.
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity lat is port( enable: in std_logic; Output: out std_logic; Input: in std_logic); end; architecture behavioral of lat is begin -- Infers a latch process (enable, input) is begin if enable = '1' then output <= input; end if; end process; end;
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity lat is port( enable: in std_logic; Output: out std_logic; Input: in std_logic); end; architecture behavioral of lat is begin -- Unexpectedly infers a synchronous register process (enable) is begin if enable = '1' then output <= input; end if; end process; end;
Code VHDL - [expand] 1 2 3 4 5 wait_dff : process (clk) begin wait until rising_edge(clk); q <= d; end process
Given the exact same two files above with the change of the entity name of the 2nd to lat_reg. I got the following consistent results from two different synthesis tools: XST and Vivado synthesis (I believe for both of these, the core synthesis technology was purchased by Xilinx).
That's what I had expected for Quartus synthesis, too.So the question remains, which tool is doing the correct synthesis? ISE and Vivado both think the description is a poorly written latch as it seems to expect that a register has to have an edge controlled event.
process (enable, reset) is
begin
if reset = '1' then
output <= '0';
-- infers a latch with a warning
elsif enable = '1' then
output <= input;
end if;
end process;
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -- Option 1: bogus D-FF process (clk) begin if (clk = '1') then q <= d; end if; end process; -- Option 2: WTF D-FF Gotta save one line of code!!! process (clk) begin wait until rising_edge(clk); q <= d; end process; -- Option 3: I'm old school and I don't care if my clock has Z-1, X-1, U-1, or 0-1 transitions process (clk) begin if (clk'event and clk = '1') then q <= d; end if; end process; -- Option 4: This is what VHDL should have had from the start. DUH! process (clk) begin if rising_edge(clk) then q <= d; end if; end process;
Sloppy!? I think the VHDL language itself is sloppy and overly verbose. I get carpal tunnel just thinking about typing a VHDL description. ;-)Let the sloppy code stay in the Verilog world.
It was not my intention to create a VHDL-Verilog war in this thread. VHDL is not perfect. The code that made Quartus generate a D-flipflop is similar to the Verilog code for the same thing. I like that hardware is fully described by a VHDL process "body" and that the sensitivity list is only a help for the simulator to speed things up. The Quartus behavior to create a DFF from a missing signal in the sensitivity list is not good for VHDL as a synthesis language. A transparent latch and a warning is what I prefer.Sloppy!? I think the VHDL language itself is sloppy and overly verbose. I get carpal tunnel just thinking about typing a VHDL description. ;-)
It was not my intention to create a VHDL-Verilog war in this thread. VHDL is not perfect. The code that made Quartus generate a D-flipflop is similar to the Verilog code for the same thing. I like that hardware is fully described by a VHDL process "body" and that the sensitivity list is only a help for the simulator to speed things up. The Quartus behavior to create a DFF from a missing signal in the sensitivity list is not good for VHDL as a synthesis language. A transparent latch and a warning is what I prefer.
Run it through a synthesis tool like I did and start counting latches...but what should be the exact answer 4 or 5 d latches?
First of all, you should not write "if CLK = ’1’ then" since it is not compatible with all synthesis tools.but what should be the exact answer 4 or 5 d latches?
How many D-Latches are generated here?
but what should be the exact answer 4 or 5 d latches?
First of all, you should not write "if CLK = ’1’ then" since it is not compatible with all synthesis tools.
Use "if rising_edge(CLK) then".
As the discussion revealed, it's no so easy to predict how a synthesis tool will interpret your code. But what we can clearly say, if you are using d-latches for a counter, either intentionally or by accident, the counter won't work in hardware.But they keep saying how many "LATCHES" not "edge triggered D-Flip-Flops". Maybe they don't know the difference?
So vishal_sonam, do you want latches or edge-triggered D-flip-flops?
Hmmm, FvM pretty much said it. You can't make a counter out of transparent latches.I want transparent latches
Hmmm, FvM pretty much said it. You can't make a counter out of transparent latches.
WHY!? you ask.
When the latch is transparent....
count <= count +1;
count <= (count+1) +1;
count <= ((count+1)+1) +1;
count <= (((count+1)+1)+1)+1;
...
Uh, when is it supposed to stop? You have a feedback loop. I guess it will randomly stop when you latch whatever value is sitting at the count latch d input. Not very predictable over temperature and process variations.
vishal_sonam,I want transparent latches
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?