FPGA Practice (II) 8 LED Lights on and off and Flowing Lights[Copy link]
This post was last edited by bqgup on 2019-4-12 21:24 The external clock of the board I use is 50MHz, and the clock pin is PIN_23. The on and off state of the light is just what our eyes can distinguish. The state of the light changes very quickly, maybe once every 10ms, but due to the limit of human eye resolution, we cannot perceive this limit, so we can only see the change of the state of the light after the time exceeds the limit of our vision. Because our clock is 50MHz, the frequency is very high. In order for us to distinguish the state change of the light, we need to make the light last longer, which is what we usually call "delay". Delay is often used in microcontroller development, but we cannot call it delay in FPGA, because our microcontroller is executed sequentially, and each instruction executed must wait for a certain period of time, while our FPGA runs in parallel, so it runs faster than our microcontroller. So what else can we call FPGA if not delay? FPGA can divide and multiply the frequency. Through dividing and multiplying the frequency, we can change the frequency to very low or very high. The change of frequency means the change of time, so the "delay" of FPGA is called dividing the frequency. Let's first look at the change of light on and off. Because our external clock frequency is 50M, a change requires 1/50M=0.02us. If we want to "delay" 1000ms, it needs to change 50_000_000. We can realize the light on and off based on this principle.
The effect after downloading is as follows:
1.mp4(1.11 MB, downloads: 21)
2019-4-12 20:24 上传
点击文件名下载附件
LED on and off project file:
3、LED闪烁.rar(312.72 KB, downloads: 18)
2019-4-12 20:53 上传
点击文件名下载附件
The principle of flowing light also uses the persistence of vision. The principle is similar to the on and off state, but it is necessary to switch the on and off of several lights in real time to achieve the flowing light effect. The HDL language is as follows:
module LED_Water( input ext_clk_50M, output reg[7:0] LED ); reg[31:0] cnt; always @ (posedge ext_clk_50M) if(cnt == 32'd400_000_000) cnt <= 32'd0; else cnt <= cnt + 1'd1; always @ (posed ge ext_clk_50M) if(cnt == 32'd50_000_000) LED <= 8'b1000_0000; else if(cnt == 32'd100_000_000) LED <= 8'b0100_0000; else if(cnt == 32'd150_000_000) LED <= 8'b0010_0000; else if(cnt == 32'd200_000_000) LED <= 8'b0001_0000; else if(cnt == 32'd250_000_000) LED <= 8'b0000_1000; else if(cnt == 32'd300_000_000) LED <= 8'b0000_0100; else if(cnt == 32'd350_000_000) LED <= 8'b0000_0010; else if(cnt == 32'd400_000_000) LED <= 8'b0000_0001; endmodule
复制代码
The water flow effect is from right to left, the effect is as follows:
2.mp4(1.1 MB, downloads: 27)
2019-4-12 21:20 上传
点击文件名下载附件
Flowing light program (project file):
4、LED流水.rar(397.75 KB, downloads: 47)