Op Amp Design Techniques

Analog Adventures

Op amps can play useful roles in circuit designs linking the real analog world to microcontrollers. Stuart shares techniques for using op amps and related devices like comparators to optimize your designs and improve precision.

By Stuart Ball

Connecting the real world to your microcontroller circuit is what makes it useful for something more than blinking an LED. This is a broad topic. And several years ago, I wrote a book specifically about this: Analog Interfacing to Embedded Microprocessor Systems . What I want to do here is describe a few techniques that may save you some time and grief when connecting things to your own designs.

Op amp Voltage References

An op amp (Figure 1) is an amplifier that has an inverting input, a noninverting input and an output. The voltage difference between the noninverting input and inverting input is amplified by a high internal gain and presented to the output. Resistors or other components are connected between the output and (usually) the inverting input to produce a feedback circuit that controls the gain of the completed circuit.

Figure 1
Standard inverting amplifier with reference offset voltage. The reference is needed to level-shift the -2.5 V to 2.5 V input up to the 0 V to 5 V input needed by a microcontroller.

Generally, the rule of thumb is that, as long as the op amp is properly connected—not saturated, no floating inputs—the inverting and noninverting inputs will be at the same voltage. This is because the negative feedback loop will cause the op amp to drive the inverting input to a voltage that matches the noninverting input. If the op amp can’t drive the output so that the inputs are equal, the output will saturate in either the positive or negative direction.

The circuit in Figure 1 is a commonly used inverting amplifier circuit, and it is what you might use to convert a signal that swings from -2.5 V to 2.5 V to the 0 to 5 V input of a microcontroller’s analog-to-digital (ADC) converter. If your microcontroller had an ADC that could only handle inputs of 0 to 3.3 V or 0 to 2.5 V, the same principles would apply, but the component values would be different. The op amp pinout shown is typical of one half of an 8-pin, dual op amp.

The input signal might be the output of a device with a -2.5 V to 2.5 V range. Or it might just be a capacitor-coupled AC signal such as an audio waveform. Whatever the source, the -2.5 V to 2.5 V range is outside the range of your ADC input, so you have to shift the level so that it is within the range of the ADC.

The circuit shown is a typical inverting amplifier, which means that the output is 180 degrees out of phase with the input. When the input is at its maximum voltage, the output is at its minimum, and vice-versa. The gain of the amplifier is defined as RF/RI, which is a gain of 1 for this circuit since both resistors have the same value. For other applications you might need gain greater or less than one.

If you work through the math as shown in Figure 1, you can see that the output equation is (2REF – Input) or 2× the reference voltage (1.25 V) minus the input voltage (-2.5 V to
2.5 V). So, when the input is 2.5 V, the output is (1.25 × 2) – 2.5, or 0 V. When the input is -2.5 V, the output is (1.25 × 2) – (-2.5), or  5 V. So, the input is inverted and translated up 2.5 V to match the ADC input requirements at the op amp output.

Double Trouble

Now the potential problem: While the input voltage is multiplied by 1 (and level-shifted), the reference voltage is multiplied by 2. So, any noise or ripple on the reference voltage will show up doubled on the output. A 10 mV ripple signal will be 20 mV at the ADC input and will be combined with the input signal you are trying to measure.
A 50 mV DC error in the reference will translate to a 100 mV constant offset at the output.

Figure 2
A voltage divider provides a simple voltage reference but is subject to variation from ripple on the supply voltage, and the normal variation in the supply voltage. The supply voltage can vary with temperature, part tolerance and other factors.

Suppose that the reference voltage is generated as shown in Figure 2, with a pair of resistors to divide the 5 V supply down to 1.25 V. Using 1% resistors provides a reference voltage that is within about 01.7% of the intended value—provided the 5 V supply is exactly 5 V. However, this 5 V value can vary with temperature, with the input voltage and with the tolerance of the reference voltage inside the regulator circuit. The values of the resistors can also drift with temperature, although this effect is negligible in many applications.

In addition to the variation in the 5 V supply DC voltage, any AC signal on the
5 V supply will be transmitted to the op amp reference and will be multiplied by two at the op amp output. . …

Read the full article in the July 336 issue of Circuit Cellar

Don’t miss out on upcoming issues of Circuit Cellar. Subscribe today!

Note: We’ve made the October 2017 issue of Circuit Cellar available as a free sample issue. In it, you’ll find a rich variety of the kinds of articles and information that exemplify a typical issue of the current magazine.

Component Tolerance

Accuracy Unmasked

We take for granted sometimes that the tolerances of our electronic components fit the needs of our designs. In this article, Robert takes a deep look into the subject of tolerances, using the simple resistor as an example. He goes through the math to help you better understand accuracy and drift along with other factors.

By Robert Lacoste

One of the last projects I worked on with my colleagues was a kind of high-precision current meter. It turned out to be far more difficult than anticipated, even with our combined experience totaling almost 100 years. Maybe this has happened with your projects too: You discover that, even when you’re not looking for top performance out of your electronic components, the accuracy and stability of those components can be pernicious. My topic this month is examining component tolerances. And, for simplicity, I will focus on the simplest possible electronic device: a resistor.

FIGURE 1 A very simple voltage divider. With these values, Uout will be 1 V with Uin=100 V

Let’s start with a basic application. Imagine that you have to design a voltage divider with a ratio of 1/100 (Figure 1). I will assume that the source impedance is very low and that the load connected on the output draws no current at all. With those parameters the calculations are very easy. You just need to know Ohm’s Law. Because the resistors are in series, the current circulating through the two resistors is:

Similarly, the output voltage is:

Given that the current I is the same in both equations, we get:

This circuit is indeed a voltage divider, with a ratio of R2/(R1+R2). We want a ratio of 1/100, so one resistor could be fixed arbitrarily and the second easily calculated. For example: R1=9,900 Ω and R2=100 Ω will do the job as:

Of course, you can easily simulate such a circuit with any SPICE-based circuit simulator if you wish. I personally used Proteus from Labcenter to draw and simulate the small schematic provided on Figure 1, and the output voltage is 1 V with 100 V applied on the input, as expected. As usual, I encourage you to reproduce these small examples with your preferred simulator: for example the free LT-Spice.

Now let’s talk about accuracy. You want your divider to be as precise as possible and therefore you want to buy reasonably accurate resistors. But what if your budget is constrained? Will you use a high accuracy resistor for R1 (9,900 Ω)? Or for R2 (100 Ω)? Or for both? The good answer is both. In that case, a 1% error on either R1 or R2 gives close to a 1% error of the output voltage, as shown in Figure 2. Even if R1 has a stranger value than R2—9,900 Ω vs. 100 Ω—their accuracy is just as critical.

Figure 2
A 1% error either on the top or bottom resistors will induce a roughly 1% error on the output. That would not be the case for other division ratios.

Maybe you think this is too obvious? In that case I will give you another exercise: What happens with a divide-by-2 circuit using two resistors of the same value? Do the calculation or simulate it and you will find that both resistors have still the same impact on accuracy. But now a 1% error on one of the resistors has only a 0.5% impact on the output voltage. That means you could buy slightly less expensive resistors for the same overall precision! In fact, the higher the division ratio, the higher is the impact of each resistor on the overall accuracy.

E Series Resistors

Let’s go back to the 1/100 divider example. If you want to build it and look for a
9,900-Ω resistor, you will have some difficulties because nobody sells them.. …

Read the full article in the April 333 issue of Circuit Cellar

Don’t miss out on upcoming issues of Circuit Cellar. Subscribe today!
Note: We’ve made the October 2017 issue of Circuit Cellar available as a free sample issue. In it, you’ll find a rich variety of the kinds of articles and information that exemplify a typical issue of the current magazine.

PCI Switching Solutions

Pickering
Pickering Interfaces expanded its range of PCI switching solutions with the introduction of seven new PCI cards and the expansion of an eighth card. The expansion includes programmable and precision resistors, general-purpose relays, high-density matrices, and multiplexers.

The 50-293 PCI programmable resistor and relay card offers two or four programmable resistor channels. An optional eight single pole, double throw (SPDT) relays can be used for general-purpose switching. Each resistor can be programmed with resistance calls that set the module’s resistance to a ±1% resolution accuracy and the ability to read back the resistance setting to 0.3%. Depending on the version, the resolution is 0.25 to 2 Ω and the resistance is up to 131 kΩ.

The expanded 50-297 PCI precision resistor card family increases the versions offered from six to 42. Each version provides a choice of the number of resistor channels, the resistance range, and the resistance setting resolution. Depending on the version, the resolution is from 0.125 to 2 Ω and the resistor counts from three to 18. Resistor values up to 1.51 MΩ can be simulated and accuracy is ±0.2% resolution.

Two PCI general-purpose 2-A relay cards were also introduced. Model 50-131 provides 16 or 26 single pole, double throw (SPDT) relays. Model 50-132 provides 16, 32, or 39 SPST relays, each rated at 2 A and featuring up to 60-W hot switch power.

Pickering’s PCI 2-A 1-pole high-density matrix solutions include three models. The 50-527 is a 32 × 2, one-pole matrix; the 50-528 offers 32 × 4 or 16 × 4 configurations; and the 50-529 offers 16 × 8 and 8 × 8 configurations.

The 50-635 PCI low-cost electromechanical relay (EMR) multiplexer (MUX) system has a variety of different configurations ranging from a 64:1 single-pole MUX to a quad 8:1 two-pole MUX. All the PCI relay cards use high-quality EMRs and standard D-type connectors.

Contact Pickering Interfaces for pricing.

Pickering Interfaces, Ltd.
www.pickeringtest.com

Traveling With a “Portable Workspace”

As a freelance engineer, Raul Alvarez spends a lot of time on the go. He says the last four or five years he has been traveling due to work and family reasons, therefore he never stays in one place long enough to set up a proper workspace. “Whenever I need to move again, I just pack whatever I can: boards, modules, components, cables, and so forth, and then I’m good to go,” he explains.

Raul_Alvarez_Workspace _Photo_1

Alvarez sits at his “current” workstation.

He continued by saying:

In my case, there’s not much of a workspace to show because my workspace is whichever desk I have at hand in a given location. My tools are all the tools that I can fit into my traveling backpack, along with my software tools that are installed in my laptop.

Because in my personal projects I mostly work with microcontroller boards, modular components, and firmware, until now I think it didn’t bother me not having more fancy (and useful) tools such as a bench oscilloscope, a logic analyzer, or a spectrum analyzer. I just try to work with whatever I have at hand because, well, I don’t have much choice.

Given my circumstances, probably the most useful tools I have for debugging embedded hardware and firmware are a good-old UART port, a multimeter, and a bunch of LEDs. For the UART interface I use a Future Technology Devices International FT232-based UART-to-USB interface board and Tera Term serial terminal software.

Currently, I’m working mostly with Microchip Technology PIC and ARM microcontrollers. So for my PIC projects my tiny Microchip Technology PICkit 3 Programmer/Debugger usually saves the day.

Regarding ARM, I generally use some of the new low-cost ARM development boards that include programming/debugging interfaces. I carry an LPC1769 LPCXpresso board, an mbed board, three STMicroelectronics Discovery boards (Cortex-M0, Cortex-M3, and Cortex-M4), my STMicroelectronics STM32 Primer2, three Texas Instruments LaunchPads (the MSP430, the Piccolo, and the Stellaris), and the following Linux boards: two BeagleBoard.org BeagleBones (the gray one and a BeagleBone Black), a Cubieboard, an Odroid-X2, and a Raspberry Pi Model B.

Additionally, I always carry an Arduino UNO, a Digilent chipKIT Max 32 Arduino-compatible board (which I mostly use with MPLAB X IDE and “regular” C language), and a self-made Parallax Propeller microcontroller board. I also have a Wi-Fi 3G TP-LINK TL-WR703N mini router flashed   with OpenWRT that enables me to experiment with Wi-Fi and Ethernet and to tinker with their embedded Linux environment. It also provides me Internet access with the use of a 3G modem.

Raul_Alvarez_Workspace _Photo_2

Not a bad set up for someone on the go. Alvarez’s “portable workstation” includes ICs, resistors, and capacitors, among other things. He says his most useful tools are a UART port, a multimeter, and some LEDs.

In three or four small boxes I carry a lot of sensors, modules, ICs, resistors, capacitors, crystals, jumper cables, breadboard strips, and some DC-DC converter/regulator boards for supplying power to my circuits. I also carry a small video camera for shooting my video tutorials, which I publish from time to time at my website (www.raulalvarez.net). I have installed in my laptop TechSmith’s Camtasia for screen capture and Sony Vegas for editing the final video and audio.

Some IDEs that I have currently installed in my laptop are: LPCXpresso, Texas Instruments’s Code Composer Studio, IAR EW for Renesas RL78 and 8051, Ride7, Keil uVision for ARM, MPLAB X, and the Arduino IDE, among others. For PC coding I have installed Eclipse, MS Visual Studio, GNAT Programming Studio (I like to tinker with Ada from time to time), QT Creator, Python IDLE, MATLAB, and Octave. For schematics and PCB design I mostly use CadSoft’s EAGLE, ExpressPCB, DesignSpark PCB, and sometimes KiCad.

Traveling with my portable rig isn’t particularly pleasant for me. I always get delayed at security and customs checkpoints in airports. I get questioned a lot especially about my circuit boards and prototypes and I almost always have to buy a new set of screwdrivers after arriving at my destination. Luckily for me, my nomad lifestyle is about to come to an end soon and finally I will be able to settle down in my hometown in Cochabamba, Bolivia. The first two things I’m planning to do are to buy a really big workbench and a decent digital oscilloscope.

Alvarez’s article “The Home Energy Gateway: Remotely Control and Monitor Household Devices” appeared in Circuit Cellar’s February issue. For more information about Alvarez, visit his website or follow him on Twitter @RaulAlvarezT.