简体   繁体   English

在Quartus中编译Verilog代码

[英]compiling Verilog code in Quartus

I'm new to verilog HDL and my first project is to implement a simple stopwatch counter using a set of registers. 我是Verilog HDL的新手,我的第一个项目是使用一组寄存器实现一个简单的秒表计数器。 I'm using Altera Quartus. 我正在使用Altera Quartus。

When I tried compiling the code below, I keep getting an error for each and everyone of the registers. 当我尝试编译下面的代码时,对于每个寄存器,我总是收到错误消息。 one of the error messages looks like this: 错误消息之一如下所示:

Error (10028): Can't resolve multiple constant drivers for net "sec0[3]" at test_interface.v(127) 错误(10028):在test_interface.v(127)上无法解析网络“ sec0 [3]”的多个常量驱动程序

Anyone can help? 有人可以帮忙吗? The code simulates fine in Modelsim. 该代码在Modelsim中模拟良好。

Here's the fragment of code that's causing problems: 这是引起问题的代码片段:

always @ (posedge clk)

  if (qsoutput == 1)
      sec0 = sec0 + 1;
  else if (sec0 == 4'b1010) begin
      sec1 = sec1 + 1;
      sec0 = 4'b0000;
  end else if (sec1 == 4'b0110) begin
      min0 = min0 + 1;
      sec1 = 4'b0000;
  end else if (min0 == 4'b1010) begin
      min1 = min1 + 1;
      min0 = 4'b0000;     
  end else if (min1 == 4'b0110) begin
      sec0 = 4'b0000;
      sec1 = 4'b0000;
      min0 = 4'b0000;
      min1 = 4'b0000;
  end

Based on your code in Dropbox , you are assigning registers in multiple always blocks. 根据Dropbox中的代码 ,您将在多个always块中分配寄存器。 This is illegal for synthesis and cosponsors to the Altera Quartus error message is referring to. 这对于合成是非法的,并且是Altera Quartus错误消息所指的共同赞助者。 A reg type should only be assigned with in one always block. reg类型只能在一个always块中分配。

As an example, sec0 is defined in always @(posedge reset_reg) and the code provided in your question. 例如, sec0 always @(posedge reset_reg)always @(posedge reset_reg)定义,并在您的问题中提供代码。 The code in Dropbox is even worse because you split the counter logic into 4 separate always blocks that assign sec0 . Dropbox中代码更糟糕,因为您将计数器逻辑分为分配sec0 4个独立的sec0块。

I suggest you put all sec* and min* resisters one clock synchronous always block with an asynchronous: 我建议您将所有sec*min*电阻器的一个时钟同步始终以异步方式阻塞:

always(@posedge clk or posedge reset_reg)
begin
  if(reset_reg)
  begin
    // ... asynchronous reset code ...
  end
  else
  begin
    // ... synchronous counter code ...
  end
end

This paper goes into detail about good verilog coding practices for synthesis: http://www.sunburst-design.com/papers/CummingsSNUG2000SJ_NBA.pdf 本文详细介绍了用于综合的良好Verilog编码实践: http : //www.sunburst-design.com/papers/CummingsSNUG2000SJ_NBA.pdf


Other issues you will have: 您将遇到的其他问题:

  • Use non-blocking ( <= ) when assigning registers. 分配寄存器时,请使用非阻塞( <= )。 This is discussed in Cliff's paper mentioned earlier. 前面提到的Cliff的论文对此进行了讨论。
  • Get rid of the initial block. 摆脱最初的障碍。 I understand some FPGA synthesizers allow it and some ignore it. 我了解一些FPGA合成器允许它,而有些则忽略它。 It is a better practice to have an asynchronous to put everything into a known and predictable value. 更好的做法是使用异步方法将所有内容置为已知且可预测的值。
  • The block starting with always @ (clk or start_reg or lap_reg or reset_reg) has a bizarre sensitivity list and will likely give you problems. always @ (clk or start_reg or lap_reg or reset_reg)开头的块具有奇怪的敏感性列表,可能会给您带来问题。 you wither want @(*) if you want combination logic or @(posedge clk or posedge reset_reg) for synchronous flops. 如果需要组合逻辑,或者要使用@(posedge clk or posedge reset_reg)进行同步触发器,则需要使用@(*)
  • Very rarely dual edge flops are used. 很少使用双边缘触发器。 The line always @ (posedge clk or negedge clk) should be always @ (posedge clk) for synchronous or always @(*) for combination logic. 对于同步行, always @ (posedge clk or negedge clk)always @ (posedge clk) ,对于组合逻辑,应always @ (posedge clk)always @(*)

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

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