module pregate(clk,gateout);
input clk; //输入标准时钟
output gateout;//输出预设闸门信号
reg gateout,gatebuf;
reg [31:0] cnt;//计数器
always @(posedge clk)
begin
//计数值越大,闸门时间越长
if(cnt==32'd50000000)
begin
gatebuf<=~gatebuf;
gateout<=gatebuf;
cnt<=32'd0;
end
else
begin
cnt<=cnt+32'd1;
end
end
endmodule
开发板内部晶振是50MHz,上述程序对内部晶振产生的时钟进行分频,每50000000个标准脉冲,输出电平翻转一次,最终得到周期2s的信号。