Joined: Fri Aug 30, 2002 1:09 am Posts: 8546 Location: Southern California
|
Here are a couple of ways to handle it. Yes, the LED is a current device, not voltage; but the op amp can just as easily put out a current as a voltage. Here's the idea:
Attachment:
R2R_LEDdriver.gif [ 25.43 KiB | Viewed 1741 times ]
The resistors in the ladder need to be matched within about 1% for the six bits shown here. I find that 5% carbon-film resistors are usually within 1% anyway, so if you have a bunch, just measure them with your DMM and you might find a set that are within half percent of a center value. I kept it up at 10K and 20K because the pin drivers of the 65C22 aren't exactly zero ohms, but more like 50 ohms which is 0.5% of 10K. You could go higher, like 15K and 30K, 18K and 36K, or 75K and 150K, all of which are standard 5% values. 1% values will give more choices. The LM358's or LM324's maximum input bias current is 250nA (45nA typ), and 250nA times 75K is about 1/2 LSB here, so I wouldn't go any higher than that.
The top 2R resistor is tied to ground so the output of the ladder goes 0 to 2.5V*(63/64) which is 2.46V which will be reflected on the emitter resistor, leaving at least about two and a half volts for the LED at max brightness which is fine for red or yellow. Green won't get quite all the way to full brightness, meaning approximately the last five codes (out of 64) won't result in any increase in brightness. Blue will be worse. IIRC, red is around 1.7V, yellow around 2.2V, green around 2.7V, and blue around 3.3V. Raising the power supply voltage at the LED's anode is one way to do the job. Another is to add another R-2R pair at the top of the ladder and ground that 2R as well, then cut the 220 ohm resistor down to 100 or 120 ohms. As it is, with a red or yellow LED, you'll get a maximum current of about 11mA which is very bright with modern LEDs. I never run them that high for indicators in our products. The days when you needed 20mA are gone.
Several things here are flexible, especially to the right of the ladder. The LM358 is a common, inexpensive dual op amp available in an 8-pin DIP. The LM324 is the quad version, in a 14-pin DIP. You only need the one section here, and the other(s) is (or are) left for other purposes.
For a software-implemented PWM, one way is discussed in the 65(c)22 data sheet, where it's talking about using T1 in free-run mode and making it invert PB7 on each time-out, and generating an interrupt with every time-out. What it does not clarify is that you need to write x1xxxxxx to the ACR before writing to the counters, and you need to write directly to the T1 counters to get T1 started, and then you can write to the latches after that. I don't know if all brands are the same (I suspect they are), but we had quite a time of getting this going in the late 1980's until an applications engineer sent us some sample code.
_________________ http://WilsonMinesCo.com/ lots of 6502 resources The "second front page" is http://wilsonminesco.com/links.html . What's an additional VIA among friends, anyhow?
|
|