中山网站网站建设,旅游网站色彩搭配,站长工具seo综合查询引流,高端零食品牌有哪些fpga流水灯的设计
思路#xff1a;外部时钟频率50mhz#xff0c;若要实现每隔0.5s闪烁一次#xff0c;则使用内部计数器计数到24999999拉高一个周期电平#xff0c;当电平被拉高的时候#xff0c;进行LED灯电平的设置#xff0c;每次检测到高电平#xff0c;就进行一位…fpga流水灯的设计
思路外部时钟频率50mhz若要实现每隔0.5s闪烁一次则使用内部计数器计数到24999999拉高一个周期电平当电平被拉高的时候进行LED灯电平的设置每次检测到高电平就进行一位LED灯的设置进行循环设置就形成了流水灯的设计。
module flow_led
#(parameter cnt_max 25d24999999) //0.5s闪烁一下
(input wire clk,
input wire rst,
output reg [3:0] led);reg [24:0] cnt;
reg cnt_flag;always(posedge clk or negedge rst )beginif(rst1b0)cnt25d0;else if(cntcnt_max)cnt25d0;elsecntcnt25d1;endalways(posedge clk or negedge rst)beginif(rst1b0)cnt_flag1b0;else if(cnt (cnt_max)-1)cnt_flag1b1;elsecnt_flag1b0;endalways(posedge clk or negedge rst)beginif(rst1b0)led 4b1110;else if(cnt_flag1b1 led 4b1110)led 4b1101;else if(cnt_flag1b1 led 4b1101)led 4b1011;else if(cnt_flag1b1 led 4b1011)led 4b0111;else if(cnt_flag1b1 led 4b0111)led 4b1110; endendmodule 测试代码 timescale 1ns/1ns
includeflow_led.vmodule top();reg clk;
reg rst;
wire [3:0] led;initialbeginrst 1b0;clk 1b0;#20rst 1b1;endalways #10 clk~clk;flow_led
#(.cnt_max (25d24))
led_inst(clk,rst,led);endmodule