### High Level Design

Before discussing the design we would like to discuss steps that we took before getting to the high level design.

Backgound

Before starting the project we did the feasibility study about the project. Our project has two fundamental parts which includes USB Mouse interface and VGA Controller.  We were quite sure about our understanding of VGA controller because we had worked with it in our previous labs. We were quite confident that we understand the proper functionality of the VGA controller and we could adapt it according to our needs.

The basic problem was the USB Mouse Interface. The USB standard is itself very complicated and designing it can itself be a big project. We had limited amount of time so implementing the USB Mouse Interface was quite infeasible. Therefore we looked at different websites and we found one in Altera Paint Brush Example.

Altera Paint Brush Example is basically a project using Altera DE2 board. This project basically involves a USB Mouse interface. The USB mouse is used to draw different pixels at different points. It also displays a cursor in the form of a PLUS ( + ) sign.

The yellow PLUS sign is drawn with the help of HSync and VSync of the VGA Controller that uses registers to display on the VGA Monitor. The background image is initialized into the M4K Block. The VGA controller reads from the M4K block to display the background image. The VGA controller multiplexes between the M4K block and the registers to display the PLUS sign and the back ground Image simultaneously.

After completely understanding the working of the Altera Paint Brush Example we concluded that it was feasible to carry on with this project.

We aimed our VGA controller to have resolution of 640x480 pixels in order to get the best results. We figured out that in order to display an image of 640x480 resolution we could not use the M4K blocks because of the following math:

Calculations of the 640 x 480 Image Display

640 x 480                         =   307200 pixels

1 pixel                              = 16 bits

640 x 480                         = 2457600 bits

Total M4K Blocks               = 2457600 / 4000 M4K

Total M4K Block                 = 614 Approx.

Total M4K in DE2               = 105 M4K Blocks

Therefore the only solution is to go for SRAM.

From the above calculation we have

640 x 480                         = 307200 pixels

1 pixel                              = 16 bits

SRAM (1 word )                 = 16 bits

SRAM ( Number of words ) = 256 K

We need                           = 307200  words

But we have only 256K words in the SRAM to display this image. The only solution for this problem is to pack two pixels in one word that is to use 8 bits to display 1 pixel. We have 255 colors for 1 pixel because of 8 bits.

After doing all maths for the memory sizes we focused on the changes we had to make in the Altera Paint Brush example and the VGA controller provided by the Altera. We changed the architecture of SRAM so that it stores two pixels per word. We also had to change the reading of VGA controller so that it takes into account the two pixel format.

The Altera Paint Brush Example displays the PLUS sign for the cursor. We changed the PLUS sign to the simple mouse cursor to make it look like a real mouse.

The Altera Paint Brush Example uses M4K blocks to display the background image. According to our calculations M4K blocks are not enough therefore we added SRAM to the VGA controller in order to display the background image. We multiplexed the SRAM with registers to display different images along with the background images.

We used ROM and RAM from Altera Mega Function Wizard to display the images on the VGA controller. The ROM is basically used for storing the different type of small images (the cute meat balls). RAM is used to store the location of these images on the screen.

VGA Controller

Before describing the working of the VGA controller we should know how the VGA works. There are basically two Pulses which are responsible for the display on the VGA Monitor. One is called the Horizontal Sync (Hsync) and other is called the Vertical Sync(Vsync) .

Horizontal Sync is responsible for the horizontal lines on the screen and vertical sync is responsible for the display for frames. Below is the description of the Pulses:

Horizontal Timing

`               ______________________          ________`
`________|        VIDEO         |________| VIDEO (next line)`
`    |-C-|----------D-----------|-E-|`
`__   ______________________________   ___________`
`  |_|                              |_|`
`  |B|`
`  |---------------A----------------|`

`Vertical Timing`
`         ______________________          ________`
`________|        VIDEO         |________|  VIDEO (next frame)`
`    |-Q-|----------R-----------|-S-|`
`__   ______________________________   ___________`
`  |_|                              |_|`
`  |P|`
`  |---------------O----------------|`
` `
` `
`The letters indicated in the above diagrams are the time for the particular event which is different for the different resolution. During the time B and P the VGA is in sync state and during the interval D and R VGA is in active state that is updating the screen. The interval Q and C are called back porch and interval E and C are called front porch.`
` `
`The details information of the VGA timings is described on this webpage: `
`http://www.epanorama.net/documents/pc/vga_timing.html`

Top level

Architectural Block Diagram of FPGA BBQ Stick

Software/Hardware Trade-off

In our design the USB Mouse interface is controlled by the software. The rest of the game is developed in the hardware. We choose hardware because our game involves a lot of dynamics such as moving stick and movement of images. Using hardware allows the images to be displayed accurately in real time with no flicker. Developing the game in the software is comparatively easier but the game may not run as smoothly as it is now. But we take a lot of advantage through software. We use software to transfer an image into the SRAM, otherwise with the hardware only it would become really difficult for us to write such a colorful image into the SRAM. In short the hardware software combination proves to be a great help to us in our project.