[vivado2019.2+Ubuntun16.04]同步复位和异步复位tb仿真及源码
一、sync_reset
1.新建项目
由于我只仿真就不选板卡了,直接finish
2.Add Design Sources 文件 
也可以
之后就是一路ok,finsh就行了。个人习惯在设计文件名后面加上“_top”。
接着就可以在右侧编写verilog程序了,
下面展示一些 内联代码片
。
`timescale 1ns / 1ps
//
// Company:
// Engineer: wty
//
// Create Date: 2021/04/17 18:08:09
// Design Name:
// Module Name: sync_reset_top
// Project Name: sync_reset
// Target Devices:
// Tool Versions: ubuntun16.04+vivado2019.2
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//
//define ports
module sync_reset_top(
input wire clk,
input wire rst_n,
input wire data_in,
output reg data_out
);
//define The data type
always @ (posedge clk)
if (!rst_n)
data_out <= 1'b0;
else
data_out <= data_in;
endmodule
3.综合RTL电路
之后点击save—ok,等待一会电路图就综合出来了。
4.编写testbench仿真文件
自己不是很会写tb,请教过学长后。自己写了tb,之前写过好久不写就忘了。
下面展示一些 内联代码片
。
`timescale 1ns / 1ps
//
// Company:
// Engineer: wty
//
// Create Date: 2021/04/17 23:29:29
// Design Name:
// Module Name: sync_reset
// Project Name: sync_reset.v
// Target Devices:
// Tool Versions: ubuntun16.04+vivado2019.2
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//
module sync_reset();
reg clk;
reg rst_n;
reg data_in;
wire data_out;
initial
begin
clk = 1;
rst_n = 0;
data_in = 1;
#100;
clk = 0;
rst_n = 1;
data_in = 1;
#100;
end
always #100 data_in = ~data_in ;
always #150 clk = ~clk;
always #100 rst_n = ~rst_n;
sync_reset_top sync_reset (
.clk(clk),
.rst_n(rst_n),
.data_in(data_in),
.data_out(data_out)
);
endmodule
5.波形仿真
根据波形可以看到,当rst_n踩到clk的上升沿的时候data_out等于data_in。当rst_n没有踩到时钟上升沿的时候,也就是时钟上升沿来临时没有复位信号,data_out给0。
6.总结
对同步复位有了差不多的了解,但应该结合异步复位来对比。异步复位的文章正在写,等写出来在做两者比较系统的总结。也通过这个小例子在复习一下好久没用的vivado,加油!
更新异步复位
二、async_reset
1.verilog源码
下面展示一些 内联代码片
。
`timescale 1ns / 1ps
//
// Company:
// Engineer:
//
// Create Date: 2021/04/20 13:32:44
// Design Name: wty
// Module Name: async_reset
// Project Name: async_reset
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//
module async_reset(
input wire clk ,
input wire rst_n ,
input wire data_in ,
output reg data_out
);
always @ (posedge clk or negedge rst_n)
if(!rst_n)
data_out <= 1'b0 ;
else
data_out <= data_in ;
endmodule
异步复位是指只要复位信号有效就执行复位操作。即使是在时钟有效边沿未到来的时候,寄存器也执行复位操作。
2.编写tb并仿真
下面展示一些 内联代码片
。
`timescale 1ns / 1ps
//
// Company:
// Engineer:
//
// Create Date: 2021/04/20 14:08:41
// Design Name:
// Module Name: async_reset_sim
// Project Name: wty
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//
module async_reset_sim();
reg clk ;
reg rst_n ;
reg data_in ;
wire data_out ;
initial
begin
clk = 1 ;
rst_n = 0 ;
data_in = 1 ;
#100;
clk = 0 ;
rst_n = 1 ;
data_in = 0 ;
#100;
end
always #100 data_in = ~data_in ;
always #100 clk = ~clk ;
always #200 rst_n = ~rst_n ;
async_reset async_reset(
.clk(clk) ,
.rst_n(rst_n) ,
.data_in(data_in) ,
.data_out(data_out)
);
endmodule
可以看到复位信号或者时钟上升沿来临时,如果此时有复位信号则data_out为data_in。如果不是复位信号out信号为0。