Lab 10 - VGA Download

Lab 10 - VGA Download

For this laboratory you will integrate the forwarding processor from the previous lab into the I/O sub-system and download your processor to the BASYS3 board. You will also learn how to use the VGA interface and change the program within your processor.

Avg Hours: 4.2 (Winter 2021)

Learning Outcomes

  • Learn how to program the VGA interface
  • Learn how to create new programs for your processor system


Memory Mapped VGA

A VGA display controller is included in the I/O devices and can be programmed by the processor. This controller organizes the 640x480 display into a text character display that can display 80x30 characters (with each character having size 8x16). This controller allows you to place ASCII text characters on the screen at any of these 80x30 locations. Each character on the VGA screen is mapped to a different address location and control of the VGA display involves writing data to specific locations within this memory. The base location of the VGA display is 0x0000_8000 and the display consumes 16384 bytes (0x0000_8000 through 0x0000_bfff).

An ASCII character can be written to a specific location on the screen by writing the 8-bit ASCII value to the appropriate address. The address of each of the 80x30 character locations is determined by the following table:

Base Address Row Address Column Address
addr[31:14] addr[13:9] addr[8:2]

For example, the address of the location 24,13 (0x18,0xd) is 0x0000_8000 + 0xd << 9 + 0x18 << 2 = 0x0000_8000 + 0x1a00 + 0x60 = 0x0000_9A60. Writing the value 0x21 to this value will place the character “!” at the location (column,row) = 24,13 as shown in the following code:

    li t0, 0x00009A60
    addi t1, x0, 0x21
    sw t1, 0(t0)

Note that we currently do not have the ability to load the 16-bit immediate value 0x9a60 into a register (we will need to add the LUI instruction in the next lab to make this possible).

Determine the address and ascii character value needed to place the character ‘$’ at column 38 and row 13 of the VGA display. There are many online ASCII Tables you can use to find the proper ASCII code.

Determine the row, column, and character that is being written to the VGA by the following code sequence

    li t0, 0x0000a2fc
    addi t1, x0, 59
    sw t1, 0(t0)

The color of the characters on the VGA can also be controlled by the assembly instructions. All colors are specified by a “RGB” 12-bit value. The top four bits [11:8] specify the “Red” component of the color, bits [7:4] specify the “Green” component of the color, and the lower four bits [3:0] specify the “Blue” component of the color. The four bits associated with each primary color indicates the intensity of the given primary color. A value of “0000” for any of the primary colors will provide none of the given color while a value of “1111” for a primary color indicates provide this primary color at its maximum intensity. The table below demonstrates eight different colors that can be generated with this 12-bit color signal:

Red [11:8] Green [7:4] Blue [3:0]  
0000 0000 0000 Black
0000 0000 1111 Blue
0000 1111 0000 Green
0000 1111 1111 Cyan
1111 0000 0000 Red
1111 0000 1111 Magenta
1111 1111 0000 Yellow
1111 1111 1111 “White”

With 12 bits, you can create up to 4096 different colors.
Each printed character appears on the display as two colors: the foreground (the color of the pixels that make up the character shape) and the background (the color where the character pixels do not exist). By default, all characters share the same foreground an background colors (this can be changed if necessary). The color of the foreground and background can be set by the VGA color register located at address 0x000_7f34. Bits [11:0] in this register determine the RGB color of the foreground and bits [23:12] determine the RGB color of the background as shown in the following table:

Reserved Background Color Foreground Color
[31:24] [23:12] [11:0]

Determine the value to write to this register to set the foreground color as yellow and the background color as blue.


Exercise #1 - I/O Sub System for Forwarding Processor

In this first exercise you will simulate your processor from the previous lab executing within the I/O system executing a program that writes to the VGA. You will have a new top-level I/O design that you will insert your processor into.
Begin this exercise by creating a new project for this lab by ‘sourcing’ the .tcl script create_forwarding_project.tcl within the ‘lab10’ directory of your repository. This script will integrate your forwarding processor from the previous lab with the I/O system you built in lab 7.

A simple test I/O program, forwarding_iosystem.s, has been written that operates on the I/O system described above. Create the instruction memory file, data memory file, and debug file from this program by using the RARs simulator:

java -jar ../resources/rars1_4.jar mc CompactTextAtZero a \
  dump .text HexText forwarding_iosystem_text.mem \
  dump .data HexText forwarding_iosystem_data.mem \
  dump .text SegmentWindow forwarding_iosystem_s.txt \

This program has been compiled and is embedded in the instruction memory of the top-level system you were provided above. This program uses the buttons, switches, LEDs, and seven-segment display. Carefully review this program and answer the questions on Learning Suite about its functionality.

Answer the questions about the test program in Learning Suite.

Add your ‘text’ and ‘data’ memory files associated with this project to your Vivado project.

add_files ./forwarding_iosystem_text.mem
add_files ./forwarding_iosystem_data.mem
set_property generic "TEXT_MEMORY_FILENAME=forwarding_iosystem_text.mem DATA_MEMORY_FILENAME=forwarding_iosystem_data.mem" [get_filesets sim_1]

You can simulate your processor operating with the top-level I/O system. You can emulate the pressing of buttons and changing th switches by creating a .tcl script that changes these top-level inputs. A template tcl file, vga_sim.tcl, has been created to help you get started with a TCL simulation. When simulating this system with the precompiled program, you will receive messagese indicating reads and writes to the I/O ports. This script will run the processor for a long time to execute the clearing of the screen. You should see many messages indicating data being written to the VGA display:

3015000:Reading 0x00000000 from Switches
4835000:Writing 0x00fff000 to Character Default Color
4955000:Writing 0x00000020 to VGA at address 0x00008000
5115000:Writing 0x00000020 to VGA at address 0x00008004
5275000:Writing 0x00000020 to VGA at address 0x00008008
5435000:Writing 0x00000020 to VGA at address 0x0000800c
5595000:Writing 0x00000020 to VGA at address 0x00008010
5755000:Writing 0x00000020 to VGA at address 0x00008014
5915000:Writing 0x00000020 to VGA at address 0x00008018
6075000:Writing 0x00000020 to VGA at address 0x0000801c

Copy this file into a new file named vga_sim_new.tcl and extend this tcl script to simulate the program writing to the VGA display with a character of your choosing. Your script should simply set the switches to an ASCII character of your choosing, press button-R or button-D, and then execute until the character is written on the screen. Note: There is debouncing logic on the buttons that will require about 6 us before the button press is available I/O system. You will need to simulate long enough for your button press to pass through this debouncing delay circuitry.

You will need to include this .tcl file file as part of your lab submission

Exercise #2 - Download

After verifying your processor works correctly with the I/O system, create a bitstream of your system and download it to your board. You will need to set the

set_property -name {STEPS.SYNTH_DESIGN.ARGS.MORE OPTIONS} -value {-generic TEXT_MEMORY_FILENAME=forwarding_iosystem_text.mem  -generic DATA_MEMORY_FILENAME=forwarding_iosystem_data.mem} -objects [get_runs synth_1]

Summarize the utilized resources for your implemented design as well as the WNS.

Resource Estimation

Verify that the board and the VGA assembly language program operate as you expected. To demonstrate that your system is working properly, press the switchces and buttons on the board such that your netID is shown in the VGA display and take a picture of the display. Name your file “vga.jpg” and try to make the size of your file reasonable.

You will need to include this image as part of your lab submission

Exercise #3 - Changing the Processor Program (Defuse)

For this exercise, you will be changing the program that is compiled into your FPGA bitstream. The steps involved in changing the program embedded in the bitstream are outlined in the following tutorial. You will be using this approach to in the future to upload your own programs to the bitstream in the future.

The program you need to insert into your bitstream is defuse.s. This program simulates the defusing of a virtual “bomb”. When first started, the VGA display is yellow indicating that the bomb is active. You need to figure out what buttons and switches to set to defuse the bomb and turn the screen green. If you make a mistake, the VGA display will turn red (i.e., explodes). When you have defused the bomb, a code will be displayed on the display. You can figure out what buttons and switches you must set by carefully reviewing the assembly code.

In this lab and future labs, you will be modifying the program frequently and it can be a hassle to download the bitstream using the Vivado Hardware Manager. Another way for downloading the bitstream is to use the openocd command that has been installed on the digital lab computers (details about this command and how to use it can be found at the following link).

A python script has been created to simplify the process of downloading new bitstreams to the board. The following python script will download the bitstream named defuse.bit to the FPGA board:

python3 ../resources/ defuse.bit

Enter the code displayed on the defused “green” screen when you have figured out how to defuse the circuit.

Exercise #4 - Custom Program

For the final exercise, you are to create your own custom assembly language program, integrate this program into your bitstream, and download it on your FPGA board. Copy the forwarding_iosystem.s assembly language program in the starter code and name the file move_char.s. Modify the assembly language program so that your assembly program behaves as follows:

  • Always display the ASCII character code 0x01 (a smiley face) rather than using the switches to decide which ASCII character to display when a button is pressed.
  • When the character moves to a new location based on a button press, clear the previous location with a space (0x20) so that it appears that the character is moving from one space to another rather than leaving a trail of characters behind.

Pass Off

To create your submission, make sure the following files are committed in your ‘lab10’ directory:

  • vga.jpg
  • vga_sim_new.tcl
  • move_char.s

Make sure you do not add unnecessary files (including Vivado project files) to your repository. Tag your repository with the string lab10_submission and push your repository back to the origin. Test your submission by running the pass-off script found in the starter code. Review the instructions for submitting and passing off labs to make sure you have completed the lab properly.

How many hours did you work on the lab?

Provide any suggestions for improving this lab in the future.

Last Modified: 2022-05-31 12:23:24 -0500