VL2 异步复位的串联T触发器
设有一个输入T和输出Q,当时钟上升沿时,如果T和Q不相同时,其输出值会是1。(异或 )
这时:Q为1:
mux(T == 1,Q = ~Q,Q = Q)
以上是一个T触发器
verilog代码:
c
timescale 1ns/1ns
module Tff_2 (
input wire data, clk, rst,
output reg q
);
//*************code***********//
reg a ;
always @(posedge clk or negedge rst )begin
if (!rst)begin
a <= 1'b0;
q <= 1'b0;
end else begin
a <= data ^ a;
q <= a ^ q ;
end
end
//*************code***********//
endmodule
testbench:
````timescale 1ns / 1ps
module tff_2_tb();
// Tff_2 Parameters
parameter PERIOD = 10;
// Tff_2 Inputs
reg data_T ;
reg clk ;
reg rst ;
// Tff_2 Outputs
wire q ;
initial
begin
clk = 0;
forever #(PERIOD/2) clk=~clk;
end
initial
begin
rst = 0;
data_T = 1'd0;
#(PERIOD*2) rst = 1;
#50 data_T = 1'd0;
#50 data_T = 1'd1;
#50 data_T = 1'd0;
#50 data_T = 1'd1;
#50 data_T = 1'd0;
$finish;
end
Tff_2 Tff_2_TB (
.data(data_T),
.clk(clk),
.rst(rst),
.q(q)
);
endmodule
波形:
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/4a8b34ea2f8649569acc6c47148e31a5.png)