PDA

View Full Version : Better VGA DAC resistors



Phil Pilgrim (PhiPi)
10-24-2011, 07:38 PM
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:

http://forums.parallax.com/attachment.php?attachmentid=86283&d=1319481003

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

http://forums.parallax.com/attachment.php?attachmentid=86282&d=1319480701
Before the fix.

http://forums.parallax.com/attachment.php?attachmentid=86281&d=1319480700
After the fix.

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

http://forums.parallax.com/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:

http://forums.parallax.com/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

Cluso99
10-24-2011, 08:14 PM
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 4@820R, 4@430R and 3@130R.

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)
10-24-2011, 08:38 PM
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

Cluso99
10-24-2011, 09:01 PM
I forgot the termination resistors 3@130R (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)
10-24-2011, 09:19 PM
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_Acula
10-25-2011, 12:53 AM
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)
10-25-2011, 01:33 AM
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.

http://forums.parallax.com/attachment.php?attachmentid=86315&d=1319575754

-Phil

Dr_Acula
10-25-2011, 02:14 AM
Brilliant - thanks Phil. I'll add that second one (correct impedance) to my circuits.

Tubular
10-25-2011, 02:53 AM
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 (http://forums.parallax.com/showthread.php?131622-Resistor-values-for-64-GreyScale-VGA-output-from-the-Propeller&highlight=greyscale)

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%?)

Cluso99
10-25-2011, 03:00 AM
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)
10-25-2011, 03:18 AM
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

Tubular
10-25-2011, 04:23 AM
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).

Tubular
10-25-2011, 04:44 AM
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

Cluso99
10-25-2011, 06:39 AM
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)
10-25-2011, 06:54 AM
If you want to use 1% resistors, there are better values than the ones I posted, which are the closest 5% values.

-Phil

Cluso99
10-25-2011, 09:37 AM
Phil, what are the best 1% values?

prof_braino
10-25-2011, 03:33 PM
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 Jakacki
10-25-2011, 04:25 PM
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)
10-25-2011, 04:48 PM
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 Jakacki
10-25-2011, 05:25 PM
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:
86304

Phil Pilgrim (PhiPi)
10-25-2011, 05:32 PM
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. :) )

Tubular
10-25-2011, 09:17 PM
*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)
10-25-2011, 10:00 PM
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)
10-25-2011, 10:40 PM
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:

http://forums.parallax.com/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

Cluso99
10-26-2011, 01:51 AM
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.

86325

86324

Phil Pilgrim (PhiPi)
10-26-2011, 05:40 AM
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

Cluso99
10-26-2011, 07:40 AM
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?

86333

Phil Pilgrim (PhiPi)
10-26-2011, 07:56 AM
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_Acula
10-26-2011, 10:28 AM
@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?

ericball
10-26-2011, 11:49 AM
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)
10-26-2011, 04:40 PM
Dr_A,

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

-Phil

Cluso99
10-26-2011, 06:39 PM
Drac: Don't forget the TV termination resistor to gnd. I would also change the values somewhat (see post #27 - plug values into spreadsheet #25 or #26)

Phil Pilgrim (PhiPi)
10-26-2011, 06:51 PM
I missed the TV connection. Dr_A, your situation is complicated by the fact that you're sharing the TV and VGA connections. This means that the voltage drop across the internal resistance of the Prop pin will derive from current through both circuits, even though you're only using one at a time. That will require a more complex analysis that what we've done here, since there's a codependence between the two circuits.

-Phil

Toby Seckshund
10-27-2011, 09:37 AM
Many moons ago, on a Blade2 copy, I put an eight way resistor in reversed. Instead of getting P24 - 31 with 10K pullups I got a mind bending set of 20K interconnects.

Dr_Acula
10-27-2011, 10:04 AM
Per the spreadsheet results shown in post #24, I'd change your 270's to 240's.

Thanks Phil - have made the changes.

Re the TV vs VGA, the *best* solution is to solder up one board for TV and another for VGA. With Gadget Gangster boards you can swap those in and out easily.

Keep up the good work!

Toby Seckshund
10-27-2011, 02:46 PM
I seriously doubt that the vast magority of VGA cables have the characteristic impedance of 75 Ohms. They often just have "thin" co-axes or even single wires within an overall shield.

Still it is good to get as close as possible.

Cluso99
10-27-2011, 10:24 PM
Since Phil has done all the hard work here, may as well use the correct values. There is little cost in this.
I just plug in VGA or TV modules into my baseboard - its easy as.

Sapieha
10-29-2011, 12:35 PM
Sorry if it is of topic.

BUT for any that need correct pin definitions and theirs Voltages on VGA.

Look on attached picture

86433

Oldbitcollector (Jeff)
06-13-2012, 02:54 AM
@Phil,

Implemented your OP fix on my test rig tonight. Went from 48 countable colors to 64 colors with the driver I'm using.

My hat's off to you. Nice fix!

OBC