1360 views|0 replies

32

Posts

0

Resources
The OP
 

Mingdeyang FPGA project practice 1-bit flashing light design [Copy link]


1 Project Background
LED (Light Emitting Diode) is a solid-state semiconductor device that can convert electrical energy into visible light. It can directly convert electricity into light. The heart of LED is a semiconductor chip. One end of the chip is attached to a bracket, one end is the negative pole, and the other end is connected to the positive pole of the power supply, so that the entire chip is encapsulated by epoxy resin.
The semiconductor chip consists of two parts, one part is a P-type semiconductor, in which holes dominate, and the other end is an N-type semiconductor, which is mainly electrons. But when these two semiconductors are connected, a PN junction is formed between them. When the current acts on the chip through the wire, the electrons will be pushed to the P area, where the electrons and holes recombine and then emit energy in the form of photons. This is the principle of LED light emission. The wavelength of light, that is, the color of light, is determined by the material that forms the PN junction.
LED can directly emit red, yellow, blue, green, cyan, orange, purple, and white light.
Initially, LED was used as an indicator light source for instruments and meters. Later, LEDs of various light colors were widely used in traffic lights and large-area display screens, producing good economic and social benefits. Take a 12-inch red traffic light as an example. In the United States, a long-life, low-light-efficiency 140-watt incandescent lamp was originally used as the light source, which produces 2,000 lumens of white light. After passing through the red filter, 90% of the light is lost, leaving only 200 lumens of red light. In the newly designed lamp, Lumileds uses 18 red LED light sources, including circuit losses, and consumes a total of 14 watts of power to produce the same light effect. Car signal lights are also an important application area for LED light sources. For general lighting, people need white light sources more. In 1998, white light LEDs were successfully developed. This type of LED is made by encapsulating GaN chips and yttrium aluminum garnet (YAG) together. The GaN chip emits blue light (λp=465nm, Wd=30nm), and the YAG phosphor containing Ce3+ made by high-temperature sintering emits yellow light after being excited by this blue light, with a peak value of 550nm. The blue light LED substrate is installed in a bowl-shaped reflective cavity and covered with a thin layer of resin mixed with YAG, about 200-500nm. Part of the blue light emitted by the LED substrate is absorbed by the phosphor, and the other part of the blue light is mixed with the yellow light emitted by the phosphor to obtain white light. 51)] For InGaN/YAG white LEDs, by changing the chemical composition of the YAG phosphor and adjusting the thickness of the phosphor layer, various colors of white light with a color temperature of 3500-10000K can be obtained. This method of obtaining white light through blue light LEDs is simple in structure, low in cost, and highly mature in technology, so it is the most widely used.
Ming Deyang's teaching board has a total of 8 LED lights that can emit green light. The following is the schematic diagram of the LED light.
The LED1~LED8 on the left are the silk screen of the LED lights on the board. The LED1~LED8_NET on the right are the names of the signal lines, and readers cannot see these signal lines on the board.
One end of the LED light is connected to the high level 3.3V, and the other end is the signal line LED1~LED8_NET. If LED1~LED8_NET is at a high level, the current will not flow, and the LED light will not emit light. If LED1~LED8_NET is at a low level, the current will flow, and the LED light will emit light. So whether the LED light emits or not depends on what level the signal LED1~LED8_NET is at. Where are the signal lines LED1~LED8_NET connected to? Search the schematic document and you will find that these signals are connected to the pins of the FPGA. 153)]
Below is the connection diagram of signal lines and FPGA pins. For example, the signal line LED1 is connected to the AA4 pin of the FPGA.
LED1~LED8_NET are connected to the 8 pins of FPGA respectively, so the level of LED1~LED8_NET, that is, whether the LED lamp will emit light, depends on the output of the FPGA pin.
For example, FPGA pin AB14 is connected to LED7. To control the on and off of this light, FPGA only needs to output pin AB14 to low or high. When the output is high, LED7 is off, and when the output is low, LED7 is dimmed. All 8 LEDs can be controlled independently by FPGA.
2 Design Goal
This project uses 1 LED lamp---LED1 to realize the function of a flashing light. The working clock of the project is 50M, that is, the clock cycle is 20ns. When pin AA4 outputs a low level, LED1 lights up, and when it outputs a high level, LED1 lights up. The specific functional requirements are: every 1 second, light up for N seconds. The changes of N are: 1, 2, 3,---, 9 seconds, and then cycle again. The following is the waveform:
The upper board effect diagram is shown as follows:
3 Design and Implementation3.1 Top-level signal
Create a new directory: D:\mdy_book\my_led. In this directory, create a file named my_led.v, open it with GVIM, and start writing code.
Let's first analyze the LED light on the board. To control an LED light on and off, the FPGA needs to generate a signal, assuming it is led, and this signal is connected to the led light. To turn the LED off, the FPGA outputs the signal led as 1; to turn the LED on, the FPGA outputs the signal led as 0. The following table shows the connection relationship of the hardware circuit diagram.
In summary, our project requires three signals, clock clk, reset rst_n and output signal led. Define the name of the module as my_led. To do this, the code is as follows:
To sum up, our project requires three signals, clock clk, reset rst_n and output signal led. Define the name of the module as my_led. To do this, the code is as follows:
Among them, clk and rst_n are input signals, led is the output signal, and all three signals are 1 bit. Based on this information, we add the input and output port definitions. The code is as follows:
[ /align] 3.2 Signal Design
Let's analyze the functional requirements again. The LED light changes in a pattern of 1 second dark, N seconds bright, where N changes as follows: 1, 2, 3, ---, 9 seconds, and then repeats the cycle. From the phenomenon to the signal, it is actually the signal led = 1 for 1 second, then led = 0 for N seconds, where N changes as follows: 1, 2, 3, ---, 9 seconds. The waveform diagram is as follows:
The above picture is the changing waveform of the LED signal. In the first time, led=1 and lasts for 1 second, then led=0 and lasts for 1 second, for a total of 2 seconds; in the second time, led=1 and lasts for 1 second, then led=0 and lasts for 2 seconds, for a total of 3 seconds; and so on, in the ninth time, led=1 and lasts for 1 second, then led=0 and lasts for 9 seconds, for a total of 10 seconds. Then it repeats again.
As can be seen from the waveform, we need a counter to calculate time, such as 2 seconds, 3 seconds, etc. The working clock of this project is 50MHz, that is, the period is 20ns. When the counter counts to 2_000_000_000/20=100_000_000, we can know that the 2 seconds are up. Similarly, when the second time, it counts to 150_000_000, it means that the 3 seconds are up. When the ninth time, it counts to 500_000_000, it means that the 10 seconds are up. In addition, since the counter counts continuously and never stops, it can be considered that the plus 1 condition is always valid, which can be written as: assignadd_cnt==1. In summary, combined with the variable method, the code of the counter is as follows.
[ /color]
Where x represents the number of counter cnt0 to count. How to define this value will be considered later.
Observing the waveform again, we find that there are words for the 1st, 2nd, and 9th times, which means that another counter is needed to indicate the number of times. This counter indicates the number of times, so it is naturally increased by 1 after one is completed, because the condition for increasing by 1 can be end_cnt0. The counter needs to count 9 times in total. So the code is:
[/color ]
[color=rgb(51,With two counters, let's think about the changes of the output signal LED. In summary, LED has two change points: change to 0 and change to 1. The reason for changing to 0 is that the count reaches 1 second, that is, when cnt0 counts to 1_000_000_000/20=50_000_000, LED changes to 0. The reason for changing to 1 is that the counting time is up, that is, end_cnt0. So the code of the LED signal is as follows:
[color=rgb(153, 153, Finally, let's think about the variable x. When we were discussing the counter cnt0, we said, "When the counter counts to 2_000_000_000/20=100_000_000, we know that the 2 seconds are up." By analogy, when you count to 150_000_000 the second time, you know that the 3 seconds are up. When you count to 500_000_000 the ninth time, it means that the 10 seconds are up. "You can see that the number of cnt0 counts is related to the number of times. The first time, count 100_000_000, the second time 150_000_000. That is, it is related to cnt1. Therefore, the code for x is as follows:
This time, the main program has been completed. The next step is to complete the module. 3.3 Signal definition Next, define the signal type.
cnt0 is a signal generated by always, so the type is reg. The maximum value of cnt0 count is 500_000_000, which needs to be represented by 29 lines, that is, the bit width is 29 bits.
So the code is as follows:
add_cnt0 and end_cnt0 are both designed in assign mode, so the type is wire. And its value is 0 or 1, which can be represented by 1 wire. So the code is as follows:
cnt1 is a signal generated by always, so the type is reg. The maximum value of cnt1 count is 8, which needs to be represented by 4 lines, that is, the bit width is 4 bits. Therefore, the code is as follows:
add_cnt1 and end_cnt1 are both designed using assign, so the type is wire. And its value is 0 or 1, represented by 1 wire. Therefore, the code is as follows:
:
The LED is designed in the always mode, so the type is reg. And its value is 0 or 1, which can be represented by 1 line. So the code is as follows:
x is designed in the always way, so the type is reg. And its maximum value is 500_000_000, which requires 29 lines to represent. : Therefore, the code is as follows:
At this point, the design of the entire code has been completed. The next step is to create a new project and put it on the board to check the phenomenon. 4.1 Create a new project First, create a project folder named "my_led" in the D drive, name the written code "my_led.v", and name the top-level module "my_led" 153)][ /color]
3. Click Next in the interface that appears again.
4. Then the project folder, project name, and top-level module name setting interface will appear. Fill in the previous naming, then click Next, and then click Next on the interface that appears.
[ /color]
5. Then comes the file adding interface. Add the "my_led.v" file written before, click the "Add" button on the right, then the file will be displayed below, then click "Next"
Device model selection interface. Select Cyclone ⅣE, select EP4CE15F23C8 in the chip model selection, and then click "Next".
EDA tool interface. Directly click "Next"
8. On the interface that appears, click "Finish".
4.2 Comprehensive
1. After the new project step is completed, the following interface will appear. Select the file to be compiled and click the Compile button.
2.After the compilation is successful, the following interface will appear
4.3 Configuration Pins
In the menu bar, select Assignments, then select Pin Planner, and the pin configuration window will pop up. 10.33333]
In the location column at the bottom of the configuration window, configure the FPGA pins according to the two rightmost columns in the table below. 10. 16-bit PIN OUTPUT :
PIN OUTPUT :
PIN OUTPUT :
4.4 Comprehensive again
In the menu bar, select Processing, then select Start Compilation, and compile and synthesize the entire project again.
The above interface appears, indicating that the compilation and synthesis are successful.
4.5 Connect the development board
In the picture, the downloader is connected to the computer's USB port, the power supply is connected to the power supply, and then the blue switch below is pressed. 1. Click on the following interface. 1. Click "Add File" to add the .sof file. Click "Start" to display the progress. :
3.After the progress bar prompts success, you can observe the corresponding phenomenon on the development board.
This content is originally created by EEWORLD forum user guyu_1. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source51)] In the picture, connect the downloader to the computer USB port, connect the power supply to the power supply, and then press the blue switch below.
4.6 Boarding
1. Click in the following interface.
2. The following interface will appear. Click add file to add the .sof file. Click "Start" and the progress will be displayed in "Progress".
3. After the progress bar indicates success, you can observe the corresponding phenomenon on the development board.
This content is originally created by EEWORLD forum user guyu_1. If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source. 51)] In the picture, connect the downloader to the computer USB port, connect the power supply to the power supply, and then press the blue switch below.
4.6 Boarding
1. Click in the following interface.
2. The following interface will appear. Click add file to add the .sof file. Click "Start" and the progress will be displayed in "Progress".
3. After the progress bar indicates success, you can observe the corresponding phenomenon on the development board.
This content is originally created by EEWORLD forum user guyu_1. If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source.

This post is from FPGA/CPLD
Personal signature我与fpga的那些事儿http://blog.sina.com.cn/u/5707446562
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

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