FPGA advanced application based on Xilinx artix 7 (1): VGA image display (combat)

The FPGA chip used in this project is artix7 xc7a35t from Xilinx, and the development software is Vivado 2018.3

FPGA advanced application (1) VGA image display

The VGA image display program has the characteristics of " single output/input, multiple entries " in the C language design . Not much to say, let's first look at the input and output variables of the module

Insert picture description here
It can be seen that in addition to the three primary colors and scanning signals, we also introduced a clock, reset and a key backup.

In the principle article, we mentioned that VGA has a fixed standard according to the different scanning frequency, as shown in the figure below:

Insert picture description here
Since the onboard clock frequency is 50Mhz, we choose a relatively similar 65.0Mhz clock, 1024*768@60 standard. It can be seen that the row timing period and column timing period have been determined at this time, so we use parameter to determine:

Insert picture description here
After setting the cycle, we noticed that the clock corresponding to this standard is 65.0Mhz, and our onboard clock is 50Mhz. At this time, we need to multiply the frequency. The more convenient way is to use the IP core that comes with vivado: at
Insert picture description here
first we As mentioned, this program has the characteristics of ***"single output/input, multiple entries"***, that is, the data must comply with the following submission methods:

Insert picture description here
Therefore, we cannot directly use the input and output for scanning, color adjustment, etc., so we have to set a series of intermediate values, that is, the variables in the "to be submitted" area and the ones that are actually used for color correction and traversal. The black input line in the figure Representative variables:

Insert picture description here
Looking up the table, we know that the actual row and column pixels are 1344 and 806 respectively, so the row pixel variable needs an 11-bit register, and the column pixel variable needs a 10-bit register. What we ultimately want to achieve is the entire screen of different colors, gradient color screens, black and white squares and color stripes. Here are the register variables that store their colors. Because it is multi-functional, we have to set the VGA mode variable. Then we set the scan signal.
Note that here we use keys to switch modes, so there is a key_counter variable, let's first look at how to use keys to switch modes:

Insert picture description here
The VGA mode register has four bits. This rstn is the reset function in the clock IP core. Once reset, we first change the VGA to the default 0000 mode and clear the key variable key_counter. ***The non-blocking method is used here. pay attention! ***When the button is pressed and the time is less than 1ms, the key_counter counts with the clock until the VGA mode register is incremented by 1 when the count is 1ms, the mode switch is completed, and the counter is automatically cleared when the button is released. When the button is pressed again, it switches to the next mode.

After talking about the key switch function, let's care about the realization of the most important scan signal. First, take a look at how to traverse every pixel on the screen:

Insert picture description here
Insert picture description here
The horizontal and vertical scanning counts are exactly the same, that is, the counter is set to 1 when reset, and then starts to count until the row/column maximum value is automatically cleared. The only thing to note is that the column scan count starts and the next column counts the condition of the row The count has reached the maximum value.

This is the traversal count. With the count, we can give the scan signal:

Insert picture description here
Insert picture description here
When the sync signal at the beginning of the row/column comes, we set the scan signal to 0, and after the sync pulse ends, we set the scan signal to 1

Then there is the color matching for each mode: the
Insert picture description here
above is the color bar display, which is not difficult to read. More difficult is the following black and white squares:

Insert picture description here
This short code directly draws the grid graph. In fact, we can understand this: **x_cnt is an 11-bit variable first, we delineate x_cnt[4]=1b'1 actually delineate some discrete line segments in the x direction: the judgment condition is the first variable of the variable. Whether the five digits are binary 1, then there will be a series of variables that meet this condition at intervals in the x direction, and the length is 2 to the fourth power of 16 pixels (this variable is the fifth digit). **The same is true in the y direction, and then we fill it with black and white.

After the code of the image mode is completed, we enter the mode selection part, here is an if-case statement to complete:

Insert picture description here
Insert picture description here
Insert picture description here

Then we handed the defined scan signal to the input and output of the real module

Insert picture description here
The code is now complete. Let me show you the realization of color stripes:

Insert picture description here
Through this code as a whole, we can see his principle of **"single input/output, multiple entries"**, such as scanning a signal, instead of directly assigning the output port of the module, it establishes an intermediate quantity, and then adds more The input is assigned to the intermediate value, and finally submitted to the output port. The code written in this way is very efficient and readable, which is a good habit.

This issue is over here. If you have a small partner who wants the complete code, you can contact me on qq: 459007310.
Thank you for watching!

Guess you like

Origin blog.csdn.net/weixin_43824941/article/details/108113535