64-Color VGA Display Test

Image Indexing Group

 

Introduction

A standard VGA monitor contains of a grid of pixels typically 480 rows and 640 columns. Each pixel can display various colors, depending on the state of the red, green and blue signals (R, G and B) . A VGA monitor also has an internal clock that determines when each pixel is refreshed, typically 25.175 MHz. The refresh behavior of the monitor is partially controlled by the horizontal and vertical synchronization signals. After the first pixel is refreshed, the monitor refreshes the remaining pixels in the row in the raster scan mode. When the monitor receives a horizontal synchronization signal, it retraces and then starts to refresh the second row also in raster scan mode. By repeating this process until the scan reaches the bottom of the monitor, the monitor will receive a vertical synchronization signal and retrace back to the first pixel (top left corner). Although stated above that normally the monitor only scans 640 pixels each row, actually it uses 800 clock periods of which 640 are used to scan the pixels which can be seen on the screen. The remaining 160 clock periods are used to retrace back (moving the CRT from the end of the row to the beginning) and also the synchronization. A similar process applies to the vertical synchronization, which uses 525 instead of 480 horizontal synchronization pulses. So the screen refresh frequency is typically 60 Hz.

Problem

Fortunately the clock frequency of the UP1 board used is the same as the VGA operating frequency. So if in 800*525 clock periods, we send 640*480 signals, including RGB, i.e., a 640*480 8-color picture data, we can get a steady display of that picture. However, the picture which can be displayed is limited to 8-color only, because 3 bits – R, G, B are used to represent the color and each bit can only have two states – 0 and 1. Therefore there is a big problem: 8-color (3 bits) is too less to display a natural picture which is generally 16-bit or higher (24-bit for true color) per pixel.

Attempt to reach 64 colors

The solution of the problem is similar to develop a VGA display driver which can display 64 colors on the screen. In theory, if we can expand the 1-bit RGB to 2-bit RGB state, we can have a display of 26=64 available colors. The following scheme is the trick used to have a virtual 2 bit RGB state:

  1. The picture data we use for the indexing is true color. It is easy to extract the RGB data and round them up to have 2 bits with 4 states: 11, 10, 01, 00.
  2. We need to find the way to convert the 4 states of each RGB into 2 states: 0 or 1 because the screen can indeed show 8 colors pattern for every refresh screen (i.e., 1/60 second). But our eyes can be cheated by displaying same data in slightly different color patterns and acknowledge that the displayed pattern has 64 colors.
  3. One example is that we can use a 2-bit counter in 3 states (00, 01 and 10), and by doing simple logic calculation, the 2-bit RGB data can be converted into 1-bit states. The counter is increased by 1 at every rising edge of the vertical sychronization pulse. Then for a 3 continuous refresh screen clock (3*(1/60) seconds), the monitor receives the signal of the following RGB states:

 

value

R or G or B

00

01

10

11

Counter

00

0

0

0

1

01

0

0

1

1

10

0

1

1

1

 

  1. The above way actually behaves like that we divide the refresh screen frequency by 3 into 20 Hz. So another problem appears that the screen is flicking very heavily to our eyes since only the refresh screen frequency is higher than about 45 Hz we will not perceive the flicking.
  2. We have to accelerate the refresh screen frequency by increasing the horizontal and vertical synchronization frequency. That is, for example, we will send the horizontal synchronization signal to the monitor every 500 internal clock time instead of 800 and also the vertical synchronization signal every 300 internal clock time instead of 525.

Test results

The following table lists the comparison of screen display performance for different parameters used:

fh-synch

(unit:clock period)

f-synch

(unit:horizontal synchronization pulse)

Refresh

Rate

Screen Flicking

800

525

60

very heavily

700

451

80

heavily

600

373

112

slightly

560

357

126

acceptable

500

271

186

stable

 

Comments

(1)  Obviously the trick used in this method to display more than 8-color can only be used to display patterns smaller than about 400*200 pixels, if we want to have a stable display.

(2)  Because of the different properties of display monitor, some monitors can not accept refresh rate higher than a certain value. This experiment results were obtained on a Panasonic PanaSync E70i type monitor.

 

Code list

vga_test.vhd, syncgen.vhd, RGB_gen.vhd, clock_rgb.vhd