让led闪烁
module led(sys_clk,
sys_rstn,
led
);
input sys_clk;
input sys_rstn;
output [2:0] led;
reg [2:0] led;
reg [24:0] delay_cnt;
always@(posedge sys_clk or negedge sys_rstn)
begin
if(!sys_rstn)
delay_cnt <= 25'd0;
else
begin
if(delay_cnt == 25'd24999999)
delay_cnt <= 25'd0;
else
delay_cnt<=delay_cnt+1'b1;
end
end
always@(posedge sys_clk or negedge sys_rstn)
begin
if(!sys_rstn)
led<=3'b111;
else
begin
if(delay_cnt==25'd24999999)
led<=~led;
else
led<=led;
end
end
endmodule
此帖出自
小平头技术问答
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:Liqingtao
//
// Create Date: 09:51:48 11/22/2016
// Design Name:
// Module Name: div
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module div(
clk,
rst_n,
div_clk
);
//input signal;
input clk;
input rst_n;
//output signal;
output div_clk;
reg [31:0] counter;
reg div_clk;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
counter <= 32'd0;
div_clk <= 1'b0;
end
else begin
if(counter==32'h17d7840)
begin
counter <=32'h0;
div_clk <=~div_clk;
end
else
counter <= counter+1'b1;
end
end
endmodule
PS:分频模块;跨时钟信号自己利用计数器进行分频容易出现亚稳态,建议使用PLL进行分/倍频;
一周热门 更多>