简体   繁体   English

用并发语句实现触发器

[英]implementing a flip-flop with concurrent statement

It is stated in VHDL programming that for combinational circuits, concurrent statements are used while for sequential circuits, both concurrent and sequential statements are applicable. 在VHDL编程中规定,对于组合电路,使用并发语句,而对于顺序电路,并发和顺序语句均适用。 Now the question is: 现在的问题是:

What will happen if I write a sequential code in a concurrent form? 如果以并发形式编写顺序代码会怎样? For example, I don't use process and write a flip flop with when..else 例如,我不使用process并用when..else编写触发器

architecture x of y is
begin
   q <= '0' when rst=1 else
        d   when (clock'event and clock='1') else
        q;
end;

Is that a correct and synesthesizable code? 那是正确且可合成的代码吗? If it is an incorrect code, what is wrong with that exactly (apart form syntax errors)? 如果代码不正确,那到底是什么问题(除了语法错误)?

You say: "It is stated in VHDL programming that for combinational circuits, concurrent statements are used while for sequential circuits, both concurrent and sequential statements are applicable.". 您说:“在VHDL编程中指出,对于组合电路,使用并发语句,而对于顺序电路,并发和顺序语句均适用。” That is simply not true. 那明显是错的。 You can model both combinational and sequential code using either concurrent or sequential statements. 您可以使用并发或顺序语句对组合代码和顺序代码进行建模。

It is unusual to model sequential logic using concurrent statements. 使用并发语句为顺序逻辑建模是很不寻常的。 (I say that because I see a lot of other people's code in my job and I almost never see it). (我之所以这样说是因为我在工作中看到了很多其他人的代码,而我几乎从没看到过)。 However, it is possible. 但是,这是可能的。 Your code does have a syntax error and a more fundamental error. 您的代码确实存在语法错误和更基本的错误。 This modified version of your code synthesises to a rising-edge triggered flip-flop with an asynchronous, active-high reset, as you expected: 您的代码的此修改后的版本综合为具有异步,高电平有效复位的上升沿触发触发器,如您所料:

q <= '0' when rst='1' else
      d  when clock'event and clock='1';

The syntax error was that you had rst=1 instead of rst='1' . 语法错误是您拥有rst=1而不是rst='1' The more fundamental error was that you don't need the else q . 更根本的错误是您不需要else q This is unnecessary, because signals in VHDL retain the value previously assigned until a new value is assigned. 这是不必要的,因为VHDL中的信号会保留先前分配的值,直到分配了新值为止。 Therefore, in VHDL code modelling sequential logic, it is never necessary to write q <= q (or its equivalent). 因此,在VHDL代码建模顺序逻辑中, 永远不需要写q <= q (或其等值)。 In your case, in the MCVE I constructed q was an output and so your else q gave a syntax error because you cannot read outputs. 在您的情况下,在MCVE中,我构造的q是输出,因此您的else q给出了语法错误,因为您无法读取输出。

Here's the MCVE: 这是MCVE:

library IEEE;
use IEEE.std_logic_1164.all;

entity concurrent_flop is
  port (clock, rst, d : in  std_logic;
        q             : out std_logic);
end entity concurrent_flop;

architecture concurrent_flop of concurrent_flop is
begin
   q <= '0' when rst='1' else
         d  when clock'event and clock='1';
end architecture concurrent_flop;

I wrote an MCVE to check what I was about to say was correct. 我写了一个MCVE来检查我要说的是正确的。 You could have done the same. 您可以做同样的事情。 Doing so is a great way of learning VHDL. 这样做是学习VHDL的好方法。 EDA Playground is often a good place to try things out (shameless plug), but was no good in this case, because one cannot synthesise VHDL on EDA Playground. EDA Playground通常是一个尝试的好地方(无耻的插件),但在这种情况下就不好了,因为不能在EDA Playground上合成VHDL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM