You are on page 1of 4

Chapter 6

VGA Object Display


The purpose of this laboratory is to create a circuit that generates several objects on the VGA display. You will also create a simple circuit to move the objects on the screen.

Learning Objectives
Understand the timing signals required to drive a VGA display Understand how to create colors on the VGA display Create a reusable digital circuit for controlling the timing of a VGA display

Exercises
Exercise 1 Object Display Logic
In the previous VGA timing lab, you created a top-level circuit that generated a simple pattern on the VGA screen. You accomplished this by decoding the current value of the VGA horizontal and vertical counters (pixel_x and pixel_y). For this lab, you will display multiple independent objects that share the VGA screen. To draw an object on the display, you will need to create logic that indicates when the object should be displayed. For example, the following VHDL denes a rectangle that is 100 pixels wide and 50 pixels high. This rectangle is displayed in the region: 150 <= pixel_x < 250 and 100 <= pixel_y < 150: rectangle_on <= '1' when pixel_x >= 150 and pixel_x < 250 and pixel_y >= 100 and pixel_y < 150 else '0'; In addition, logic is needed to specify the color of this rectangle. The following logic specied the color blue for the rectangle. rectangle_rgb <= "000" & "000" & "11"; -- blue The following logic dene a green square that is 50 pixels wide and 50 pixels high: square_on <= '1' when pixel_x >= 350 and pixel_x <400 and pixel_y >= 200 and pixel_y <250 else '0'; square_rgb <= "000" & "111" & "00"; -- green

31

32 Other custom drawing circuits could be created to draw a variety of objects. Since the VGA display is controlled by only one RGB output, additional logic must be created to determine which object to display. In some cases, objects may overlap each other and logic must be created to determine which object has priority for display. Multiplexing logic must be created to select the appropriate color value to display at the current location based on the various object display circuits. The following example displays the rectangle and square with the rectangle having higher priority. Note that this VGA display logic will generate a black background where the rectangle and square are not displayed. -- Default value when no object is being displayed background_rgb <= "00000000"; rgb_out <= rectangle_rgb when rectangle_on = '1' else square_rgb when square_on = '1' else background_rgb; For this exercise, create the VHDL logic for the following object: draw a red border around the VGA display that is 10 pixels wide (i.e., a 10 pixel wide border on the top and bottom and right and left sides). Save this logic as you will use this logic in your top-level design. Upload: Copy and paste your VHDL for the red border

Exercise 2 Object Animation Logic


It is also possible to animate the objects you display. Object animation can be done by using registers rather than constants to decide when an object should be drawn. For example, the code shown below will draw a 5x5 pixel red box at the location specied by the contents of the registers box_x_location and box_y_location: moving_box_on <= '1' when pixel_x pixel_x pixel_y pixel_y '0'; moving_box_rgb <= "111" & "000" & >= < >= < box_x_location box_x_location + 5 box_y_location box_y_location + 5 and and and else

"00";

These registers can be modied to support some form of animation. For example, the box_x_location register could be incremented by its next state logic to move the box one pixel to the right. This logic could be based on input from the buttons or some other user-specic action. Alternatively, this movement could be done in regular intervals to provide a steady movement of the object. Note that when movement is desired, appropriate delays must be added to prevent the movement from occurring too fast for the eye to see. For this exercise, create a yellow rectangle that is 7 pixels wide and 50 pixels high. This rectangle should be drawn in columns 20 through 26. The rectangle should be able to move up and down within these columns but should not move from right to left. This rectangle should move up when BTN3 is pressed and move down when BTN2 is pressed. Bounds should be placed on the up/down motion of this rectangle so that the top of rectangle never moves higher than the edge of the top red border and the bottom of the rectangle never moves below the edge of the bottom red border. This logic should include a register that species the y location of the yellow rectangle. You will use this logic for your top-level design. Upload: Copy and paste your VHDL for the yellow rectangle. Question: Determine how many valid Y positions there are for the rectangle.

Exercise 3 Top-Level Design Exercise


For this laboratory, create a single top-level design that includes your VGA timing controller and the seven-segment display controller. Add additional logic to create a VGA design that conforms to the following specications:

33 Add your decoding logic to draw a red border around the VGA display that is 10 pixels wide (i.e., a 10 pixel wide border on the top and bottom and right and left sides). This is the code you created for exercise #1 Draw a yellow rectangle that is 7 pixels wide and 50 pixels high. This rectangle should be drawn in columns 20 through 26. The rectangle should be able to move up and down within these columns but should not move from right to left. This rectangle should move up when BTN3 is pressed and move down when BTN2 is pressed (you will need to add some delay into the rectangle movement - moving the rectangle one pixel per clock cycle will be too fast for the eye to see). Bounds should be placed on the up/down motion of this rectangle so that the top of rectangle never moves higher than the edge of the top red border and the bottom of the rectangle never moves below the edge of the bottom red border Draw a green rectangle that conforms to the same specication as the yellow rectangle described above except that this rectangle is drawn in columns to 614 through 620 and the rectangle moves up when BTN1 is pressed and the rectangle moves down when BTN0 is pressed Draw a 5 pixel by 5 pixel white square that continually bounces on the screen. The square should travel diagonally in one of four directions: down/right (increment the x,y location), down/left (decrement x, increment y), up/right (increment x, decrement y), and up/left (decrement x, decrement y). The square should travel in one of the diagonal directions until it hits the red border. Once it hits the border, change the direction appropriately (i.e., if the box is travelling up/right and hits the right border, the box should change its direction of travel by moving up/left). The direction of travel can be maintained by a register (enough bits to indicate one of the four directions of travel). You will need to add some delay into this movement - moving the square one pixel per clock cycle will be too fast for the eye to see The background of the VGA should be black (i.e., black should be drawn when no other object is at the current x,y location) In addition to your display logic, create a 16-bit counter that counts the number of frames being displayed. A new frame occurs when both the last_column and the last_row signals of your VGA timing controller are asserted. Note that these signals will be asserted for two clock cycles since the VGA timing module is only updated every other clock cycle. You should only increment your frame counter once per frame. Attach the output of your 16-bit frame counter to the seven-segment display controller. When running, the seven-segment display should update at a frequency of 60 Hz (the VGA refresh rate). When you instance your timing controller, you will need to provide a signal for the reset of the timing controller. For this lab, create a signal with a constant 0 to drive your reset input (i.e., to prevent the circuit from being reset). Question: If you want the rectangle to move at a speed of 1000 pixels/second, how many clock cycles of delay are needed if the clock is running at 50 MHz? Question: How many clock cycles of delay did you use for your bouncing square? Question: What is the speed of your bouncing ball in terms of pixels/second? Question: This lab could be the start to a simple game of pong. What would need to be done in order to get the ball to bounce off the rectangle paddles at each end of the screen? Upload: Copy and paste your VHDL for your top object display design.

Synthesis Warnings
It is essential that you review the warnings associated with the synthesis of your circuit. It is very easy to code your VHDL in a way that leads to a synthesizable circuit but one that is not synthesized the way you intended. There are two types of synthesis warnings you should look for. First, you can generate circuit latches when the sensitivity list is not complete. Incomplete Sensitivity List

34

WARNING:Xst:819 - "/home/mwirthlin/ee320/lab6/pong.vhd" line 217: One or more signals are missing in the process sensitivity list. To enable synthesis of FPGA/CPLD hardware, XST will assume that all necessary signals are present in the sensitivity list. Please note that the result of the synthesis may differ from the initial design specification. The missing signals are: Second, you can generate latches in your logic when you do not cover all cases in if/case statements within a process. Latches WARNING:Xst:737 - Found 10-bit latch for signal <right_paddle_top_y_loc_next>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems If you nd any of these messages, you need to modify your code until these messages go away. Question: Review your synthesis logs and report on all warnings. Summarize these warnings and justify the warnings if you believe they are acceptable. Question: What is the minimum clock period of your circuit (review the Post-PAR Static Timing Report and search for Minimum period)? Question: Review the Map Report and determine the number of slices used by your design.

Personal Exploration
The lab has a lot of fun opportunities for personal exploration. For your personal exploration, modify the design to add some additional visual feature. Ideas include: Have the square bounce off the two rectangles Provide other objects on the screen and have the yellow square bounce off of these Create logic to display a pattern or picture in the background

Pass Off
Show your VGA object display to the TA Show the TA your personal exploration

You might also like