4259 views|4 replies

693

Posts

7

Resources
The OP
 

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.
  1. module LED_Flash( input ext_clk_50M, output reg D1 ); reg[31:0] cnt; always [url=home.php?mod=space&uid=775551]@[/url] (posedge ext_clk_50M) if(cnt < 32'd100_000_000) cnt <= cnt + 1'b1;/ /Period else cnt <= 32'd0; always @ (posedge ext_clk_50M) if(cnt > 32'd50_000_000) D1 <= 1'b1; //ON, duty cycle else D1 <= 1'b0; //OFF, duty cycle endmodule
复制代码
The effect after downloading is as follows: 1.mp4 (1.11 MB, downloads: 21) LED on and off project file: 3、LED闪烁.rar (312.72 KB, downloads: 18) 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:
  1. 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) Flowing light program (project file): 4、LED流水.rar (397.75 KB, downloads: 47) Welcome all netizens to communicate together


This post is from Innovation Lab

Latest reply

Great job, keep it up sir!  Details Published on 2019-4-13 22:23
 
 

693

Posts

7

Resources
2
 
The speed and direction of the water light can be changed
This post is from Innovation Lab
 
 
 

173

Posts

0

Resources
3
 
Thanks for sharing!
This post is from Innovation Lab
Personal signature服务器大全
 
 
 

1368

Posts

6

Resources
4
 
Great job, keep it up sir!
This post is from Innovation Lab

Comments

Thanks  Details Published on 2019-4-14 21:41
Personal signature专注智能产品的研究与开发,专注于电子电路的生产与制造……QQ:2912615383,电子爱好者群: void
 
 
 

693

Posts

7

Resources
5
 
Thank you
This post is from Innovation Lab
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list