Using diodes for subtraction? - Page 1
Forum section: electronics / beginners

author: cellularmitosis
author_rank: Unknown
timestamp: June 04, 2014, 06:28:26 am
content: I am conditioning the signal from a temperature IC (MCP9701) in order to get the best resolution from the ADC I'm hooking it up to. This means subtracting an offset and then adding some gain.Currently I'm doing this with a bunch of op amps, but it sure is tempting to instead perform the subtraction by running it through a few diodes (each subtracting roughly 0.6v).Is diode subtraction considered a no-no for working with precision signals? I'm looking for feedback about how using a diode for subtraction is a bad idea because of X Y and Z...

author: AndyC_772
author_rank: Super Contributor
timestamp: June 04, 2014, 06:33:03 am
content: The forward voltage across a diode is not a constant, it's roughly an exponential function of the current flowing through the device. It also varies from diode to diode and with temperature.

author: katzohki
author_rank: Frequent Contributor
timestamp: June 04, 2014, 05:54:29 pm
content: You can do voltage "subtraction" in an analog way using a differential amplifier or an opamp:http://en.wikipedia.org/wiki/Differential_amplifier#Operational_amplifier_as_differential_amplifierBesides that, you could invert the reference voltage and send both into a "voltage summer" sort of opamp design. Better to just set it up as a difference amplifier I think. More info:http://www.fatih.edu.tr/~aliadam/EEE201A/EEE201opampsCircuit.pdfAnyway, you can do it using opamps better because you can feed one input a precise reference voltage. Not sure what you meant by "a bunch" of opamps.

author: jlmoon
author_rank: Unknown
timestamp: June 04, 2014, 06:10:29 pm
content: Quotenot to mention better temperature stability and linearity.

author: cellularmitosis
author_rank: Unknown
timestamp: June 04, 2014, 07:06:50 pm
content: Thanks for the feedback guys, that's about what I expected.Here's what I was originally planning on doing, using 3 op amps (basically a poor-man's instrumentation amp?).

author: cellularmitosis
author_rank: Unknown
timestamp: June 04, 2014, 07:10:04 pm
content: The interesting thing to me was that the diodes might actually work in this particular application, as I'm basically making a tiny little oven to keep a component (a vishay foil resistor) at exactly (well, +/- 0.1C is the goal) the same temperature, to create a "resistance standard" which I could potentially have calibrated, and then use that to calibrate my meters.So in this particular case, I don't actually care what specific temperature the PID loop settles on, I only care that it stays as stable and repeatable as possible.I think I'll use the op-amps, but its interesting to think that in this particular case, the diodes might be a useable alternative? I'm not sure which would drift more over time (in a constant temperature environment): op amp offset voltage, or diode voltage drop?

author: cellularmitosis
author_rank: Unknown
timestamp: June 04, 2014, 07:21:11 pm
content: (oops, there's a typo in that LTSpice setup. the 0C offset for the MCP9701 is 400mV, not 500mV)

author: cellularmitosis
author_rank: Unknown
timestamp: June 04, 2014, 07:37:52 pm
content: ah, actually I could eliminate the last op-amp by fiddling with the resistor ratios in the subtractor.http://reviseomatic.org/help/s-op-amp-advanced/Op%20Amp%20Difference.php

author: katzohki
author_rank: Frequent Contributor
timestamp: June 04, 2014, 07:48:34 pm
content: Yes you can pare it down to two opamps and I suspect that you could safely use just one op amp.Although I can't say that I know more about your application than I do, I would probably use a Voltage Reference for your "offset" rather than a voltage divider. If not, then you will probably want some decently precise resistors for R11 and R7 at least. And temperature stable as well.

author: Galaxyrise
author_rank: Frequent Contributor
timestamp: June 04, 2014, 08:09:15 pm
content: And all that just to feed another control loop... another opamp, right? You should be able to do the whole thing with just that one opamp. Exampleshereusing a thermistor in a resistive bridge to generate the measured and reference voltages and feed an opamp as a PI controller, but I think you can adapt it to use your IC instead.

author: ignator
author_rank: Regular Contributor
timestamp: June 04, 2014, 08:49:12 pm
content: Quote from: cellularmitosis onTodayat 02:10:04 PM>The interesting thing to me was that the diodes might actually work in this particular application, as I'm basically making a tiny little oven to keep a component (a vishay foil resistor) at exactly (well, +/- 0.1C is the goal) the same temperature, to create a "resistance standard" which I could potentially have calibrated, and then use that to calibrate my meters.So in this particular case, I don't actually care what specific temperature the PID loop settles on, I only care that it stays as stable and repeatable as possible.I think I'll use the op-amps, but its interesting to think that in this particular case, the diodes might be a useable alternative? I'm not sure which would drift more over time (in a constant temperature environment): op amp offset voltage, or diode voltage drop?It depends on where these diodes are kept relative to the temperature oven. Your device (MCP9701) uses a diode junction for temperature measurement, and has amplifier-linearizing circuits that convert the PN junction temperature coefficient to an analog voltage. I think you will just complicate the circuit by doing this (using diodes to drop voltage), and if you ever change the set point temperature, the diodes will cause more frustration with their calibration influences.

author: cellularmitosis
author_rank: Unknown
timestamp: June 04, 2014, 08:53:55 pm
content: Quote from: Galaxyrise on June 04, 2014, 08:09:15 pmThanks for the link, lots of interesting reading in that thread. Some circuits I had seen before and a few new ones.Actually, I wanted to try out digital control, so this would be driving the ADC pin on an ATTiny, which would run PID and then control a DAC (MCP4821) which would drive a constant-current op amp / TIP21 (as heater) / sense resistor setup. I wanted to keep it digital so that I could easily tweak and fool around with it over a serial line, rather than having to take it apart and desolder resistors, etc.The whole mess will be put in a mason jar. The inner temperature controlled environment will be a pair of circular PCB's sealing off a small section of PVC pipe, which will make a "jar within a jar" setup. The empty space around the PVC / PCB sandwich will be filled with styrofoam microbeads. I've had lots of fun designing it!I decided the whole project was practical as a fun exercise when I realized the $20 vishay foil resistors can be found used (salvaged?) on ebay for $4.

author: cellularmitosis
author_rank: Unknown
timestamp: June 04, 2014, 09:11:04 pm
content: Quote from: ignator on June 04, 2014, 08:49:12 pmInteresting.My plan is to try to keep the entire circuit within the temperature controlled environment, in hopes that it would reduce the temperature coefficient of the entire unit as a black box against the slowly changing temperature in my room.

author: IanB
author_rank: Super Contributor
timestamp: June 04, 2014, 09:13:05 pm
content: When using an ADC you may realize you can often get fractional bits of precision by sampling many times and averaging (dithering)? This could be simpler than various analog circuitry that is going to distort the signal on its way from the signal source to the ADC.

author: fcb
author_rank: Super Contributor
timestamp: June 04, 2014, 09:17:18 pm
content: If you mount the diode next to the MCP9701 then any temperature dependent Vforward changes won't matter, you needn't pull a constant current through the diode either, any non-linearities can be compensated through a LUT. If your application is just to maintain a set point, you might not even need an LUT.Vforward will be different on diodes from the same reel, probably not enough to worry about though.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 04, 2014, 09:30:19 pm
content: You can do this a whole hell of a lot easier -- use one amp, a series resistor from sensor to +in, a feedback resistor from out to -in, and resistors from +/-in to VCC/GND as needed to pull the output into the right voltage range.You can use textbook ideal circuits as a starting point, but chaining them together is, well... you know what it is, that's why you're askingTim

author: cellularmitosis
author_rank: Unknown
timestamp: June 04, 2014, 09:37:11 pm
content: Quote from: IanB on June 04, 2014, 09:13:05 pmThe first circuit I breadboarded used VCC (5V) as the VREF for the ATTiny, which meant that one LSB was about 0.25 degrees C. I was able to get the PID loop to mostly bounce around the setpoint by 1 LSB (+/- 0.25C). That's what started me down this path: the desire for finer resolution (which means either reducing VREF, or offset + gain, or both).But you raise an interesting point. e.g., if you consider the sequence of samples [5, 5, 5, 4, 4], instead of turning that into a 5, I should instead turn that into a 4.6, is that right?

author: IanB
author_rank: Super Contributor
timestamp: June 04, 2014, 09:47:11 pm
content: Quote from: cellularmitosis on June 04, 2014, 09:37:11 pmYes, but it is even easier to do in binary with a power of two sample count. For example, take 8 samples in succession [5, 5, 5, 4, 4, 5, 4, 5] and sum them up.In binary:5 = 1014 = 100sum(5,5,5,4,4,5,4,5) = 37 = 100101You can divide by 8 by shifting right three times, so the average is 100.101, which in decimal would be 4 + 0.5 + 0.125 = 4.625.If you are clever you can even do your PID calculations in fixed point arithmetic and not ever convert to floating point.

author: cellularmitosis
author_rank: Unknown
timestamp: June 04, 2014, 10:02:47 pm
content: Quote from: T3sl4co1l on June 04, 2014, 09:30:19 pmTim,Thanks for the idea! You are saying that I just need the right set of resistor values in something like this?

author: cellularmitosis
author_rank: Unknown
timestamp: June 04, 2014, 10:15:09 pm
content: Wow, a few minutes of guess-and-check lead to a decent solution, and then I realized I don't even need the resistors around the MCP9701! this is way simpler!Thanks Tim!

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 04, 2014, 10:30:03 pm
content: Yup!You can calculate the slope or gain (dVout / dVin) of the amp based on the R4 into R1 || R5 voltage divider. Don't forget that the input is attenuated by R6 into R2 || R3. Then, offset by following the voltage offsets around (if the R2-R3 divider has the same potential as R1-R5, then when R6 has no current flow, the output's at zero).Further, if you actually have a negative supply handy, you only need one bias resistor (up or down as needed).A good example and way-of-thinking about this:Suppose you have a current shunt. So, zero referenced, no offset, low impedance. But too low voltage. Say you want 0-5V from a 100mV shunt. So you need a gain of 50. So, from op-amp output, 49k to -in, 1k to GND. Shunt to +in via 1k resistor (match input resistances -- helps to match the offsets due to input bias current). If the amp has +/-1mV input offset, it's 50mV at the output, which kind of sucks (1% error). So, suppose we bias the input by 1mV, and bias the other by 0-2mV from a trimmer, so you can calibrate it to zero offset. From a 10V supply, you'd use a 10Meg resistor to +in to guarantee an offset of 0-2mV, then a trimpot spanning GND to supply (0-10V) with the wiper to a 5Meg resistor to -in (which has a Thevenin equivalent of a little under 1k, so twice the offset needs half the dropping resistor). Or since Megs are kind of sucky, you could run the trimpot as a divider (say, a 1k trimmer with 100k from supply = 0.1V) and use smaller values (100k from the top of the trimmer, and 50k from the trimmer wiper).Note that, in a case like this, you can approximate the voltage divider equation (R2 / R1+R2 and related) as linear (R2/R1) and parallel resistors as ignored (1k || 50k is barely less than 1k). Take advantage of whatever approximations you can, then fine tune it with real math (set up the full equations and tweak, or just play around in the simulator for the same effect).Tim

author: katzohki
author_rank: Frequent Contributor
timestamp: June 04, 2014, 10:30:30 pm
content: What a nice reduction in parts count!

author: IanB
author_rank: Super Contributor
timestamp: June 04, 2014, 10:30:45 pm
content: Also--the second one is better because it puts less load on the MCP9701. The maximum output current according to the data sheet is 100 µA [edit: corrected value], so you have to be careful about loading down its output with resistors to ground.

author: cellularmitosis
author_rank: Unknown
timestamp: June 04, 2014, 10:43:12 pm
content: Quote from: IanB on June 04, 2014, 10:30:45 pm10uA, whoa, good catch!

author: cellularmitosis
author_rank: Unknown
timestamp: June 04, 2014, 10:47:29 pm
content: Quote from: T3sl4co1l on June 04, 2014, 10:30:03 pmI'll be thinking about that one for a while

author: IanB
author_rank: Super Contributor
timestamp: June 04, 2014, 11:06:00 pm
content: Quote from: cellularmitosis on June 04, 2014, 10:43:12 pmActually I made a mistake, it is 100 µA. Always verify what people tell you

author: cellularmitosis
author_rank: Unknown
timestamp: June 04, 2014, 11:30:28 pm
content: Here's the other half of the circuit.The ATTiny will control a DAC (MCP4821) via SPI, which will control the current through a TIP21 (the heater).The current can be scaled up or down by replacing the 15k resistor, in case you want to use a smaller wall wart (which will only cost you a longer warm up time).One nice thing about the MCP4821 is that it has a 2x gain bit, which means you get double the resolution (0.5mV) for the 0-2.048V range, but you can still reach 4.096 (with 1mV resolution).I had a variation on this circuit breadboarded up last night, with the temperature IC and TIP122 wrapped together with electrical tape, and I was able to settle on roughly +/- 2 LSB temperature regulation (about +/- 0.5C).I'll post back later with my results after using the single op amp gain + offset conditioning!

author: Richard Crowley
author_rank: Super Contributor
timestamp: June 04, 2014, 11:34:07 pm
content: We don't know what the trade-off is for your project, but if you wanted to do a more "precision" offset with diodes, you could characterize them over the operating temperature range. It may cost no more than one more of the diodes to use as an "ambient temperature transducer", and some compensation code.

author: IanB
author_rank: Super Contributor
timestamp: June 05, 2014, 12:00:49 am
content: Quote from: cellularmitosis on June 04, 2014, 11:30:28 pmSince you're in experimental mode you might try using the op amp directly to control the temperature, without the micro? Apply the temperature set point to the (+) input of the amplifier, apply the measured temperature to the (-) input, and send the op amp output to the heater. Use appropriate resistors as you have been doing to set the gain and biasing in the system. I have a feeling you should be able to get temperature regulation stable within a fraction of a degree.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 05, 2014, 01:10:18 am
content: ^ Analog > digitalAlso, note you'll need some sort of compensation in there, whether you do it digitally (PID?) or analog (say, R+C across the error amp). Easy to tell if it's working: if the current consumption isn't bobbing up and down incessantly, it's probably stable. If you have a scope with a nice long sweep rate and persistence (one thing DSOs excel at), you can easily plot the transient response to see how well it's compensated (over/undershoot).Example:http://seventransistorlabs.com/Images/TCXO.pngNote the thermistor is in a bridge, so the ref doesn't actually matter (TL431). This didn't require exact temperature precision, so the resistors and thermistor were chosen "good enough". Though since < 1% thermistors are available, one can do just as well as with that temp sensor (assuming micropower isn't required, which would be a good reason to use such a part), using the published transfer curve of the thermistor to set operating point (replace the left arm of the bridge with the DAC output).Note the two primary heat-dissipating components are heatsinked together: the TIP32 heater itself, AND the 7805, through which all the current flows. This was actually built on a hunk of copper, those two devices being soldered down directly, as well as a piece of copper clad as prototyping area for the rest of the circuit.Tim

author: IanB
author_rank: Super Contributor
timestamp: June 05, 2014, 02:45:02 am
content: Quote from: T3sl4co1l on June 05, 2014, 01:10:18 amThis part, I think is quite important. Thermally bonding everything to a good, solid heat sink enhances the stability and disturbance rejection in the physical domain. The heat sink acts like a capacitor, absorbing and damping out high frequency content in the feedback loop and helping to filter out ambient temperature changes before they can reach the device being regulated.

author: cellularmitosis
author_rank: Unknown
timestamp: June 05, 2014, 04:41:22 am
content: Well, I breadboarded up the simplified circuit and it worked! though there is some bad overshoot (+6C), when it eventually settles down it is already better than +/- 0.1C.A problem I ran into was I think due to offset error of my LM358. It looks like there is a little over 1mV offset, which unfortunately means that even when the DAC is totally shut down, the TIP120 is still drawing about 40mA. Hrmm...

author: cellularmitosis
author_rank: Unknown
timestamp: June 05, 2014, 04:54:11 am
content: Quote from: T3sl4co1l on June 05, 2014, 01:10:18 amCool, that's very similar to what I was planning! I was thinking about using the two TO-220 packages (the TIP120 and the 7805) as "table legs" to suspend a heatsink just far enough over the PCB that I could clear a few DIP-8's below it, so that all of the chips could be in the same thermal environment.Here's a mock-up:

author: cellularmitosis
author_rank: Unknown
timestamp: June 05, 2014, 05:06:04 am
content: Quote from: cellularmitosis on June 05, 2014, 04:41:22 amHmm, now I wonder if this is due to a simplification I made in the TIP120 drive circuit. Instead of amplifying the Rsense voltage, I just divided the DAC voltage in order to reduce from two op amps to just one.However, I think this means the op amps are now operating much closer to their "noise floors", e.g. the offset error is a much bigger deal, because we are dealing with smaller signals.note: the actual circuit which I breadboarded used a 33k and 1k as the divider, so it divided the DAC signal by 34x.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 05, 2014, 10:58:03 am
content: Who needs shunts: why not use a massive resistor and toss that on / near the heatsink too?Heat is heat...BTW, thermal capacitance isn't the name of the game, stability is: I achieved a 30 second time constant, which means variations of shorter duration go right into the heatsink as normal. It's not an "brick wall" heatsink, so those variations will create ripple in its temperature. Which my circuit cannot possibly adjust for, because the feedback must be at least that slow.Ideally, one uses a very fast loop so the error is limited by the op-amp precision and thermistor noise even at relatively high frequencies (~1Hz drafts?). Working example: compare a standard temp-controlled soldering station, Hakko FX-888 or Weller WES-51 for instance, to one of the high-end integral sensor models (or Metcal, etc.).Same goes for power supplies -- compare a nice peppy flyback supply to a slow moving (voltage mode) forward converter: the two pole filter in the latter (typically with a cutoff of ~kHz!) limits loop bandwidth, so that stability (in terms of peak voltage transient / peak current transient) is limited by capacitance and ESR. Whereas the flyback can respond very quickly (cycle to cycle in some cases).Tim

author: nuno
author_rank: Frequent Contributor
timestamp: June 05, 2014, 10:10:43 pm
content: Quote from: cellularmitosis on June 04, 2014, 06:28:26 amI don't know which attiny you're using, but you can subtract an offset and add gain with a diferential amplifier, and at least some tinys have that.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 06, 2014, 03:39:39 am
content: Geez, bad enough to use the internal ADC, but the internal amp stuff too? Gag me with a spoon...Tim

author: nuno
author_rank: Frequent Contributor
timestamp: June 06, 2014, 10:52:51 am
content: Sorry, no spoon on handWhat's so bad about them? For this application?

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 06, 2014, 12:21:14 pm
content: Have you read the datasheet?

author: nuno
author_rank: Frequent Contributor
timestamp: June 06, 2014, 01:24:44 pm
content: Somewhere in the past I've read a few, yes. So the problems are...?

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 06, 2014, 11:32:48 pm
content: Don't know which ATtiny in question, so I'll pick one at random (probably typical of the series),http://www.atmel.com/images/doc2535.pdfPage 119:Bandgap reference: 1.0-1.2V10% -- a plain diode is almost as good -- whereas even a $0.06 TL431 is 0.5 to 2.5% depending on grade.Analog comparator: max 40mV offset, 750ns delay for "slight overdrive" (whatever the hell that means!)An LM393 is more like 200ns and guaranteed at 5 or 10mV overdrive (whichever it is; the important part being, they actually say). It'll draw slightly more current (Fig. 19-60 on p.153 shows ~0.1mA varying with temp and supply), but there are low power versions which compare favorably.Also note the footnote, none of it is real: based on simulation only. So, if you have a critical application that depends on those parameters, uh...Next page: ADC. About 2 LSBs, but no max given. Among real ADCs that provide similar specs, the max might be anywhere from 4 to 10 LSBs. Out of 10 bits, that's pretty awful (8 LSBs is 3 whole bit positions = only 7 bits you can guarantee). Of course, they don't even give a max, so you technically can't trust any ADC sample at all...I've heard the BOD and POR suck too (malfunctioning for slow power rise/fall), so you should have a power monitor / reset generator to handle that too...So in summary, veeeery little concrete info about how well anything inside the chip actually works. They're probably shy because they're embarassed about it...Tim

author: nuno
author_rank: Frequent Contributor
timestamp: June 07, 2014, 02:40:42 am
content: Indeed those from the latest generation look crappier. You mean PICs or so are better? (never used a PIC for more than an LED blink) An older attiny26 looks better on the ADC/bandgap. The vcomp is irrelevant for the OP's application, and the bandgap's initial tolerance is bad but a calibrated (tiny26) unit is not worse than a 0.5% TL431 and still cheaper. For a one-off application like this, with the diff amp (whose offset can be nulled in sw and the gain calibrated - I usually just calibrate all in a single step) "raw" resolutions better than 0.01ºC are probably achievable. Just another suggestion.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 07, 2014, 01:31:38 pm
content: Actually, it is quite a bit worse: Fig. 19-49, p.146, temp and VCC drift (I assume typical, simulated, so who knows how representative it is). +/-4% over the full range.At nominal 5V and "normal temperatures" (say 0-60C) it looks pretty flat, but again, there are lots of gimmicks you can do that are about as stable if you calibrate them. The point is not to need a calibration at all.There's no plot for Vos, so no way to tell how it changes, which I'm sure it does. You're just as well off using one or two discrete transistors to do the comparison.I haven't looked at PICs, and don't particularly care to. The architecture is ancient and clunky. Yes there's a C compiler for it, but...why?I recall looking at the XMEGA series and seeing better numbers, but I haven't heard if they suffer the same systemic maladies (like the POR/BOD and other clunkiness).MSP430s are well received and well specified, though if all you need is an ATtiny, it's a bit overkill.It's probably just as well true that, if you think you need an ATtiny, what you really need is a couple logic gates and a discrete amp or something. There's this wonderful world called "analog" that people are so quick to forget, despite living within it.Tim

author: nuno
author_rank: Frequent Contributor
timestamp: June 07, 2014, 03:08:10 pm
content: Quote from: T3sl4co1lA lot worse, total crap, what were they thinking. The older attiny26 has typical < +/-0.09% over temp and Vcc (once I've tested one unit for a one-off project and it did comply to this).I did an LED blink and then put it on the drawer, dinosaur architecture, although the dsPIC looks much better. Never tried an xmega. Recently tried a PSoC and loved it (lots of analog stuff inside, and totally free dev tools), but I haven't gone through detailed electrical specs yet.Tried to install TI's CodeComposer in 2 machines (one older, one a top of the line) without success (just an informative "error installing" message) . Software from any other vendor installs and works. Gave up completely on MSP430 and any CodeComposer based products from TI. I don't think the chips are that interesting either, I found it better jump strait to an ARM.QuoteYes there is, although not as flexible, harder to grasp, much more components and solder, .... I'm actually a big fan of analog but lack the background (EE is not my area anyways); one cannot not be impressed with the likes of Widlar, Pease or Williams.For a one off proj like this a (decent) tiny seems to have all the machinery for the signal acquisition, trying that implementation can be a good learning exercise. A PSoC 4 would be a good alternative, there's a cheap (some 4 or 5 USD) prototyping board with usb interface. There are ampops and dacs and vcomps and other stuff inside the chip.