【问题标题】:2 Bit Counter using JK Flip Flop in VerilogVerilog 中使用 JK 触发器的 2 位计数器
【发布时间】:2014-10-02 18:15:24
【问题描述】:

我正在使用 JK 触发器编写 2 位计数器的 verilog 代码,计数 0-3 并返回到 0。我正在使用 Xilinx EDA。但是我不断收到一个错误,我不知道这意味着什么?行号未显示在此处,但错误位于“always @(posedge clk)”。

ERROR:HDLCompiler:1401 - "C:\Users\Eduardo\Documents\SFSU\Fall 2014\Engr 378\Lab 3\TwoBitCounter\twobitcounter.v" 第 30 行:单元 jkff 中的信号 q 连接到以下多个驱动程序:

`timescale 1ns / 1ps
module twobitcounter( q_out, qbar_out, j,k, clk, reset);
    input [1:0] j; input [1:0] k; input clk; input reset;
    output [1:0] q_out;
    output [1:0] qbar_out;
    wire [1:0] q_out;
    wire [1:0] qbar_out;
    wire clk;

    assign qbar_out[0] = ~q_out[0];
    assign j[0] = 1;
    assign k[0] = 1;
    assign j[1] = q_out[0];
    assign k[1] = q_out[0]; 

    jkff M1(q_out[0], qbar_out[0], j[0], k[0], clk, reset);
    jkff M2(q_out[1], qbar_out[1], j[1], k[1], qbar_out[0]);

endmodule

module jkff(output q_out, output qbar_out,
  input j, input k, input clk, input reset);

    reg q;
    assign q_out = q;
    assign qbar_out = ~q;

    initial begin 
        q = 1'b0;
        end
    always @(posedge clk)
        begin
        case({j,k})
        {1'b0, 1'b0}: begin
            q = q;
            end
        {1'b0, 1'b1}: begin
            q = 1'b0;
            end
        {1'b1, 1'b0}: begin
            q = 1'b1;
            end
        {1'b1, 1'b1}: begin
            q = ~q;
            end
        endcase
        end

    always @(posedge reset)
        begin
        q = 1'b0;
        end
endmodule

【问题讨论】:

    标签: counter verilog flip-flop


    【解决方案1】:

    问题是q 被设置在两个always 块中,这在综合中是不允许的。合并两个 always 块。另外,q 是一个 flop,因此应该使用非阻塞赋值 (<=) 进行赋值,而不是阻塞赋值 (=)。

    always @(posedge clk or posedge reset)
    begin
      if (reset == 1'b1) begin
        q <= 1'b0;
      end
      else begin
        case({j,k})
        {1'b0, 1'b0}: begin
            q <= q;
            end
        {1'b0, 1'b1}: begin
            q <= 1'b0;
            end
        {1'b1, 1'b0}: begin
            q <= 1'b1;
            end
        {1'b1, 1'b1}: begin
            q <= ~q;
            end
        endcase
      end
    end
    

    您几乎不应该在可综合代码中使用initial 块。大多数 FPGA 允许它进行初始化。然而,ASIC 设计不支持它。对于这两种情况,如果存在异步重置/设置,则不应使用它的初始块。

    【讨论】:

    • 我尝试了你的建议,但它给了我与模块 twobitcounter 相同的错误。我在“assign qbar_out[0] = ~q_out[0];”处收到错误它指出 qbar_out[0] 连接到以下多个驱动程序
    • q_out[0]qbar_out[0] 都是 M1 的输出。这使得它是非法的双驱动程序。注释掉assign qbar_out[0] = ~q_out[0];。您还缺少 M2 上的端口连接
    【解决方案2】:

    错误是告诉您您在不同的块中分配 q。这会产生错误。您在 initial 块和 always 块中分配 q。

    你不应该在可合成代码中使用initial 块。

    【讨论】:

    • **几乎从不使用初始块(大多数 FPGA 综合工具在某些情况下分配初始块,例如初始化内存元素)。此外,在 @(posedge reset) 块中也分配了 q。
    猜你喜欢
    • 1970-01-01
    • 2014-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    相关资源
    最近更新 更多