Shop OBEX P1 Docs P2 Docs Learn Events
Better VGA DAC resistors — Parallax Forums

Better VGA DAC resistors

Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
edited 2012-06-12 18:54 in Propeller 1
I needed to make a VGA plug-in board for the Propeller Backpack, so I could render some captured video. I used 510-ohm resistors, paralleling where needed to get 255 ohms (vs. Parallax's usual 470/240 combo). In order to test it, I used Kye's excellent 160 x 120 VGA driver from the OBEX to create a test pattern. (Unlike the Propeller library drivers, Kye's worked out-of-the-box with my display. Yay, Kye!) I discovered that I was only getting three easily-discernible intensity levels, rather than the four I expected: %10 and %11 looked almost the same.

Checking the output with the scope showed a signal that's 1V P-P. But one volt is not right. The VGA spec requires 0V for black and 0.7V for maximum intensity. That's why %10 (0.75V) and %11 (1.00V) looked almost the same: both were above the maximum level. So I checked my Propeller Demo board and saw the same problem.

In order to come up with a minimally-invasive fix, I computed that a 100-ohm resistor from each of the RGB pins to ground would reduce the maximum output to just below 0.7V. A convenient place to add these resistors is between each color input pin on the DB-15 footprint and its associated Vss return connection. 0603 SMD resistors fit perfectly:

attachment.php?attachmentid=86283&d=1319481003

Here are the before and after pictures taken directly from the VGA screen:

attachment.php?attachmentid=86282&d=1319480701
Before the fix.

attachment.php?attachmentid=86281&d=1319480700
After the fix.

Here's a scope trace of one RGB channel after the fix:

attachment.php?attachmentid=86280&d=1319480699

The fix, although simple, is not perfect. The problem is that the output impedance (about 43 ohms) is wrong. It should be 75 ohms. (But, hey, the unmodified output impedance is 159 ohms, which is even further from optimum.) The optimum VGA DAC circuit (using 5% resistors) for each RGB pin is this:

attachment.php?attachmentid=86284&d=1319481225

It outputs 0.7V when both DAC pins are high and has a 75-ohm output impedance. If Parallax wanted to correct the output voltage (but not the impedance) without changing the PCB layout to add the loading resistors, the best 5% DAC resistors would be 820R and 430R, instead of 470R and 240R.

-Phil
640 x 480 - 12K
249 x 191 - 46K
247 x 188 - 45K
504 x 346 - 155K
320 x 166 - 1K
«1

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2011-10-24 12:14
    Thankyou Phil. While the differences are not huge with the color blocks, I should imagine it could make quite a difference to graphics.

    From what I understand, the series resistors for H & V sync are not that important, so would 820R for VS and 430R for HS be acceptable? If so, this would make an ideal solution for 3 smt quad resistor packs [EMAIL="4@820R,"]4@820R,[/EMAIL] [EMAIL="4@430R"]4@430R[/EMAIL] and [EMAIL="3@130R"]3@130R[/EMAIL].

    I already have provision for your 191R termination resistors on my TV (composite video) pcbs. I shall add these changes to any new VGA pcbs I do.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-10-24 12:38
    Cluso99 wrote:
    From what I understand, the series resistors for H & V sync are not that important, ...
    You might be right. With 510R series resistors, I'm still getting a 3.3V signal, which means the sync lines in my monitor are unterminated. If you try it, put the lower-valued resistor on HSYNC. That way there will be less of a timing delay where it matters more.

    -Phil
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-10-24 13:01
    I forgot the termination resistors [EMAIL="3@130R"]3@130R[/EMAIL] (updated my post). This leaves a spare 130R. Might this be better for HS or do you think it may be too low?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-10-24 13:19
    Cluso99 wrote:
    Might this be better for HS or do you think it may be too low?
    Short-circuit (fault) current would be about 25mA, so it's probably okay. You could always breadbaord it first to see if any issues crop up. BTW, if you're using the termination resistors, the other resistors are 510R and 270R, per the schematic. The higher values are only for Parallax's retrofit if they don't want to modify their PCB layouts.

    -Phil
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-10-24 16:53
    Great work Phil.

    Can you please post a complete schematic (I take it there are 3 resistors now for each pin - how many resistors now in total?). I can change this easily on the next revision of the dracblade.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-10-24 17:33
    Here are the complete schematics that use 5% resistors. Both versions produce the correct voltage levels into a 75-ohm load. The second one also has the correct 75-ohm source impedance. I've shown nominal values for the sync resistors, but I'm almost certain they can be varied quite a bit without issue.

    attachment.php?attachmentid=86315&d=1319575754

    -Phil
    727 x 500 - 7K
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-10-24 18:14
    Brilliant - thanks Phil. I'll add that second one (correct impedance) to my circuits.
  • TubularTubular Posts: 4,702
    edited 2011-10-24 18:53
    Good work Phil, but you need to take into account the pin driving fet resistance on the prop die, which is roughly 27 ohms. I found that was important when doing the 6 bit greyscale calculations

    The net effect of this is to shrink those external resistor values back towards 240 and 470 ohms, since "27 ohms of each resistor is internal to the prop".

    This may help explain why your CRO picture is reading "under". While the auto measure shows 676 mV I think its including the noise spikes rather than the "average baseline" of the high and low plateaus. By my eye I make it more like 3.25~3.3 divs or 650~660 mv. Calcs based on a 27 ohm internal resistance (297||537) into (130||75) yields an estimate 658mV peak, and an effective source impedance of 77.4 ohms.

    I agree for linearity you want to aim just under 0.7 volts, including a small margin for resistor tolerances (1% resistors? or more margin for 5%?)
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-10-24 19:00
    Thanks for clearing that up Phil, and the updated schematics. On the correct impedance circuit, with a 510R on the VS instead of 270R, I can use 3 quad smt resistor networks - nice and small.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-10-24 19:18
    Tubular,

    The scope trace was from 510||255 driving 100||75 (i.e. the quick fix), which computes to 0.664V without considering the 27 ohms. Adding in the 27 ohms (i.e. 537||282 into 100||75) results in 0.621V, which is lower than the scope trace would indicate. So the effective internal resistance must be somewhat less than 27 ohms and is probably current-sensitive.

    -Phil
  • TubularTubular Posts: 4,702
    edited 2011-10-24 20:23
    Yes, but it also could be the tolerance of the resistors, and/or the vertical tolerance of the CRO. I suggest doing some direct measurements of the voltages produced at DC using a DMM. You have the exact value of resistors so its easy to do. I think you'll be surprised at the driving resistance. My tests indicate its a pretty flat 27~29 ohms, over a wide range of driving currents, and for the P and N channel drive modes.

    (edit: the above measurements are for a Vdd around 3.3v, the usual case).
  • TubularTubular Posts: 4,702
    edited 2011-10-24 20:44
    I've been needing to revisit this for my own work, so here's some quick results

    "PNP drive mode" (resistor load to ground), Vdd = 3.28v
    Rext = 150 ohms, measured 150 ohms. Vext = 2.768v / 150 = 18.45mA. Rint = 0.515v / 18.45mA = 27.9 ohms
    Rext = 470 ohms, measured 470 ohms, Vext = 3.104v / 470 = 6.60mA. Rint = 0.1795v / 6.6mA = 27.2 ohms
    Rext = 1000 ohms, measured 1002 ohms, Vext = 3.198v /1002=3.198ma Rint = .0857v / 3.198ma = 26.8 ohms
    Rext = 10kohms, measured 9.98 kohms, Vext = 3.27v/9980 = .327mA. Rint = .0093/.000327 = 28.4 ohms <-- relatively large error possible due to low mV reading

    "PNP drive mode" (resistor load to small signal diode (0.71v node) then to ground), Vdd = 3.28v
    Rext = 243 ohms, measured 240 ohms, Vext = 2.301v / 240 = 9.59mA. Rint = 0.262v/9.59mA = 27.3 ohms <-- this setup is closest to VGA driving


    "NPN drive mode" (resistor load to Vdd), Vdd=3.28v
    Rext = 150 ohms, (same 150 ohms). Vext = 2.761v/150 = 18.41mA. Rint = 0.523 / 18.41mA = 28.4 ohms
    Rext = 470 ohms, (same 470 ohms), Vext = 3.097v/470 = 6.59mA. Rint = .1875/ 6.59mA = 28.4 ohms

  • Cluso99Cluso99 Posts: 18,069
    edited 2011-10-24 22:39
    I don't use any resistors that are not at least 1% tolerance max. There just seems no point when compared to the minimal cost savings.

    The only real advantage to using 5% is you can read the color code easier (or text if smt) ;)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-10-24 22:54
    If you want to use 1% resistors, there are better values than the ones I posted, which are the closest 5% values.

    -Phil
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-10-25 01:37
    Phil, what are the best 1% values?
  • prof_brainoprof_braino Posts: 4,313
    edited 2011-10-25 07:33
    Here are the complete schematics.

    This is probably a stupid question, but in post #7 the green inputs are labeled as going to the red output. Is this right?
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2011-10-25 08:25
    Phil, I'm aware that monitors ain't monitors and what you are seeing may indeed be a one-off especially as you say that the other library drivers didn't work out of the box with your display. I know too that the synch signals are sometimes high impedance and other times the series resistor has to be very low for it to work. I just measured one of my LCD monitors and they show 75 ohm termination on RGB and around 2.2K resistance on the synch lines but I am sure that I have had different readings from other monitors in the past.

    Also, the color charts that you showed could just indicate that you need to adjust the contrast and brightness for the monitor. Did you take readings on other monitors as well?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-10-25 08:48
    Cluso99,

    I'll have to redo the math later today to come up with the 1% values.

    prof_braino,

    Funny how errors propagate when you copy and paste! Yes, green goes to green. Thanks for catching it.

    Peter,

    Adjusting the brightness and contrast was the first thing I tried -- to no avail. But specs are specs. The VGA spec calls for 0.7V max into a 75-ohm load, and Parallax's circuit pushes 1.0V with a 150-ohm source impedance. Granted, there are differences among monitors, but the best way to accommodate most of them is to get the signal right to start with. That's why I created this thread. Think of it this way:

    1. The monitor showed symptoms that it was saturating (i.e. being over-driven).
    2. Checking with the scope confirmed that the output was too high.
    3. Parallax's circuit was fixed so output was in spec.
    4. Saturation symptoms disappeared.

    Science doesn't get any cleaner than that! :)

    -Phil
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2011-10-25 09:25
    I can't argue with your calculations which BTW are certainly ideal indeed. Just checking before I looked into your posts closer :)

    However, I hate using discrete resistors and especially all those different values as I much prefer resnets. if you use 270R resnets you could end up with this:
    precision video dac using resnets.png
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-10-25 09:32
    Peter, I agree with the resnet approach 100%. (That's the way I did composite output on the Propeller Backpack.) It not only saves on the BOM and pick-and-place setup but on board real estate, too. Plus, the DAC ratios are exact*. Thanks for the additional schematic!

    -Phil

    *Well, exact if you disregard the Prop's internal resistance. (I don't want Tubular to think I'm ignoring him. :) )
  • TubularTubular Posts: 4,702
    edited 2011-10-25 13:17
    *Well, exact if you disregard the Prop's internal resistance. (I don't want Tubular to think I'm ignoring him. :) )

    Perish the thought, lol.

    There's something else... the middle step on your CRO image is less than a division, so less than 1/3 of the full 3.3ish divisions of the full amplitude. The internal resistance may help explain this. But looking at your capture images, if anything I'd be saying the jump from 01 to 10 is *more* than 1/3, especially for the green channel. But that could be the LCD at my end too, and so it goes on.

    At the end of the day, "what looks good/sounds good/works best with my equipment" certainly has some validity, we've seen that with the C3 audio discussion. But its good to understand the science thoroughly too*

    * there is an excellent chance I will trip myself up with this statement
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-10-25 14:00
    Tubular,

    I think you're over-analyzing things. :) The color test patterns are photographs taken with a digicam from a VGA screen (with who-knows-what-kind of gamma correction in place) in subdued lighting with the camera's lowest EV setting, then rendered as jpegs without dealing with the visible Moire interference. <understatement>There is likely to be some non-linearity introduced by this process.</understatement> But that does not compromise the main thrust of this thread, since the resistor mods produced a significant visible improvement in the linearity.

    -Phil
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-10-25 14:40
    Okay, attached is a spreadsheet everyone can use to analyze the situation. (Play with the values in column B, and observe the results, shown in red.) Here's the output with some standard 5% resistor values, including Tubular's internal resistance observations:

    attachment.php?attachmentid=86318&d=1319578704

    (Note that the net resistance to ground includes the 75-ohm load. The computed impedance is the output impedance.) It would be hard to ask for better linearity, maximum output, and impedance matching than that! :)

    -Phil
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-10-25 17:51
    Phil, I have added the TV (composite video) calculations to your spreadsheet. Would you mind checking my calcs please. These are ideal, not preferred values.

    VGA-TV-Resistors.JPG


    vga_tv_resistors.xls
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-10-25 21:40
    Your formulae look okay. But for composite NTSC/PAL output you want your voltage range to be as close to 0.0V - 1.0V as possible.

    Attached is your spreadsheet with the analysis I originally did for the Propeller Backpack, which uses 4x430R resistor packs exclusively, and which analysis did not include consideration for the Prop's internal resistance. If you add the internal resistance, you also have to add it to the 215R ground resistor, since that gets pulled to ground by a Prop pin (A16) in the Backpack.

    -Phil
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-10-25 23:40
    Thanks Phil. Here is the TV using 1% 0805 resistors for straight prop circuitry (not backpack).
    I wonder if this may account for some problems people are having with some TV monitors?

    VGA-TV-Resistors2.JPG
    973 x 327 - 76K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-10-25 23:56
    The standard Parallax video circuit will definitely cause trouble for non-75-ohm-terminated monitors that expect a 2V P-P signal, since its unloaded output is 3.3V P-P.

    -Phil
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-10-26 02:28
    @Cluso, I have a TV display in front of me and it seems to me that with 270/560/1k1 the gray scale on the standard propeller palette looks fairly even to me. (There are big problems with the yellows which are all dark orange, but these are not due to the resistors, and also can be fixed by putting the actual TV colors into a Floyd Steinberg algorithm which then lightens up all the yellows by mixing with white).

    VGA is much better for a more even palette of colors.

    Re the VGA colors, are these the correct resistors?
    668 x 600 - 147K
    922 x 572 - 93K
  • ericballericball Posts: 774
    edited 2011-10-26 03:49
    For TV the resistor values are less critical as the TVs can (and typically do) perform automatic gain correction using horizontal sync as a voltage reference.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-10-26 08:40
    Dr_A,

    Per the spreadsheet results shown in post #24, I'd change your 270's to 240's.

    -Phil
Sign In or Register to comment.