0
\$\begingroup\$

I have a project where I want to read the HSync and VSync signal from a VGA cable into an microcontroller and calculate the pixel clock.

Calculation: Pixel clock = Horizontal Pixel Count * Vertical Line Count * Refresh rate

I'm currently stuck by the question of how I can get the horizonal pixel count.

If we assume that my VGA cable caries a 640x480 (800x525 with the porches) @ 60Hz signal, like shown here:

enter image description here

http://tinyvga.com/vga-timing/640x480@60Hz.

I can get the refresh rate by timing the vertical sync pulses to each other (~16.68ms > 1/16.68ms = 60Hz.) I can get the vertical pixel count by dividing the time of every frame and the time of every HSync pulse to each other (16.68ms / 31.77µs = ~525 lines).

How do I get the horizontal pixel count?

For 640x480 @ 60Hz it should be 800 pixels.

Really important is that the resolution and framerate of the VGA cable is not fixed, so I can not use any definitions for timings.

For clarification: I know that a VGA cable sends analog signals and there aren't any pixels. But my source device have pixels and they convert them into analog video signals. So want to get the pixel clock from my source device that is connected via a VGA cable.

\$\endgroup\$
14
  • 1
    \$\begingroup\$ no, for an VGA 640x480 signal 640 are only the visible pixels. The other 160 pixels are in the front and backporch and in the sync pulse. \$\endgroup\$
    – user321329
    Commented Jan 13, 2023 at 12:52
  • 2
    \$\begingroup\$ But, isn't it an analogue signal and you can sample it at whatever rate you want? \$\endgroup\$
    – Andy aka
    Commented Jan 13, 2023 at 13:04
  • 2
    \$\begingroup\$ Since VGA is an analog interface I don't think it has a (digital) pixel clock. Instead you get an analog waveform with continuously distributed (analog) voltage. Use a digital interface if you need a pixel clock, or make up your own after you convert to digital. \$\endgroup\$ Commented Jan 13, 2023 at 13:59
  • 3
    \$\begingroup\$ I just realized you said you already knew there were no pixels. If you know there are no pixels why are you asking how many pixels there are? There are none. Zip. Zilch. Zero. \$\endgroup\$ Commented Jan 13, 2023 at 14:10
  • 3
    \$\begingroup\$ That can't be calculated since there isn't enough information, but you could definitely try to estimate it via Fourier analysis and from the vertical refresh. You'll get it wrong occasionally but for most devices it shouldn't be too hard to correctly guess. \$\endgroup\$ Commented Jan 13, 2023 at 14:24

3 Answers 3

3
\$\begingroup\$

You could find out what is the display formats of the signal by analyzing the time between VSYNCs and between HSYNC.

I have found a table in the datasheet of the AD9888. At page 15 they give the expected timing on theses signals versus the display formats.

There you will also find the pixel clock rate for that given format.

Thus you need to implement a lookup table with these values in your code, measure the HSYNC and VSYNC timing to know the format and fetch the corresponding pixel clock from the table.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ That might be the best option to have lookup table. And based on the timings to choose the most likely resolution \$\endgroup\$
    – user321329
    Commented Jan 13, 2023 at 14:11
  • \$\begingroup\$ @ArtjomEske you did say you can't use any definitions, does that include guessing the best definition out of a big table of definitions? \$\endgroup\$ Commented Jan 13, 2023 at 14:40
  • \$\begingroup\$ Since 2 answer have already stated that it’s not that easy or not possible since there isn’t enough data to calculate it, the best option would be to look in a lookup table to estimate the resolution from what I’m measuring. I said that in don’t want any definitions but a lookup list would be the most possible way and only estimating the pixel count I a fine trade off. \$\endgroup\$
    – user321329
    Commented Jan 13, 2023 at 14:50
2
\$\begingroup\$

There are no horizontal pixels in VGA.

Remember VGA comes from the era of CRT (cathode ray tube) monitors. The electron beam (cathode ray) sweeps from left to right across the screen, and the VGA signal continuously adjusts the brightness of the beam. There are no pixels.

You already knew this.

\$\endgroup\$
1
\$\begingroup\$

There is no way you can calculate it with 100% certainty.

As is very rare that video cards are programmed to any arbitrary or non-standard format, not even monitors can lock on to any arbitrary format, or at least show them properly, since the exact parameters are not known.

You can only try to detect automatically what it might be, by trying to match the measured HS and VS signal parameters to known formats and allowing some tolerance.

Even with VGA, the video drivers read the monitor EDID for list of supported formats, and then simply use supported formats for which the monitor can know the parameters.

For example, if you measure 525 lines per frame, with sync on for 2 lines, and if VS rate is about 59.94 Hz and HS rate is about 31468.75 Hz with duty cycle matching the ratio of 96 active compared to 800 being length, then you can simply assume that you have a standard VGA format with 800 pixels, which means a standard pixel clock of 25175000 Hz.

Since you know what the standard values for a detected format are, you can then scale the calculated pixel clock accordingly, if the video card uses slightly non-standars pixel clock, e.g. if the frame rate is 60.00 Hz instead of 59.94 Hz.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.