说明:LED以一个固定时间周期,状态进行翻转,即闪烁
module counter
#(
parameter count_max = 25'd24_999_999 //在综合多次调用程序时,可以是同一个变量,便于修改,仿真时如果将它定义为其他值,这里赋值就不起作用了
)
(
input wire clk,
input wire rst_n,
output reg led
);
reg [24:0] count;
reg count_flag;
always @(posedge clk or negedge rst_n) //单独对计数进行操作
if (~rst_n)
count <= 0;
else if (count == count_max)
count <= 0;
else
count <= count+1'd1;
always@ (posedge clk or negedge rst_n) //计数标志位
if (~rst_n)
count_flag <= 1'b0;
else if (count == count_max-25'b1) //减一是因为时序会延迟一拍,所以早一个周期进行判别
count_flag <= 1'b1;
else
count_flag <= 1'b0;
always@(posedge clk or negedge rst_n)
if (~rst_n)
led <= 1'd0;
else if (count_flag)
led <= ~led;
else
led <= led;
endmodule
module vtf_counter;
// Inputs
reg clk;
reg rst_n;
// Outputs
wire led;
// Instantiate the Unit Under Test (UUT)
counter
#(
.count_max(24'd24) //在这里对它进行了赋值(改小,方便看时序图),所以counter.v程序中对它的赋值不起作用了
)
uut (
.clk(clk),
.rst_n(rst_n),
.led(led)
);
initial begin
// Initialize Inputs
clk = 0;
rst_n <= 0;
// Wait 100 ns for global reset to finish
#100;
rst_n <= 1;
// Add stimulus here
end
always #10 clk = ~clk;
endmodule