fpga延时程序编写
2016-01-04 15:14 工匠小建 阅读(2565) 评论(0) 编辑 收藏 举报//工匠小建 延时计数 100微妙计数 50M*0.00001-1 (个人理解:1s中50M次动作。那么100us多少次动作。做完这些动作就是延时)
parameter delay_100us=16'd49_999;
/************************************/
reg [15:0] count_1ms;
reg star_dleay;
/************************************/
//延时模块 100us后开始工作
always@(posedge i_i_clk or negedge i_rst)
if( !i_rst )
count_1ms <= 16'd0;
else if( star_dleay && count_1ms == delay_100us)
count_1ms <= 16'd0;
else if( star_dleay )
count_1ms <= count_1ms + 1'b1;
else if( !star_dleay )
count_1ms <= 16'd0;
/****************************************/
reg [9:0]Count_MS;
always@(posedge i_i_clk or negedge i_rst)
if( !i_rst )
Count_MS <= 10'd0;
else if( star_dleay && count_1ms == delay_100us)
Count_MS <= Count_MS + 1'b1;
else if( !star_dleay )
Count_MS <= 10'd0;
/******************************************/
这个程序的应用 只要控制stardelay 就开始计时,延时时间可任意设定(根据对晶振的计算)
工匠小建--希望对大家有帮助