简体   繁体   English

Verilog 对具有同步复位 (R) 的边沿触发 T 触发器的结构描述

[英]Verilog Structural description of an Edge-triggered T flip-flop with an synchronous reset (R)

I am trying to wire a Verilog Structural description of an Edge-triggered T flip-flop with an synchronous reset (R).我正在尝试将边缘触发的 T 触发器的 Verilog 结构描述与同步复位 (R) 连接起来。 Here is the circuit for this element:这是这个元素的电路:

在此处输入图像描述

Now assume that I have already written the behavioral description for each block in this schematic, so here is my structural description for this circuit by instantiation of each of this blocks in the circuit:现在假设我已经为这个示意图中的每个模块编写了行为描述,所以这是我通过电路中每个模块的实例化对该电路的结构描述:

    module edge_trig_flipflop_structure (
input x,y,clk,
  output q,
  wire a,b,c,d
);
  inv u1(c,q);
  mux_2x1 u2 (q,c,x,a);
  inv u3(d,y);
  and_2_1 u4(b,a,d);
  d_flipflop u5(b,clk,q);
endmodule

Is this a good efficient code for this circuit?这是该电路的高效代码吗? In other words, do I really need the two extra wires used for the inverters which are the wires c and d Or, is there another efficient way to write this code?换句话说,我真的需要用于逆变器的两条额外电线,即电线cd或者,是否有另一种有效的方法来编写此代码?

Edit: Here is the code for each component to know the order of ports in the declaration of each component编辑:这是每个组件的代码,用于了解每个组件声明中的端口顺序

module mux_2x1 (
input a,
input b,
input sel,
output reg c
);
 
  always @ (*) begin 
    case ( sel)
      1'b0: c=a;
      1'b1: c=b;
      default : $dispaly ("error");
   endcase
 end
        
  
endmodule 

module d_flipflop ( input d,clk , output reg q);

 always @ (posedge clk ) begin
   q=d;
      
  end 
  
endmodule
module inv(output reg b, input a);
  
  always @ (a) begin 
    b=~a;
  
  
  
  end
  
endmodule

module and_2_1 ( output reg c,input a,b);

always @(a or b) begin 
  if (a==1'b1 & b==1'b1)
    c= 1'b1;
  else
    c=1'b0;
  

end

endmodule

By default, Verilog does not require you to declare all signals.默认情况下,Verilog 不要求您声明所有信号。 If signals appear in port connections, they will implicitly be 1-bit wire types.如果信号出现在端口连接中,它们将隐含为 1 位wire类型。

However, it is good practice to declare all signals explicitly with wire , as you have done.但是,正如您所做的那样,使用wire显式声明所有信号是一种很好的做法。

You could also change the default behavior and require explicitly declared signals using this compiler directive:您还可以使用此编译器指令更改默认行为并要求显式声明的信号:

`default_nettype none

Since you are also concerned about connections, it is a good practice to make connections by name instead of connections by position.由于您还关心连接,因此最好按名称而不是按 position 进行连接。 It is more verbose, but it will help avoid simple connection errors.它更详细,但有助于避免简单的连接错误。 For example:例如:

  inv u1 (.b(c), .a(q));

I got compile errors on your module header.我的模块 header 出现编译错误。 You probably meant to code it this way:您可能打算这样编码:

module edge_trig_flipflop_structure (
  input x,y,clk,
  output q
);

  wire a,b,c,d;

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

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