1. led_test
`timescale 1ns / 1ps
module led_test(
input clk,
input rst,
(* MARK_DEBUG="true" *)output reg[3:0] led
);
(* MARK_DEBUG="true" *)reg[31:0] counter;
always@(posedge clk or negedge rst)
begin
if(!rst)
begin
led <= 4'd0;
counter <=0;
end
else if(counter > 32'd 24_999_999)
begin
counter <=32'd0;
led <= ~led;
end
else
begin
led <=led;
counter <= counter + 32'd1;
end
end
endmodule
这是很简单的一个led测试,通过计数器产生1s的延时,led反转并重新计时。
遇到的问题:
(1) 仿真时,代码是没有问题的,在实际的测试验证中,发现时钟一直置为高位,检查时钟,发现时钟没有问题,最后的排查为引脚分配错误,将复位的引脚和时钟引脚接反了。
(ps. 在检查的时候一定要检查引脚分配,尤其是时钟不正常的时候!)
2. pll_test
`timescale 1ns / 1ps
module pll_test(
input clk,
input rst,
output clk_out,
output reg led_first_out,
output reg led_second_out
);
wire locked;
wire clk_buf;
wire clk_50M;
reg[31:0] first_counter;
reg[31:0] second_counter