FPGA逻辑设计回顾(1)新手易犯的逻辑综合错误之always块

前言

  • “心中有路”与综合推断
  • “心中无路”与无从推断

这里所谓的路就是电路的意思,意思是逻辑工程师使用Verilog设计电路时要注重硬件思维,而不是软件编程。
心中有电路,在你使用RTL语言设计电路的时候,才能设计出综合工具能够推断出的具体硬件电路与之对应,否则可能语法过了,但是综合工具无法推断你的设计。

逻辑工程师在设计代码的时候要做到心中有电路,每一行代码的设计都是有对应硬件电路的。心中有电路,就是在编写Verilog程序的时候能明白我的设计会在FPGA中对应什么样的电路,使用的是什么样的资源,提前预知综合工具的想法,不一定全面,但是要有个大概,不要什么都交给综合工具去推断,这才是优秀的工程师应有的素质。

“心中有路”与综合推断

FPGA设计中,逻辑工程师对于逻辑资源的使用,有如下几种方式:Instantiation,Inference,IP Catalog和Macro Support;其含义分别为:

  • Instantiation即例化,例化一些Xilinx的原语资源,例如时钟BUFF资源:

  • IP Catalog,即IP核的使用,这种方式是FPGA设计工程师最常用的方式,简单方便且效率高,不像原语那样,参数很多且不得不在原语模板中单独配置,IP核的定制只需在GUI界面里选择自己的参数即可。如果要使用无法推断的任何FPGA原语的大块,则应使用此方法。
    例如,Xilinx的吉比特串行收发器资源:

    综合工具 错:

    如上提出的写法还只是一种,很多变种也大都是同样的问题,综合工具会 同样的错误,表明这是同一类问题:

    如:

    always块内使用同一个时钟的不同边沿。

    如:

    这是上面的例子;

    甚至这种也是不对的:

    这种相当于给时钟换了一个名字叫rst_n。
    因为你没有用rst_n作为复位或者使能或者置位信 ,Verilog会认为你的rst_n也是一个时钟,这又变成和上面两种情况一样的问题了。

    官 的相关链接给出了类似解释:

    You have to always remember that you are using Register Transfer Language (RTL) to have the synthesis infer hardware.
    Verilog HDL can do pretty much anything – the syntax of the always @() is very flexible. However, when you go to synthesize the design, the code has to map to an available piece of hardware on the FPGA.
    On the FPGA we have combinatorial logic (LUTs, MUXes, etc…). These are inferred a variety of ways, including the always @(
    ) construct.
    In addition we have flip-flops. A flip-flop on an FPGA (and pretty much anywhere else) is a device that has one clock and is sensitive to only one edge of that clock. So, the synthesis tool can only map to this device when the sensitivity list is always @(posedge clk). We have variants of the flip-flop that can do asynchronous preset/clear, so will map to always @(posedge clk or <posedge/negedge> rst), but that’s it.
    There is no real hardware device that can do the equivalent of what you are describing – always @(posedge clk or negedge clk).
    The only exception (sort of) are the IDDR and ODDR, and these need to be instantiated – they cannot be inferred from an HDL description.
    唯一的例外(种类)是IDDR和ODDR,这些需要实例化 – 它们不能从HDL描述中推断出来。
    So, no, this is not synthesizable Verilog.
    因此,这不是可以综合的Verilog。*

    多个输入直接驱动一个输出导致多驱动问题

    有些小机灵鬼可能会想,既然我在一个always块内会被认为没有对应的触发器资源,但是如果我将两个时钟分开到两个always块内,主动告诉综合工具,我需要分开使用,但是处理的是同一个数据,在本例中处理的计数数据,总该可以了吧!

    例如:

    首先验证功能是否正常,简单给出功能仿真激励:

    仿真波形:

    设计实现为:

    FPGA逻辑设计回顾(1)新手易犯的逻辑综合错误之always块
    这种实现方式就不存在任何问题,推荐大家使用。

    最后想说的是,例子并不是最终的目的,目的是设计的理念以及作为逻辑设计师的目标,一定做到心中有路,方可下手!

    参考文献

    Xilinx 7 Series FPGA and Zynq-7000 All Programmable SoC Libraries Guide for HDL Designs

    always@()的敏感源中为什么不能双边沿触发什么不能双时钟触发/p>

    ambiguous-clock-in-event-control

    [synth 8-91] ambiguous clk in event control

    【Verilog HDL 训练】第 11 天(分频电路)

    声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年1月20日
下一篇 2021年1月20日

相关推荐