### Author Topic: Using diodes for subtraction?  (Read 10153 times)

0 Members and 1 Guest are viewing this topic.

#### cellularmitosis

• Supporter
• Posts: 1042
• Country:
##### Using diodes for subtraction?
« on: June 04, 2014, 04:28:26 pm »
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...
LTZs: KX FX MX CX PX Frank A9 QX

#### AndyC_772

• Super Contributor
• Posts: 3285
• Country:
##### Re: Using diodes for subtraction?
« Reply #1 on: June 04, 2014, 04:33:03 pm »
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.

#### katzohki

• Frequent Contributor
• Posts: 354
• Country:
##### Re: Using diodes for subtraction?
« Reply #2 on: June 05, 2014, 03:54:29 am »
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_amplifier

Besides 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:

Anyway, 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.

#### jlmoon

• Supporter
• Posts: 579
• Country:
• If you fail the first time, keep trying!
##### Re: Using diodes for subtraction?
« Reply #3 on: June 05, 2014, 04:10:29 am »
Quote
Anyway, 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.

not to mention better temperature stability and linearity.
Recharged Volt-Nut

#### cellularmitosis

• Supporter
• Posts: 1042
• Country:
##### Re: Using diodes for subtraction?
« Reply #4 on: June 05, 2014, 05:06:50 am »
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?).
LTZs: KX FX MX CX PX Frank A9 QX

#### cellularmitosis

• Supporter
• Posts: 1042
• Country:
##### Re: Using diodes for subtraction?
« Reply #5 on: June 05, 2014, 05:10:04 am »
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?
LTZs: KX FX MX CX PX Frank A9 QX

#### cellularmitosis

• Supporter
• Posts: 1042
• Country:
##### Re: Using diodes for subtraction?
« Reply #6 on: June 05, 2014, 05:21:11 am »
(oops, there's a typo in that LTSpice setup.  the 0C offset for the MCP9701 is 400mV, not 500mV)
LTZs: KX FX MX CX PX Frank A9 QX

#### cellularmitosis

• Supporter
• Posts: 1042
• Country:
##### Re: Using diodes for subtraction?
« Reply #7 on: June 05, 2014, 05:37:52 am »
ah, actually I could eliminate the last op-amp by fiddling with the resistor ratios in the subtractor.

LTZs: KX FX MX CX PX Frank A9 QX

#### katzohki

• Frequent Contributor
• Posts: 354
• Country:
##### Re: Using diodes for subtraction?
« Reply #8 on: June 05, 2014, 05:48:34 am »
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.

#### Galaxyrise

• Frequent Contributor
• Posts: 526
• Country:
##### Re: Using diodes for subtraction?
« Reply #9 on: June 05, 2014, 06:09:15 am »
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.  Examples here using 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.
I am but an egg

#### ignator

• Regular Contributor
• Posts: 203
• Country:
##### Re: Using diodes for subtraction?
« Reply #10 on: June 05, 2014, 06:49:12 am »
Quote from: cellularmitosis on Today at 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.

#### cellularmitosis

• Supporter
• Posts: 1042
• Country:
##### Re: Using diodes for subtraction?
« Reply #11 on: June 05, 2014, 06:53:55 am »
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.  Examples here using 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.

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.
« Last Edit: June 05, 2014, 07:23:28 am by cellularmitosis »
LTZs: KX FX MX CX PX Frank A9 QX

#### cellularmitosis

• Supporter
• Posts: 1042
• Country:
##### Re: Using diodes for subtraction?
« Reply #12 on: June 05, 2014, 07:11:04 am »
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.

Interesting.

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.

LTZs: KX FX MX CX PX Frank A9 QX

#### IanB

• Super Contributor
• Posts: 9255
• Country:
##### Re: Using diodes for subtraction?
« Reply #13 on: June 05, 2014, 07:13:05 am »
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.
I'm not an EE--what am I doing here?

#### fcb

• Super Contributor
• Posts: 1246
• Country:
##### Re: Using diodes for subtraction?
« Reply #14 on: June 05, 2014, 07:17:18 am »
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.

#### T3sl4co1l

• Super Contributor
• Posts: 12146
• Country:
• Expert, Analog Electronics, PCB Layout, EMC
##### Re: Using diodes for subtraction?
« Reply #15 on: June 05, 2014, 07:30:19 am »
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 asking

Tim
Seven Transistor Labs, LLC
Electronic Design, from Concept to Layout.
Need engineering assistance? Drop me a message!

#### cellularmitosis

• Supporter
• Posts: 1042
• Country:
##### Re: Using diodes for subtraction?
« Reply #16 on: June 05, 2014, 07:37:11 am »
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.

The 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?
LTZs: KX FX MX CX PX Frank A9 QX

#### IanB

• Super Contributor
• Posts: 9255
• Country:
##### Re: Using diodes for subtraction?
« Reply #17 on: June 05, 2014, 07:47:11 am »
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?

Yes, 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 = 101
4 = 100

sum(5,5,5,4,4,5,4,5) = 37 = 100101

You 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.
« Last Edit: June 05, 2014, 07:50:02 am by IanB »
I'm not an EE--what am I doing here?

#### cellularmitosis

• Supporter
• Posts: 1042
• Country:
##### Re: Using diodes for subtraction?
« Reply #18 on: June 05, 2014, 08:02:47 am »
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 asking

Tim

Tim,

Thanks for the idea!  You are saying that I just need the right set of resistor values in something like this?

LTZs: KX FX MX CX PX Frank A9 QX

#### cellularmitosis

• Supporter
• Posts: 1042
• Country:
##### Re: Using diodes for subtraction?
« Reply #19 on: June 05, 2014, 08:15:09 am »
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!
LTZs: KX FX MX CX PX Frank A9 QX

#### T3sl4co1l

• Super Contributor
• Posts: 12146
• Country:
• Expert, Analog Electronics, PCB Layout, EMC
##### Re: Using diodes for subtraction?
« Reply #20 on: June 05, 2014, 08:30:03 am »
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).

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
« Last Edit: June 05, 2014, 08:41:25 am by T3sl4co1l »
Seven Transistor Labs, LLC
Electronic Design, from Concept to Layout.
Need engineering assistance? Drop me a message!

The following users thanked this post: mycroft

#### katzohki

• Frequent Contributor
• Posts: 354
• Country:
##### Re: Using diodes for subtraction?
« Reply #21 on: June 05, 2014, 08:30:30 am »
What a nice reduction in parts count!

#### IanB

• Super Contributor
• Posts: 9255
• Country:
##### Re: Using diodes for subtraction?
« Reply #22 on: June 05, 2014, 08:30:45 am »
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.
« Last Edit: June 05, 2014, 09:04:43 am by IanB »
I'm not an EE--what am I doing here?

#### cellularmitosis

• Supporter
• Posts: 1042
• Country:
##### Re: Using diodes for subtraction?
« Reply #23 on: June 05, 2014, 08:43:12 am »
Also--the second one is better because it puts less load on the MCP9701. The maximum output current according to the data sheet is 10 µA, so you have to be careful about loading down its output with resistors to ground.

10uA, whoa, good catch!
LTZs: KX FX MX CX PX Frank A9 QX

#### cellularmitosis

• Supporter
• Posts: 1042
• Country:
##### Re: Using diodes for subtraction?
« Reply #24 on: June 05, 2014, 08:47:29 am »