这是我的代码:
//`timescale 1ns / 1ps
module FourBitLedToggle(
input res,
input Clk,
output [3:0] led
);
reg [27:0] count;//for 1 second check
reg clk1s;//1 second clock
reg [3:0]counterled;
always @(posedge Clk)
begin
if(res==1'b1) //CHECK RESET
begin
clk1s<=1'b1;
count<=0;
end
else begin
if(count==28'h2FAF080)//0.5 sec //CHECKS IF SEC COMPLETED
begin
clk1s <= ~clk1s;
count <= 0;
end
else begin
count <=count+1;
end
end
end
always @(posedge clk1s) //CHECKS EVERY POSITIVE EDGE OF CLK1S
begin
counterled<=counterled+4'b0001;
end
assign led=counterled;
endmodule
这是我使用的测试平台: //我猜我只需要clk
`timescale 1us / 1us
module FourBitToggleCheck;
// Inputs
reg res;
reg Clk;
// Outputs
wire [3:0] led;
// Instantiate the Unit Under Test (UUT)
FourBitLedToggle uut (
.res(res),
.Clk(Clk),
.led(led)
);
initial begin
// Initialize Inputs
res = 0;
Clk = 0;
forever
#10 Clk=~Clk;
end
initial begin
res=1;
#20;
res=0;
end
endmodule
这是我的模拟结果:
我无法理解如何在模拟中引入 4 位计数器所需的增量行为。任何帮助将不胜感激。
28'h2FAF080
与 28'd50_000_000
相同。 这太多了 2000 倍。应该是25_000
。 变化:
if(count==28'h2FAF080)//0.5 sec //CHECKS IF SEC COMPLETED
至:
if(count==28'd24_999)//0.5 sec //CHECKS IF SEC COMPLETED
现在,
clk1s
的周期为1秒。
然后您需要将
counterled
重置为0:
always @(posedge clk1s) //CHECKS EVERY POSITIVE EDGE OF CLK1S
begin
if (res) begin
counterled <= 0;
end else begin
counterled <= counterled + 4'b0001;
end
end