带同步复位的边沿触发 T 触发器的 Verilog 结构描述 (R)
Verilog Structural description of an Edge-triggered T flip-flop with an synchronous reset (R)
我正在尝试连接边沿触发 T 触发器的 Verilog 结构描述和同步复位 (R)。这是该元件的电路:
现在假设我已经为这个示意图中的每个块编写了行为描述,所以这是我通过电路中每个块的实例化对该电路的结构描述:
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
对于这个电路来说,这是一个很好的高效代码吗?换句话说,我真的需要用于逆变器的两条额外电线,即电线 c
和 d
或者,还有另一种有效的方法来编写这段代码吗?
编辑:这里是每个组件的代码,以了解每个组件声明中端口的顺序
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
默认情况下,Verilog 不要求您声明所有信号。如果信号出现在端口连接中,它们将隐式为 1 位 wire
类型。
但是,像您所做的那样,使用 wire
显式声明所有信号是一种很好的做法。
您还可以更改默认行为并要求使用此编译器指令显式声明信号:
`default_nettype none
由于您也关心连接,因此按名称而不是按位置连接是一个很好的做法。它比较冗长,但有助于避免简单的连接错误。例如:
inv u1 (.b(c), .a(q));
我在你的模块头上遇到了编译错误。您可能打算这样编码:
module edge_trig_flipflop_structure (
input x,y,clk,
output q
);
wire a,b,c,d;
我正在尝试连接边沿触发 T 触发器的 Verilog 结构描述和同步复位 (R)。这是该元件的电路:
现在假设我已经为这个示意图中的每个块编写了行为描述,所以这是我通过电路中每个块的实例化对该电路的结构描述:
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
对于这个电路来说,这是一个很好的高效代码吗?换句话说,我真的需要用于逆变器的两条额外电线,即电线 c
和 d
或者,还有另一种有效的方法来编写这段代码吗?
编辑:这里是每个组件的代码,以了解每个组件声明中端口的顺序
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
默认情况下,Verilog 不要求您声明所有信号。如果信号出现在端口连接中,它们将隐式为 1 位 wire
类型。
但是,像您所做的那样,使用 wire
显式声明所有信号是一种很好的做法。
您还可以更改默认行为并要求使用此编译器指令显式声明信号:
`default_nettype none
由于您也关心连接,因此按名称而不是按位置连接是一个很好的做法。它比较冗长,但有助于避免简单的连接错误。例如:
inv u1 (.b(c), .a(q));
我在你的模块头上遇到了编译错误。您可能打算这样编码:
module edge_trig_flipflop_structure (
input x,y,clk,
output q
);
wire a,b,c,d;