【问题标题】:4-bit register using D flip-flop with enable and asynchronous reset使用 D 触发器的 4 位寄存器,具有启用和异步复位功能
【发布时间】:2021-01-15 13:04:25
【问题描述】:

我正在使用具有启用和异步复位功能的 D 触发器对 4 位寄存器进行建模。它包含 4 个 D FF 和 4 个 2:1 Mux。我使用结构 Verilog 对电路进行建模。

我的设计如下所示。

module DFlipFlop(D,clk,reset,Q);
input D; 
input clk,reset; 
output Q;
reg Q;
always @(posedge clk or posedge reset) 
begin
 if(reset==1'b1)
  Q <= 1'b0; 
 else 
  Q <= D; 
end 
endmodule

module m21(D0, D1, S, Y);
output Y;
input D0, D1, S;
assign Y=(S)?D1:D0;
endmodule

module DFF_with_Enable(D,clk,enable,reset,Q);
  input D,clk,reset,enable;
  output Q;
  reg Q;
  wire in;
      m21 mux(D,in,enable,in);
      DFlipFlop DFF(in,clk,reset,Q); 
endmodule

module fourbitreg(D,clk,reset,enable, Q);
  input[0:3] D; // Data input
input clk,reset,enable;
  output [3:0]Q;
  reg [3:0]Q;
  wire d0,d1,d2,d3;
  wire q0,q1,q2,q3;
  d0 = D[0];
  d1 = D[1];
  d2 = D[2];
  d3 = D[3];
  DFF_with_Enable df0(d0,clk,reset,enable,q0);
  DFF_with_Enable df1(d1,clk,reset,enable,q1);
  DFF_with_Enable df2(d2,clk,reset,enable,q2);
  DFF_with_Enable df3(d3,clk,reset,enable,q3);
        
       assign Q = {q0,q1,q2,q3};
endmodule

我使用iverilog 进行模拟。编译时出现以下错误如何解决?

design.sv:37: syntax error
design.sv:37: error: Invalid module instantiation
design.sv:38: error: Invalid module instantiation
design.sv:39: error: Invalid module instantiation
design.sv:40: error: Invalid module instantiation

1 个 DFF MUX 对的电路如下所示。

【问题讨论】:

  • 您的意思是assign d0 = D[0];? (对于 1、2、3 也一样)
  • 我有一个 4 位输入 D,我想将 1 位分别分配给 d0、d1、d2 和 d3。
  • 是的。您是否尝试过使用assign d0 = D[0]; 而不是d0 = D[0];

标签: verilog fpga


【解决方案1】:

有多个编译错误。

DFF_with_Enablefourbitreg 中,不要将Q 声明为reg,因为您对Q 进行连续赋值。

需要使用assign关键字连续赋值d0等:

  assign d0 = D[0];
  assign d1 = D[1];
  assign d2 = D[2];
  assign d3 = D[3];

您还应该在 edaplayground 上尝试不同的模拟器以获得更有意义的错误消息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多