简体   繁体   English

VHDL:变量和过程

[英]VHDL: variable and process

I am studying VHDL and I found one thing particularly difficult to understand, since VHDL is a HDL, in my humble opinion, everything it describe should be able to be converted into a circuit.我正在研究 VHDL,我发现一件特别难以理解的事情,因为 VHDL 是一种 HDL,在我看来,它描述的一切都应该能够转换成电路。 But how could this happen to variable and process?但是这怎么会发生在变量和过程上呢? Is there any circuit that can realize variable and process?有没有什么电路可以实现变量和过程? Can you give me an example of this?你能给我举个例子吗? Thanks谢谢

Processes containing variables certainly can be converted into circuits.包含变量的过程当然可以转换为电路。

Here are a couple of simple examples.这里有几个简单的例子。

Process(clk)
Variable Q : std_logic_vector(7 downto 0);
begin
  if rising_edge(clk) then
     if En = '0' then
        Q := D;
     end if;
  end if;
  Output <= Q;
end process;

In every clock cycle, if the En (Enable) input is low, the input data D is stored in the variable Q;在每个时钟周期内,若En(Enable)输入为低电平,则输入数据D存入变量Q; otherwise nothing happens (and the variable keeps its old value).否则什么都不会发生(并且变量保持其旧值)。 This is a very specific circuit;这是一个非常特殊的电路; an 8-bit register with enable;一个带使能的 8 位寄存器; look up the 74LS377 in an old data book to see the same circuit in TTL.在旧数据手册中查找 74LS377 以查看 TTL 中的相同电路。

Notice that the clock "if" statement is kept separate from the En statement, and surrounds it.请注意,时钟“if”语句与 En 语句分开,并围绕它。 Synthesis tools look for specific patterns that they know how to translate, and this is one of them.综合工具寻找他们知道如何翻译的特定模式,这就是其中之一。 If you have any software experience you might be tempted to combine them : if rising_edge(Clk) and En = '0' then ... - and in simulation you would get exactly the same behaviour.如果您有任何软件经验,您可能会想将它们组合起来: if rising_edge(Clk) and En = '0' then ... - 在模拟中,您将获得完全相同的行为。

However some synthesis tools may not recognise this pattern, and may report errors instead of generating hardware.然而,一些综合工具可能无法识别这种模式,并且可能会报告错误而不是生成硬件。 (Synthesis tools are continually improving, so you might be lucky nowadays). (合成工具在不断改进,所以你现在可能很幸运)。 The tool's documentation (eg Xilinx " synthesis and simulation design guide ") ought to describe what is and isn't possible.该工具的文档(例如 Xilinx 的“ 综合和仿真设计指南”)应该描述什么是可能的,什么是不可能的。 [edit:] unfortunately it is stuck around 1995 practices and contains some truly horrible examples of VHDL. [编辑:] 不幸的是,它停留在 1995 年的实践中,并且包含一些真正可怕的 VHDL 示例。

Process(clk)
Variable Count : Integer range 0 .. 255 := 0;    -- set to 0 when process first starts
begin
  if rising_edge(clk) then
     Count := Count + 1 mod 256;
  end if;
  Output := Count;
end process;

Notice that variables, like signals, do not need to be logic types;注意变量和信号一样,不需要是逻辑类型; integers, arrays and records (with some restrictions) are synthesisable;整数、数组和记录(有一些限制)是可合成的; floats usually are not (though this is changing as tools improve).浮动通常不是(尽管随着工具的改进这种情况正在发生变化)。 Notice that I limited the range of the integer, to get an 8-bit counter.请注意,我限制了整数的范围,以获得 8 位计数器。

With integers, you also need to explicitly specify what happens when they overflow (as I did here) - otherwise you will get errors in simulation.对于整数,您还需要明确指定当它们溢出时会发生什么(就像我在这里所做的那样) - 否则您将在模拟中出错。 However, specifying the obvious behaviour (as here) should not cost any additional hardware.但是,指定明显的行为(如此处)不应该花费任何额外的硬件。 And using other numeric types like numeric_std.unsigned, the tools are not so fussy.使用其他数字类型,如 numeric_std.unsigned,这些工具就不会那么繁琐了。

I have simplified a little;我简化了一点; usually there is a Reset clause in a typical process to let you control startup behaviour, but these examples are real and ought to work.通常在典型的过程中有一个 Reset 子句来让你控制启动行为,但这些例子是真实的,应该可以工作。

Variables can be very handy - they change immediately, but can also keep their value from one tick to the next.变量可能非常方便——它们会立即改变,但也可以从一个刻度到下一个刻度保持它们的值。 This avoid replicating code when you want to access a previously calculated value which is normally an "output" of your process.当您想要访问先前计算的值(通常是您的过程的“输出”)时,这可以避免复制代码。

As to creating circuits, variables and signals merely transfer values from one place to another within the design.至于创建电路,变量和信号只是将值从设计中的一个地方转移到另一个地方。 Variables are limited to within a process, signals can flow all over the design.变量仅限于一个过程,信号可以在整个设计中流动。 Either way the synthesiser's job is to figure out what behaviour you have described and implement logic to match.无论哪种方式,合成器的工作都是弄清楚您所描述的行为并实现匹配的逻辑。 If you increment a variable, or a signal, the same set of "gates" (or look-up tables, etc) results.如果你增加一个变量或一个信号,同样的一组“门”(或查找表等)会产生。

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

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