1.IDE:Quartus II
2.设备:Cyclone II EP2C8Q208C8N
3.实验:同步时序电路与异步时序电路
4.时序图:
同步时序电路:
异步时序电路:
5.步骤
6.代码:
同步时序电路代码:
/*
*同步时序电路代码
*/
module tb_yb(
input wire sys_clk,
input wire sys_rst_n,
input wire key_in,
output reg led_out
);
/*
*同步时序电路
*/
always @ (posedge sys_clk) begin
if(sys_rst_n == 1'b0)
led_out <= 1'b0;
else
led_out <= key_in;
end
endmodule
异步时序电路代码:
/*
*异步时序电路代码
*/
module tb_yb(
input wire sys_clk,
input wire sys_rst_n,
input wire key_in,
output reg led_out
);
/*
*异步时序电路
*/
always @ (posedge sys_clk or negedge sys_rst_n) begin
if(sys_rst_n == 1'b0)
led_out <= 1'b0;
else
led_out <= key_in;
end
endmodule
时序电路仿真代码:
/*
*时序电路仿真代码
*/
`timescale 1ns/1ns
module tp_tb_yb();
reg sys_clk;
reg sys_rst_n;
reg key_in;
wire led_out;
initial
begin
sys_clk =1'b1;
sys_rst_n <=1'b0;
key_in <= 1'b0;
#20 //延时20ns
sys_rst_n <=1'b1;
#210
sys_rst_n <=1'b0;
#40
sys_rst_n <=1'b1;
end
always #10 sys_clk = ~ sys_clk; //模拟时钟
always #20 key_in <= {$random}%2; //随机赋值
/*
*监视窗
*/
initial
begin
$timeformat(-9,0,"ns",6); //ns单位,无小数位,位宽6位
$monitor("@time %t:key_in=%b,led_out=%b",$time,key_in,led_out);
end
/*
*实例化
*/
tb_yb tb_yb_inst(
.sys_clk (sys_clk) ,
.sys_rst_n (sys_rst_n) ,
.key_in (key_in) ,
.led_out (led_out)
);
endmodule