Sunday, July 15, 2012

quarter VGA (qVGA) 320 by 240 resolution

The default for vga is 640 by 480.  There are tons of documentation about how to get this timing correct and there are tons for larger resolutions.

However, there is hardly any mention of 320 by 240.

The reason I needed that resolution was because I needed to make a pixel matrix that would hold the color
value for each coordinate.  The pixel matrix exists in memory and unfortunately my spartan 6 doesn't have a lot of it.

The purpose of this blog entry is to document the qVGA timings that I have found through trial and error.


 hdisp_size = 320;  //This specifies the width of the screen
 hpw_size = 48; // pulse width
 hbp_size = 28; // back porch
 hfp_size = 4; //front porch

 hsync_period = 400//this specifies the number of clock ticks before going back to zero.  ie. 0 to 399


 vdisp_size = 240; // this specifies the height of the screen
 vpw_size = 1; //pulse width
 vbp_size = 15; // back porch
 vfp_size = 4; // front porch

 vsync_period =  260;// this specifies the number of clock ticks before going back to zero. ie 0 to 259

The h clock will tick every 80 ns
the v clock will tick every 63.84 us

The screen I was using was quite finicky when it came to the right pw, bp, or fp values, but after awile I started to notice a trend.

The screen should refresh 60 hz to 60.5 hz.
In reality I got 60.48 hz.

The numbers MUST conform to that timing constraint or else it will not work properly.
When the screen resolution was 640 wide, we would need to count up to 800.
At first I mirely set it to 320 wide and made it count to 800 (and increased the bp,pw,and fp to accomodate it).    This made big black margins
to appear on the left and right side of the screen

The same happened with the height.  Originaly i had it at 480 and had it count to 521.
Then I changed it to 240 and increased the bp,pw, and fp to keep the counter counting up to 521.
This made top and bottom margins.

Although it worked, i was more interested in taking over the entire screen.

The h_sync had to cycle every 32 us. which means that you have to count from 0 to 399 in 32 us.
originally would count to that number in 16us so I basically clock divided the h clk.

The v_sync had to cycle every 16640 us.  which means that you have to count from 0 to 259 in 16640 us.
I also clock divided the v_clk.


*****
important observation
******
for a long time I had been missing a margin.  I had thought my value for the fp,bp, or pw were offset.
but in reality, it was because I was sending color when I wasn't suppose to.  I tried sending the color outside of the 320*240 grid and as a result, the screen tried to adjust to fit it in.  The screen doesn't know where coordinate (0,0) is located so it will need to guess based on when it gets a color.  If this theory is true,
then it would be wise to always place a background.  A very light background.

4 comments:

  1. Hi Derrick. Interesting post; indeed there are no definite stuff on the QVGA timings. Most people use the pixel scaling to emulate QVGA at a VGA resolution.

    I have a question: can you recall the h_clk and v_clk you were using? Did you further divide e.g. a 25 MHz clock?

    Nikos Kavvadias

    ReplyDelete
    Replies
    1. Hi Nikos
      Great question. I say good, because a slight variation can make it not work. If you look in the article I actually mention the periods I used.

      The h clock will tick every 80 ns
      the v clock will tick every 63.84 us

      Perhaps the word "tick" is not used in your area. The tick is the same as the rising edge of something. In this case the rising edge of a h clock is happens every 80ns or 12.5 Mhz

      Hope this Helps

      Delete
  2. Hi, Derrick and thanks for your answer. Indeed, you mention that h clock ticks every 80ns so 1000/80 = 12.5 MHz for the pixel clock. A few more questions:

    1) Did you play with polarity of hsync and vsync as well? (for 640x480@60Hz both have negative polarity).

    2) Did you test QVGA output on a VGA/CRT monitor or a TFT-LCD panel?

    Thanks!
    Nikos Kavvadias

    ReplyDelete
    Replies
    1. 1) I don't know what you mean by polarity

      2) I used an LCD screen that had VGA port.

      Delete