简体   繁体   English

使用 D 触发器的 4 位寄存器,具有启用和异步复位功能

[英]4-bit register using D flip-flop with enable and asynchronous reset

I am modelling a 4-bit register using D flip-flops with enable and asynchronous reset.我正在使用具有启用和异步复位功能的 D 触发器对 4 位寄存器进行建模。 It contains 4 D FF and 4 2:1 Mux.它包含 4 个 D FF 和 4 个 2:1 Mux。 I used structural Verilog to model the circuit.我用结构Verilog来model电路。

My design is shown below.我的设计如下图所示。

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

I used iverilog for simulation.我使用iverilog进行模拟。 How do I fix the following errors during compilation?如何在编译期间修复以下错误?

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

The circuit of 1 DFF MUX pair is shown below. 1 个 DFF MUX 对的电路如下所示。

电路

There are multiple compile errors.有多个编译错误。

Inside DFF_with_Enable and fourbitreg , do not declare Q as a reg because you make continuous assignments to Q .DFF_with_Enablefourbitreg中,不要将Q声明为reg ,因为您对Q进行了连续分配。

You need to use the assign keyword to make continuous assignments to d0 , etc.:您需要使用assign关键字对d0等进行连续分配:

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

You should also try different simulators on edaplayground to get more meaningful error messages.您还应该在 edaplayground 上尝试不同的模拟器以获得更有意义的错误消息。

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

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