Bitmap Memory Module

The provided bitmap_mem module stores a 320x240 bitmap image, with 3-bit color (one bit for red, one bit for green, and one bit for blue). This uses 12 of the 50 block memories on the FPGA, which is a significant portion of the available memory. As such, it’s not possible to store the full 640x480 VGA resolution, or to use more than 1 bit per color channel, because that would require too much memory.

This module behaves similarly to the char_gen module, in that it receives an (x,y) coordinate from the VGA timing generator, and outputs the pixel data at that location. While the char_gen module output a single bit (on or off) for each pixel, the bitmap_mem module outputs 3 bits of color information.

Because the stored bitmap is a scaled down version of the full VGA resolution, each pixel in the bitmap corresponds to a 2x2 block of pixels on the VGA display.

Module Name = bitmap_mem      
Port Name Direction Width Description
clk Input 1 100 MHz Clock
rd_x_vga Input 10 x-Coordinate of pixel to read (0..639)
rd_y_vga Input 9 y-Coordinate of pixel to read (0..479)
rd_data_r Output 4 Red component of pixel. This is the 1-bit red value duplicated 4 times, for convenience in sending to the VGA output
rd_data_g Output 4 Green component of pixel. This is the 1-bit green value duplicated 4 times, for convenience in sending to the VGA output
rd_data_b Output 4 Blue component of pixel. This is the 1-bit blue value duplicated 4 times, for convenience in sending to the VGA output
wr_x_qvga Input 9 x-Coordinate of pixel of QVGA resolution bitmap to write (0..319)
wr_y_qvga Input 8 y-Coordinate of pixel of QVGA resolution bitmap to write (0..239)
wr_color Input 3 Color of pixel to write. [2]=red, [1]=green, [0]=blue
wr_en Input 1 Write enable – set to 1 to enable writing to the bitmap image

Drawing Pixels using the Write Port

The wr_x_qvga, wr_y_qvga, wr_color and wr_en inputs allow you to write pixel data to the bitmap image stored in the bitmap_mem module. This allows you to change individual pixels of the 320x240 bitmap image. Note that the x and y coordinates for the write port are in the QVGA resolution (320x240), not the full VGA resolution (640x480).

The following waveform example demonstrates writing the (35, 40) pixel to red, the (34, 41) pixel to green and the (100, 2) pixel to yellow.

Reading Pixels using the Read Port

The rd_x_vga, rd_y_vga allow you to provide the (x,y) coordinates of a pixel to read from the bitmap image. These values are VGA coordinates (0..639 for x, 0..479 for y). Similar to the char_gen module, you can connect the pixel_x and pixel_y outputs of the VGA timing generator to these inputs, so that the bitmap memory will output the color of the pixel at the current VGA coordinates.

The rd_data_r, rd_data_g and rd_data_b outputs will provide the color of the pixel at the specified coordinates. The bitmap is only 3 bits of color (1 bit for red, 1 bit for green, and 1 bit for blue), but these outputs duplicate the single bit of color information 4 times to make it easier to connect to the VGA output.

Latency / Timing

The bitmap_mem module has a latency of 1 clock cycle. This means that if you should delay the Hsync and Vsync signals by 1 clock cycle to align them with the color data outputs.

Combining with the Character Generator

You can combine the bitmap_mem module with the char_gen module to create a more complex VGA output. There are different ways to do this, but one way is to draw characters over top of the bitmap image. To do this, include both the char_gen and bitmap_mem modules in your design, and connect the VGA timing generator outputs to both modules. Then, if char_gen’s pixel_out is 1 (indicating that the character generator wants to draw a pixel), output the character color. Otherwise, output the bitmap color. You could do the reverse as well, by drawing the bitmap on top of the characters, but you would need to choose a specific color in the bitmap to be the “transparent” color that allows a multiplexer to select the character color instead of the bitmap color.