Archive

Electronics

As happens on a fairly regular basis these days, the two- to six-week shipping wait came to an end last night for another so-cheap-as-to-be-questionable eBay electronics purchase from China or Hong Kong. This time, it was an item called “New Mini Mirror Clip Mp3 Sport Music With TF-Card[1] Slot Up To 8GB”. I purchased two of these for $1.45 each, shipping included, with the intention of cracking them open and controlling them using a microcontroller[2], but also with the knowledge that even the non-MP3 parts, including a 3.5mm stereo jack, a USB mini-B jack, a microSD slot, a little rechargeable battery, and maybe some other goodies, would justify the already trifling cost as scrap.

The Player Itself

Backed by a $5 memory card and a USB cable from a far more expensive Sony music player, this tiny device somehow fails to be irrelevant.

Before I went to work on taking it apart, I set about making sure the thing actually worked. Because I didn’t have a card adapter handy, I used the USB interface on the device itself. It’s not fast by any stretch of the imagination—I think it actually uses USB 1.1 (and, after having looked at the guts, I’m guessing the low-speed SPI interface on the card). I put on files in four formats—MP3, WAV, Ogg, and FLAC—in order to determine what it would actually play.

The results are these: Only the MP3 file played. After changing the extensions on the other files to .mp3, the WAV file also played, but the others were still skipped. And while the output of the audio content itself was adequate, there was substantial background noise carried over from the rest of the circuit. For under $8 including the shipping and the memory card, we’re not expecting a hi-fi or even an iPod shuffle—but this is a reminder that we’re working with something suitable for little more than a toy. And that’s okay, because the less shady version of an MCU-controlled MP3 decoder will set you back $40 from a finer (and more legitimate-feeling) retailer.

MP3 player with front face slightly separated

The device comes apart with a light touch.

No screws were visible on the device, so I set about coercing it apart by running my thumbnail down a seam on the face. As you can see, it was more than cooperative. (That said, I think it would take a non-trivial impact for it to come apart on its own.)

MP3 player with mirror face detached

Pink.

The mirror face is actually kind of like a sticker with a backing having roughly the malleability of thin sheet aluminum. It was stuck by a tacky adhesive to the back of the face, which was a slightly thicker piece of pink plastic.

MP3 player with face removed and tactile domes exposed

Clickity.

The rest of the face comes off easily, revealing the PCB with five tactile domes (the kind that deform under your finger and make an obvious click when depressed) taped in place.

MP3 player with tactile domes partly removed

The domes and contacts.

MP3 player with tactile domes removed

Bull’s eye.

Under each dome are concentric outer and inner contacts on the PCB; pressing the dome connects the center to the surrounding ring, registering a button press.

Freeing the PCB from the case was slightly more than my thumbnail could muster, so I used a prong from the plug end of a phone charger I had handy. As before, it was only lightly stuck into place and required only trivial force to remove.

MP3 player full PCB and battery

The guts.

The internals of this thing, at least from what I can see without desoldering anything, are amazingly simple. Other than a number of discretes countable on one or two hands, you have the battery, the microSD slot, the stereo jack, the USB jack, a very small switch (I think SPDT), and the main event—an SOIC-16 chip running the whole show.

Detail of MP3 player PCB

I don’t know who this “JL” guy is.

The latter is marked with a logo that looks like somewhere between “JL” and “π”, followed by the cryptic legend “AB1426CF3Y13.1-83En” for which Google proves useless to make any connection.

Several of the pins on the microSD card are kept intentionally disconnected (there even appears to be a bit of silkscreen to prevent their accidental connection), which is why I think the SPI mode (which uses fewer pins than the full-speed modes) is in use.

Anyway, the whole thing is actually surprisingly simple connection-wise (a good deal less complex than the player in original Instructable). I kind of wonder if I could perhaps get the whole thing desoldered, reverse-engineer a schematic, and put it back together in a way that would have fewer noise issues.

Fun.

  1. [1] TransFlash, or “TF”, is an outdated name for microSD. Given that microSD is far more recognizable, and that an 4GB or 8GB card is not even plain microSD but microSDHC, I have no idea why they’d call it by this name.
  2. [2] in a similar fashion to this Instructable which uses a somewhat more expensive but mostly identical player

A simple one-directional level shifter is easy to build out of an NPN transistor and two resistors in the common-emitter topology, if the application doesn’t need to sink as well as it sources—that is, if a significant output impedance is acceptable when the output is high. If low impedance is needed for high output, an additional PNP transistor and two resistors[1] can be added, again in common-emitter topology, to re-invert the signal, but then the output low has the impedance instead.

To both source and sink with comparably low impedances, the obvious solution, if you’re properly equipped, is probably CMOS: Two complementary MOSFETs configured to pull the output either up or down, with similarly low impedance either way—or, more likely, a CMOS logic IC that does the same thing, but in a more compact fashion.

Still, there are some possible issues:

  • If you don’t keep a stock of (fairly well matched) N-channel and P-channel FETs around, you can’t really build a CMOS inverter out of them.
  • If all you have are 74HC-series ICs, the output voltage must be from 2V to 6V. If your output voltage is, say, 13V, this is a no-go.[2].
  • If the input high voltage is too much lower than the output voltage, a logic high may not register properly. A preliminary low-to-high shifter (such as the single-sided NPN thing from before, 3 parts) would be needed for each input.
  • If the input high voltage is too much higher than the output voltage, a logic high may do some damage to the IC. A preliminary high-to-low shifter (such as a resistive divider, 2 parts) would be needed for each input.

Incidentally, constructing a CMOS-like complementary output using discrete bipolar transistors is not advisable;  even short input transitions can cause high and low transistors to be on simultaneously for a non-trivial amount of time, a condition called shoot-through, which results in a massive current spike likely to damage both transistors and possibly other components. One way to avoid this condition is to add a resistance between the high and low sides, but then we’re back to the original problem. Shoot-through is evidently less of a concern with CMOS, partly because the FETs involved have better tuned and matched thresholds, and partly because a MOSFET is less subject to self-destruction via thermal runaway than a BJT.

Wanting to prototype something with an oddball push-pull 3.3V-to-13V switch led me to concoct an experiment using only stuff available at a reasonably well-stocked Radio Shack[3], with particular attention to ICs that provide push-pull outputs. So far I’ve tried configurations based on the original 555 timer[4] and the TL082 op amp.

My first experiments with the TL082 in Schmitt trigger configuration were not promising, but I’m suspicious something may have been connected wrong; the logic low never went below 1.15V, which happens to have been the reference voltage, half of 3.3V. Either way, the supply voltage had to read 17.3V for a high output of 13V.

In contrast, the 555-based Schmitt trigger appears to be a workable solution, as long as you can drive the chip 1.5V higher than the desired high output.

555 shifter

555 as a level shifter in just two parts (not including the load). Output is a roughly fixed amount below Vcc.

The output stage of the 555 is a push-pull output, but it is implemented with bipolar transistors in a traditional style, meaning both high and low sides are NPN transistors. This works, but at the cost of about 1.5V from Vcc. If you can pay that cost, it should work nicely.

In my experiments with the pictured circuit, using 1K for the load, the output was 12.5V for a 14.0V input. Similarly, it went up to 13.0V for 14.5V input, and 5.0V for 6.5V.

Apart from the 555, there is a diode to set the control voltage. The CV pin is essentially the top split of a 5K:5K:5K resistive divider from Vcc to ground. The splits of this divider set the high and low thresholds of the Schmitt trigger; they are CV (default 2Vcc/3) and CV/2, respectively. A silicon rectifier diode is added from the CV pin to ground, forming a crude shunt regulator with the internal resistors. This sets CV to about 0.6V and the low threshold to about 0.3V. This is suitable to make the input accept a clean signal directly from a 3.3V or 5V CMOS logic output. Adding a second diode in series with the first would double those levels, making input from a somewhat noisy source or from 5V TTL practical. CV could similarly be set using a Zener diode (in reverse) or by constructing a voltage buffer, but at that point you may just want to order a more suitable part.

So, there you have it—an imperfect but still practical low-impedance level shifter in just two parts.

  1. [1] or one resistor, with caveats I haven’t fully investigated
  2. [2] If you have the older CD4000-series ICs, however, up to about 18V is possible, as long as the inputs are brought within range.
  3. [3] For those of us who don’t have 24 hours to wait for progress.
  4. [4] Not the TLC555 they also carry, which may work better or worse.

(Continued from Part I.)

I lead with two developments that required an additional shopping trip—on Hack Friday, no less.

First, I discovered that there could be some situations in which the holes on the two opposing corners of the plates turn out to be insufficient. In particular, the board may need to be of a minimum size and placed symmetrically across the line between the two bolts; otherwise the pressure over the surfaces of the board may be uneven. One remedy for this could be to restore balance with a spacer of the same thickness, such as a scrap piece of the same copper-clad.

Another fix could be to forget about the holes and secure the board more evenly (for example, on each of the four corners) with some sort of clamps. This might be more generally applicable since it could be adapted to larger plates that do not already have holes. So, I had to identify something that would be useful as a clamp that is also inexpensive and capable of surviving being baked. A small steel beam clamp in the electrical section of Chain Home Improvement Store seemed like it could fit the bill for under $1 apiece.

Second, my wife vetoed my use of the oven in the kitchen. This is completely understandable—we use it for food, and the hardware I’ll be heating, not being graded for food safety, could potentially produce all sorts of unfriendly gases and residues. This is a job for a garage oven, and that means a toaster oven. Fortunately, a fancy one isn’t necessary—an arbitrary box that semi-steadily holds its content at a set temperature is all we need. Much-Maligned Chain Department Store stocks a $15 firestarter model. They were out of stock, so I upgraded to the $20 firestarter model.

Supplies

The ragtag bunch of misfits. Clockwise from top: Toaster oven, steel beam clamps, steel electrical work box cover plates, USB mini-B breakout board patterns on baking parchment, double-sided copper-clad PCB blanks.

So, on to the first experiments executed this evening.

I started by printing the layout of Sparkfun’s USB mini-B breakout board several times over on baking parchment paper. I selected this board because it’s small and thus suitable for repeated trials. (As a bonus, I actually need one; I’ve got a couple of the connectors collecting dust in a drawer.)

Parchment

Left to right: A freshly cleaned piece of copper-clad, a nicely printed pattern on parchment, and one that didn’t come out so nicely.

Printing on parchment is tricky. It is something that you can get to work, but it may take a few tries. Parchment paper is coated with silicone, making it difficult to stick anything to. The fact that the paper releases easily is a desirable property for a toner transfer backing, but it does its job perhaps a little too well. Traces printed this way may not stick long enough to fuse correctly, resulting in smears and runs. When a pattern does take correctly, it must be handled somewhat delicately, as it can scratch or flake off without much of an impact. Still, since someone has gotten it to work[1], I think this can be a reasonably useful medium if you have some patience, and it’s certainly priced to sell (sold by the roll in your grocery store of choice).

I may include the other common media (magazine paper, inkjet glossy photo paper) in future experiments.

Incidentally, any sort of slick tape appears to be a bad choice for attaching the medium to ordinary paper; it being all I had at the moment, it caused more paper jams than I’ve ever encountered with this printer. I’ve had more success with matte tape[2].

I cut the copper-clad for the board and gave it a light cleaning with a soft abrasive[3] before building the apparatus around it.

Patterns, board, and one plate

Copper-clad between two patterns on top of the bottom plate.

One copy of the pattern was placed on either side of the board. The registration wasn’t given too much attention because that isn’t the point of the current experiment (I’ll work on it once I have the adhesion process working), and because the patterns are both the same rather than flip sides of a double-sided board. To conserve the clearly printed copies of the pattern, a misprinted copy of the pattern was used on one side.

Apparatus with top plate

All of the above plus the top plate.

The board and patterns were laid down onto one of the steel plates, then the other plate was placed on top.

Apparatus with clamps

Clamps are added to press everything together.

The steel clamps were added to the edges of this sandwich and the bolts tightened.

Apparatus in oven

The smell of fresh-baked productivity. (But seriously, try not to inhale any fumes.)

The full apparatus was then placed on the top rack of the preheated oven (there are two heating elements situated at the top and bottom, so the bake should be fairly even regardless) and baked for a specified amount of time.

Quenching the assembly

If lowered into the water slowly, there is audible boiling. If dropped quickly, as shown, you end up with a watery mess. Some sort of middle ground is probably a good idea.

Afterward, the assembly is removed from the oven and immersed in cool to tepid water, bringing it to a safe temperature for handling.

The results are examined immediately. The medium is removed without any special degree of care; any toner dislodged by normal handling cannot be considered to have adhered properly.

The variables I’m currently seeking to study are:

  • Bake time
  • Bake temperature
  • Clamp pressure

For tonight’s experiments, I decided on:

  • Trials of 10 and 30 minutes
  • Temperature of 350°F (setting of the oven, not measured temperature)
  • Clamp pressure resulting from tightening the bolts as far as I could using only my fingers, rather than a wrench.

10-minute trial, proper side.

10-minute trial, misprint side.

30-minute trial, proper side. Note that the extra time has discolored the copper somewhat.

30-minute trial, misprint side.

Put briefly, neither result was quite satisfactory, but I believe I’m on the right track. The 10-minute trial gave a better result than I’ve achieved with an iron and parchment. The 30-minute trial was somewhat better, but not so much so that I think adding more time is the key. The toner that did transfer was clear and crisp with no real smudging, which to me indicates that we could afford to apply more pressure. So, it’s likely that the next experiment will be a repeat of tonight’s, except using a wrench to tighten the clamps a little harder.

  1. [1] Refer to the Instructable by dustinandrews.
  2. [2] “magic” or “invisible” tape
  3. [3] Bar Keepers Friend soft cleanser.

While lying in bed last night, I was going over in my head everything I could recall having learned about getting a PCB[1] layout out of my computer and onto a piece of copper clad.

At this point in history I’ve managed to successfully iron a toner pattern onto a board only about three times, and each success came at the cost of around ten failures. The glossy photo paper is the only thing I’ve gotten to work; with magazine paper the image was too smudged to use, while with parchment paper hardly any of it stuck (though what did stick was high-fidelity). What has really been frustrating in this whole process is that there are too many variables and not enough correlation. I don’t know whether I haven’t been using enough pressure, waiting enough time, executing the correct motions, or using the right setting on the iron. For all I know, I could just have a crappy iron!

And everyone seems to have something different to try, with the most consistent results apparently from either (a) using a modified laminator for the toner transfer or (b) equipping for photoresist boards. Of the two, I would surely choose the photoresist, in part because it produces truly sharp results but mostly because the failure/success ratio seems to be lower. But both options involve buying new equipment (and in one case ruining it) with no guarantee of out-of-box success, and given the laser printer and copper-clads already in my possession, I’m already well in.

Anyway, I suddenly had an idea that, if it works, combines the even heat and pressure of a laminator with extremely low (new) equipment cost and increased controllability, the latter of which translates into more meaningful experiments and, when an experiment succeeds, more repeatable results.

What I decided was necessary is as simple as this:

  • The patterns are printed in reverse on the medium of choice—for me, it will be parchment paper since it already exists in my house.
  • The board is placed in alignment with the patterns on one or both sides.
  • The board and patterns are placed between two flat plates of rigid metal, such as steel.
  • The plates are bolted together and tightened at least to the point that nothing slides around.
    • Here, the sustained flatness of the plates is important so that the pressure remains fairly even across the entire pattern.
    • If you have any way to gauge it, take note of the tightness or pressure of the plates on the board. This is possibly one of the variables.
  • The oven is set to the target transfer temperature.
    • To be truly scientific about it, use an oven thermometer to ensure the knob is telling the truth.
    • The temperature is certainly one of the variables.
  • The oven is allowed to preheat until up to temperature.
    • My hypothesis is that a consistent result is probably easier to obtain from a preheated oven due to variances in rise time.
  • The plate apparatus is placed in the oven near the heat source.
    • If the apparatus can be hung sideways from the rack, do so allowing equal heat exposure to the two sides.
    • If the oven has a convection mode, it might be worth using.
  • A prescribed amount of time passes.
    • Another variable.
  • The apparatus is removed from the oven.
  • The apparatus is allowed (as by air) or forced (as by water) to cool to a safe temperature for handling.
    • Maybe another variable.
  • The apparatus is disassembled and the results are examined.
    • An effective transfer should stick well enough that it does not lift or flake when the medium is pulled away. Therefore, the medium can be pulled away without being exceedingly gentle.
    • If the result is unsatisfactory, a hypothesis is formed as to why that relates to one of the variables. The variable is adjusted and another attempt is made.

With this basic process in my head, I went to Chain Home Improvement Store to seek something I could use for the plates. What I found was square steel covers for electrical work boxes, in a flat variety with no punchouts. They already have holes for fasteners at two of the corners, and it was only $1 for the pair. I also got #10-24 stainless steel bolts and wingnuts which themselves totaled $4. This setup should adequately accommodate boards up to about 3 by 4 inches (for comparison, the standard Arduino footprint is 2.7 by 2.1 inches).

I now have all the equipment I think I’ll need to give this a shot, and that could happen as early as this weekend (and I’ll try to take photos). I really hope it works, not just because it would be convenient for me, but because it has the potential to lower the blood pressure of many other frustrated hobbyists.

  1. [1] printed circuit board
2-channel-power-Pch

If it works as intended, this circuit should allow an Arduino to control 2 different output voltages via PWM.

(EDIT: The above is the second revision.[1] Note also that the above will not work as-is, except perhaps in the NPN or N-channel variants; it doesn’t account for the fact that the op amp outputs peak well below the voltage necessary to turn off a PNP or P-channel transistor.)

Out of nowhere I just happened to find an 18V wall wart in my junk box. The lack of such a thing makes it necessary for a PIC programmer to produce its 12-14V programming voltage some other way, such as with an adjustable regulator and a pair of 9V batteries or with a boost converter. Even so, a programmer for production-quality output must be able to adjust its own programming voltage as well as its own output supply voltage.

Read More

  1. [1] This version uses P-channel MOSFETs instead of PNP, and better explains the power requirements.
piculear Suite

A suite of pieces that just might comprise a working PIC programmer when connected to an Arduino.

Years ago, while frustrated with my Microchip PICkit 2, which I only bought because of two failed attempts at building serial-port-based PIC programmer designs, I considered the possibility of a somewhat more open design that still had solid USB-based communications and the 5-to-13V boost converter, which was still kind of mysterious to me at the time.

Read More

This circuit provides a pulse-sequencing capability using the control voltage inputs of the 555.

The circuit described here triggers three (or an arbitrary number) monostables with differing but related widths. What’s different about this one than others I’ve seen is that this circuit has only one timing signal; in particular, there is only one RC network among all, which could potentially reduce the parts count and, more importantly, increase consistency among the timers.

The timing network is actually sort of a modified RC using a transistor and a voltage reference to charge the capacitor with a constant current. The timing is determined by the base voltage of the PNP transistor, the resistance at the emitter resistance, and the capacitance at the collector. The voltage drop across the resistor is the Vcc – Vb + Veb[1]. As long as none of these three values vary significantly in the application, the resistor’s voltage drop can be considered constant. If the resistor is, as expected, also constant, then the current through it is constant as well: I = V/R. The transistor will adjust as necessary, if possible, to maintain that current through the transistor[2]. If the supply voltage is well regulated, the base voltage can be set with a voltage divider.

The output of this constant current timing network, in contrast to the tricky curve of a regular RC network, is a linear ramp. This makes it easier to calculate the desired control voltage for each monostable. In the example above, the control voltages are 1V, 2V, and 3V, where the 1V and 2V timers produce a pulse exactly 1/3 and 2/3, respectively, the width of the 3V timer pulse. The values need not be this regular. A normal RC network could be substituted if you’re willing to do the math.

The monostable with the longest delay should have its discharge pin connected with its threshold pin in order to discharge the capacitor.

This approach gets a little unfortunate where setting the control voltages comes in. The CV is preset internally with a three-step resistor divider network. The CV itself is roughly 5k from Vcc and roughly 10k from ground. If I’ve done the math correctly, this is equivalent to a 2Vcc/3 supply through a 3.3k resistance. This means that you can’t trivially set the control voltage with a divider—something with a low (ideally zero) output resistance is necessary. Here are some things that might be worth trying:

  • Resistor divider with proper buffer (2 resistors, 1/4 to 1 op amp IC). If you’re not willing to complicate the calculations, an op amp can output the same voltage as the input, with no base-emitter drop. As a bonus, it’s an op amp, which is capable of a whole lot more. If restricted to Radio Shack, I’d pick up two TL082 JFET dual amps (or an LM324 quad if they’re out), then use three of the amps with a resistor ladder to set CVs and the one left over to upgrade the current source. I’d guess this is the option that would involve the least hair-pulling. (Edit: An example of a buffered resistor divider, complete with redone current source, in terms of a 7805 voltage regulator. Would require a supply voltage above 7 volts or so, but it’s an easy out in 2-3 ICs and about 10 resistors, plus the transistor and RC already in the circuit.)
  • Resistor divider with unity gain transistor (2 resistors, 1 NPN transistor). Similarly to the current source, the emitter voltage is a nearly fixed drop below the base voltage.
  • Trimmer (1 potentiometer, potentially up to 2 biasing resistors) if you’re okay with a bit of tuning.
  • Linear voltage regulators/references. Would probably work really well, but might be expensive depending on where you buy[3] and in this case requires a fairly small one (probably around 1V). The LM317 can be treated as a precision 1.25V drop, as long as the minimum load requirement is met.
  • Diode drops (1 diode). In the simulator, I was able to get the circuit to work with a ladder of diode drops for the control voltages (i.e., around 0.7, 1.4, and 2.1V). I’ve read that in practice this doesn’t work nearly as well.

By the way, the intended purpose is to trigger some D flip-flops to read serial data in an experimental line encoding I’ve conceived. It’s a variation of one I discussed way back, but the initial rising edge is followed by three bits of data before the mandatory fall. If it works, it could mean a simple output interface for PCs (e.g. via monitor or sound card) to devices that only understand data in terms of data, clock, and latch. What does this mean? You guessed it—semi-headless 74HC595 displays. (Okay, maybe not so much, but that’d at least be a good way to test it.)

This circuit is available on the Falstad simulator.

  1. [1] Veb may vary slightly depending on current, but is roughly 0.7V under normal circumstances.
  2. [2] Up to near the max collector voltage, in this case slightly lower than the emitter voltage.
  3. [3] LM317 is $3 at Radio Shack, but way cheaper online, especially in a TO-92 package.

No guarantees, but it worked in the simulator.

Today, figured out how to make a (possibly low-speed) transparent D latch out of an R-/S latch, plus a couple of logic gates, and an inverter. Each of these four things can be constructed from a 555 timer (or half of a 556). Alternatively, each of the gates can be replaced by three diodes[1] and a resistor, and the inverter by an NPN transistor and a resistor. Not pictured is the AC coupling[2] on the E input that would make this an edge-triggered flip-flop instead of a latch.

The significance of this is that a D flip-flop, a 1-bit static RAM and an important element of sequential logic, can be constructed very easily with stuff readily available from Radio Shack, which doesn’t stock logic ICs anymore but does carry 555s and 556s (as well as diodes, resistors, and transistors). Naturally, I have the best interests of the impatient experimenter in mind. :-)

  1. [1] With Schottky diodes you could probably get away with omitting the output diode.
  2. [2] In this case, an RC highpass is used, an inline capacitor of about 0.1µF followed by a 10kΩ pull-down resistor.

This circuit has not been tested. It might work. It might not. Who knows? All diodes should probably be Schottky.

I contrived a diode-transistor logic (DTL) circuit for a SR latch[1] with a CMOS push-pull output and a break-before-make mechanism to prevent simultaneous push and pull (shoot-through). I have no idea whether it actually works and there are probably easier ways to do it, but it was kinda fun.

The upper schematic lays out the concept in terms of OR gates with different inversions (clockwise from upper left: NOR, OR, AND, NAND). The output is fed back into the inputs through diode-resistor level shifts so that the one being fed into the high side is high when the output is high but low if the output is either low or off (high-impedance), and the one into the low side is low when the output is low, but high if the output is high or off. This feedback should prevent either output FET from turning on until the complement is turned off (or close to off).

The lower schematic is the upper schematic rendered in diode-transistor logic. The lower-left gate, a NAND, is implemented using the textbook DTL NAND with an NPN transistor. The NOR in the upper left is actually the same as the NAND, but with the diodes reversed and a PNP on the output. Note that in both cases the feedback diode-resistor shift is now part of the gate itself. The other two gates are just diode logic since OR (upper right) and AND (lower right) can be implemented without a transistor on the output.

This contrivance is for a power logic buffer; the intended supply voltage would be somewhere from 12 to 48 volts and the current capacity on the output MOSFETs would be at least a couple of amps. I haven’t tested the thing. Please don’t use it, except in test circumstances, unless you know what you’re doing.

  1. [1] Technically, an S AND NOT R latch.

I’ve been spending a lot of time thinking about op amps and comparators lately.

One of the common uses of an op amp is as a “unity gain” buffer, meaning that the output voltage is as close as possible to being the same as the input voltage. At a glance this might seem like a trivial thing, but it’s used to great advantage.

For example, a resistive voltage divider can be used to derive some fraction of a larger voltage by representing the ratio with resistors. Given a 9V supply, a divider over 100K and 47K would yield about 2.9V (9V * 47K/(100K+47K)). Unfortunately, this is of only limited use directly, since driving a load from the output causes that voltage to drop. This happens because the load itself acts as a resistor to ground in parallel with the divider, changing its resistance.

The divider does okay, though, feeding to a high-impedance input (i.e., one that doesn’t pull a lot of current). The inputs on an op amp fit that description, and its output is low-impedance (meaning that it can supply current without trouble). That’s a huge part of why op amps are useful. If you take the resistive divider’s output into the non-inverting (“+”) input of an op amp and the amp’s own output into the inverting (“-“) input, you get a unity gain buffer, an amplifier that outputs the same amplitude as the input (“unity gain” refers to the 1:1 ratio of input to output). The buffer continuously compares its output to the input. If the output is too high, it’s lowered; if too low, it’s raised.

In general, the op amp’s job is to perform an analog computation on its inputs that amounts to subtraction followed by multiplication. It subtracts the voltage of the inverting input from the voltage of the non-inverting input, then multiplies it by a factor called gain. By default, the gain is an arbitrarily high number called the open-loop gain of the amp. However, by feeding the output back into the inputs in different ways, it’s possible to fix the gain to a more useful value, such as 1 in the above scenario.[1]

Anyway, this ability to continuously adjust an output to a certain point reminded me of linear voltage regulators, like the 7805 and the LM317. I hypothesized that these 3-terminal regulators are basically heavy-duty op amps with a fixed voltage reference on one of the inputs. A little research confirmed this.

A linear voltage regulator is a voltage reference stuck to an op amp with high output current capability. Now you know—and knowing is half the battle.

[Note: The above image replaces a previous version that was less accurate.]

The data sheet for the fixed 7805 (and other 78xx) regulators suggested a circuit that allows the use of the regulator in an adjustable mode for voltages higher than the nominal voltage. Under normal circumstances, the regulator simply adjusts the output pin to be exactly 5V above the ground pin. In this mode, the ground pin is not tied to ground. Instead, the output and ground pin are placed across the high side of a resistive divider. The regulator fixes the voltage across the upper resistor to its face value. The lower resistor gets all of the current from the upper resistor, plus the garbage quiescent current from the machinery in the device. Multiplying this sum by the lower resistance yields, via Ohm’s law, the voltage across the lower resistor. The sum of that voltage and the regulated voltage is the output.

The data sheet for the LM317 shows a circuit essentially identical to the one described above with a few name changes. In fact, the ‘317, when used in the 7805’s nominal configuration, is itself a fixed 1.25V[2] regulator.

Knowing that these regulators are so alike, then, why should we ever choose ‘317 over 7805? The answer: ‘317 has a subtle difference that makes it far more suitable in its adjustable mode: The current out of its adjustment terminal is a couple of orders of magnitude smaller[3], enough smaller in fact that it could be disregarded in many cases when calculating Vout. This is especially useful in cases where the application doesn’t adjust the output voltage, but that requires a regulator for an awkward voltage (like the 13V programming voltage of a PIC). Using a 7805 in such an application might require a trimmer to fine-tune the output, while the ‘317 would probably be okay with a fixed-value resistor instead.

Pictured are the much simplified equivalent schematics, plus my derivation of how Vout is calculated. R2Iadj should be dominated by the rest of the expression.

  1. [1] Incidentally, a comparator is basically a specialized op amp that has been optimized to only output high or low (i.e. in the logical sense). It works as specified above, but boils the problem down to “is the non-inverting input greater than the inverting input?” yielding high if so and low if not. An op amp can be used as a comparator, but actual comparators do the job faster and better.
  2. [2] 1.25V is less arbitrary than you might think: It is the output of a silicon bandgap reference, which is designed to be steady and reliable in spite of temperature and environmental changes. Cool.
  3. [3] 7805 IQ is 5mA typ., LM317 Iadj is 50µA typ.