Routine explanation of lighting LED lights
Based on many years of work experience, the FPGA design process has been summarized in a total of the above 12 steps, some of which can be omitted depending on the difficulty of the project. For example, for very simple projects, we can omit the steps in the dotted box, but our introductory course, no matter how simple it is, will be explained according to these 12 steps.
1. Interpretation of requirements
1.1 Requirements
Realize lighting up an LED light (D2).
1.2 Knowledge background
Introduction to LED lights
LED, also known as light-emitting diodes. The operating current of LED lights is very small (some can emit light with only a few tenths of a milliamp). They have good impact and seismic resistance, high reliability and long life. Due to these advantages, LED lights are widely used in instruments and meters as indicator lights, LCD screen backlights and many other fields. Light-emitting diodes of different materials can emit eight colors of light: red, orange, yellow, green, cyan, blue, purple and white. As shown below:
1.3 Hardware design
1.4 Interface description
Signal name | direction | FPGA pin number | illustrate |
---|---|---|---|
LED0 | output | L12 | Connected to LED light, low level LED light turns on |
Summary: Through the above explanation, the requirement can be interpreted as that as long as the L12 pin of the FPGA is set to low level, the LED light D2 can be lit.
2. Draw theoretical waveform diagram
3. New TD project
In order to make the project look tidy and facilitate project transplantation. We create 4 new folders, namely Project, Source, Sim, and Doc.
Project — the project folder, which contains the TD project
Source — the source code folder, which contains the project source code (.v file or .vhd file)
Sim — the simulation folder, which contains the simulation-related files
Doc — stores relevant information , such as data manuals, requirements documents, etc.
4. Write code
///
//QQ:3181961725
//TEL:13540738439
//作者:Mr Wang
//模块介绍:点亮LED灯
///
module led_on(
output led
);
assign led=1'b0;
endmodule
5. Write simulation test stimulus file
`timescale 1ns/1ps
module led_on_tb;
wire led;
//例化被仿真模块
led_on Uled_on(
.led (led)
);
endmodule
6.Modelsim simulation
This routine is very simple and uses only one statement, so no simulation verification is required. But in order to demonstrate a complete development process to everyone, we also created a new simulation project for this experiment, starting from the simplest code to teach you how to write simulation stimulus files and how to use Modelsim software for simulation. Add the source code written in the third step and the simulation test stimulus file written in the fourth step to the Modelsim simulation project to simulate and observe the waveform.
There are generally two methods for Modelsim simulation:
-
Graphical interface simulation means that all operations are completed on the Modelsim software interface. The advantage of this method is that it is easy to learn and suitable for simple projects. The disadvantage is that the operation steps are cumbersome.
-
Batch simulation , this method requires writing corresponding script files before simulation. The advantage of this method is that the simulation can be completed with one click, saving time and effort. The disadvantage is that script files need to be written in the early stage. In order to quickly apply what everyone has learned to engineering practice, only the first experiment and the second experiment were simulated using a graphical interface, and all subsequent experiments were simulated using batch processing.
Graphical interface simulation steps:
1. Create a new project, file–>new–>Project
2. Fill in the project name and specify the simulation project storage path
3. Add files, source files and simulation stimulus files
4. Compile
5. Start simulation
6. Add observation signal
7. Interrupt simulation
8. Enter the run command, run + simulation time
At this point, we can observe the level status of the simulated signal in the waveform window.
When we change the source code, we need to start from step 4 again.
The simulated waveform is shown in the figure below:
7. Compare waveforms
Compare the theoretical waveform diagram drawn in the second step with the waveform diagram simulated by Modelsim in the sixth step. The results are consistent, indicating that our logic design is correct. If the comparison results are found to be inconsistent, you need to find the reason for the inconsistency, and ultimately ensure that the comparison results are consistent.
By comparison, the theoretical waveform is consistent with the simulated waveform, indicating that the function meets the design requirements.
8 Add .v file
9 Bind the pins and save the constraint file (.adc)
10 Compile and synthesize the BIT file
11. Download BIT file
After the download is successful, you can observe the experimental phenomena on the development board. If the experimental phenomena match the design requirements, it means that there is no problem with our design, and we can proceed to the next step of solidifying the configuration file.
12 solidification configuration file
FPGA has a characteristic that the configuration information will be lost after power failure, so we need to store the configuration information in the configuration chip (FLASH). After the development board is powered on, the FPGA will read the configuration information in the configuration chip, so the development The board can still work normally after powering off and on again.
After the curing is successful, power off the development board and then power it on again. It can be observed that the development board can still perform the functions just now.
Experimental phenomena
The LED light connected to FPGA pin L12 is lit, meeting the design requirements, and the design is completed!