# 1/x function with op amps or multiplier or something else...

Started by April 15, 2016
```Hello,

I'm trying to figure out the best way to go about making a -1/x function in hardware. From googling around I see 2 methods,

1. Inverting log -> Anti-log
2. OpAmp with multiplier in the feedback loop

I have +/-5V rails available, and my input is from 0.4V to 2V (which should give me an output of (-2.5 to -0.5). All DC values.

Can anyone point me in the right direction here, I'm trying to do this with as few parts (no microcontroller) and as painlessly as possible, it doesn't have to be very accurate (2-5% error it ok).

Much Thanks!

```
```Use a diode with exponential current vs voltage. Input a current to the diode and measure the voltage to get a log function. Then a derivative of ln(x) = 1/x
```
```On Thu, 14 Apr 2016 20:44:56 -0700, omnilobe wrote:

> Use a diode with exponential current vs voltage. Input a current to the
> diode and measure the voltage to get a log function. Then a derivative
> of ln(x) = 1/x

But how do you take the derivative of ln(x)?

--
www.wescottdesign.com
```
```On Thu, 14 Apr 2016 20:18:25 -0700, Fibo wrote:

> Hello,
>
> I'm trying to figure out the best way to go about making a -1/x function
> in hardware. From googling around I see 2 methods,
>
> 1. Inverting log -> Anti-log 2. OpAmp with multiplier in the feedback
> loop
>
> I have +/-5V rails available, and my input is from 0.4V to 2V (which
> should give me an output of (-2.5 to -0.5). All DC values.
>
> Can anyone point me in the right direction here, I'm trying to do this
> with as few parts (no microcontroller) and as painlessly as possible, it
> doesn't have to be very accurate (2-5% error it ok).
>
> Much Thanks!

For a production system that has to work at all temperatures over all
possible part variations, a microprocessor may be the most painless thing
of all.

Either of your proposed methods should work.  Beware of temperature
variations.  Multiplier circuits are compensated.

--
www.wescottdesign.com
```
```On Thu, 14 Apr 2016 23:24:17 -0500, Tim Wescott wrote:

> On Thu, 14 Apr 2016 20:18:25 -0700, Fibo wrote:
>
>> Hello,
>>
>> I'm trying to figure out the best way to go about making a -1/x
>> function in hardware. From googling around I see 2 methods,
>>
>> 1. Inverting log -> Anti-log 2. OpAmp with multiplier in the feedback
>> loop
>>
>> I have +/-5V rails available, and my input is from 0.4V to 2V (which
>> should give me an output of (-2.5 to -0.5). All DC values.
>>
>> Can anyone point me in the right direction here, I'm trying to do this
>> with as few parts (no microcontroller) and as painlessly as possible,
>> it doesn't have to be very accurate (2-5% error it ok).
>>
>> Much Thanks!
>
> For a production system that has to work at all temperatures over all
> possible part variations, a microprocessor may be the most painless
> thing of all.
>
> Either of your proposed methods should work.  Beware of temperature
> variations.  Multiplier circuits are compensated.

Oh -- forgot to mention.  If you feel compelled to roll your own with
diodes or whatnot, a transistor with the base shorted to the emitter
works better than a diode -- I dunno why, and I don't have a lot of
experience, but it's been mentioned to me here before and my own
(limited) experience seems to bear it out.

--
www.wescottdesign.com
```
```On Thursday, April 14, 2016 at 8:18:30 PM UTC-7, Fibo wrote:
> Hello,
>
> I'm trying to figure out the best way to go about making a -1/x function in hardware. From googling around I see 2 methods,
>
> 1. Inverting log -> Anti-log
> 2. OpAmp with multiplier in the feedback loop
>
> I have +/-5V rails available, and my input is from 0.4V to 2V

For a multiplier, one possibility is a variable duty cycle chopper.
Start with a '555 with current source pullup (just a grounded-base PNP transisor
with emitter resistor to +5) to make a sawtooth ('555 powered from GND and  -5V, this
makes a 1.67 Vpp triangle).   Attenuate the input signal, 'X', to the {0, 1V} range and feed
to a comparator, and use the comparator's open-collector output to chop (shunt
to ground) your other signal, 'Y'.

After a bit of low-pass filtering, the chopped signal has a value of X * Y /1.67...

I'd level-translate the triangle with a blocking capacitor and ground-clamp
diode, but there's other options.

This all assumes that your 'X' input, and your 'Y' output signals can be much
slower than a manageable sawtooth generator.  Under 1 kHz would work fine; over
1 MHz, means you'd be better off with something else.
```
```On 15.4.16 07:52, Tim Wescott wrote:
> On Thu, 14 Apr 2016 23:24:17 -0500, Tim Wescott wrote:
>
>> On Thu, 14 Apr 2016 20:18:25 -0700, Fibo wrote:
>>
>>> Hello,
>>>
>>> I'm trying to figure out the best way to go about making a -1/x
>>> function in hardware. From googling around I see 2 methods,
>>>
>>> 1. Inverting log -> Anti-log 2. OpAmp with multiplier in the feedback
>>> loop
>>>
>>> I have +/-5V rails available, and my input is from 0.4V to 2V (which
>>> should give me an output of (-2.5 to -0.5). All DC values.
>>>
>>> Can anyone point me in the right direction here, I'm trying to do this
>>> with as few parts (no microcontroller) and as painlessly as possible,
>>> it doesn't have to be very accurate (2-5% error it ok).
>>>
>>> Much Thanks!
>>
>> For a production system that has to work at all temperatures over all
>> possible part variations, a microprocessor may be the most painless
>> thing of all.
>>
>> Either of your proposed methods should work.  Beware of temperature
>> variations.  Multiplier circuits are compensated.
>
> Oh -- forgot to mention.  If you feel compelled to roll your own with
> diodes or whatnot, a transistor with the base shorted to the emitter
> works better than a diode -- I dunno why, and I don't have a lot of
> experience, but it's been mentioned to me here before and my own
> (limited) experience seems to bear it out.

A transdiode is a transistor with base shorted to the collector, not
emitter. You'll get a diode even with the emitter connection, but with
worse performance.

--

-TV

```
```On 04/15/2016 05:45 AM, Tauno Voipio wrote:
> On 15.4.16 07:52, Tim Wescott wrote:
>> On Thu, 14 Apr 2016 23:24:17 -0500, Tim Wescott wrote:
>>
>>> On Thu, 14 Apr 2016 20:18:25 -0700, Fibo wrote:
>>>
>>>> Hello,
>>>>
>>>> I'm trying to figure out the best way to go about making a -1/x
>>>> function in hardware. From googling around I see 2 methods,
>>>>
>>>> 1. Inverting log -> Anti-log 2. OpAmp with multiplier in the feedback
>>>> loop
>>>>
>>>> I have +/-5V rails available, and my input is from 0.4V to 2V (which
>>>> should give me an output of (-2.5 to -0.5). All DC values.
>>>>
>>>> Can anyone point me in the right direction here, I'm trying to do this
>>>> with as few parts (no microcontroller) and as painlessly as possible,
>>>> it doesn't have to be very accurate (2-5% error it ok).
>>>>
>>>> Much Thanks!
>>>
>>> For a production system that has to work at all temperatures over all
>>> possible part variations, a microprocessor may be the most painless
>>> thing of all.
>>>
>>> Either of your proposed methods should work.  Beware of temperature
>>> variations.  Multiplier circuits are compensated.
>>
>> Oh -- forgot to mention.  If you feel compelled to roll your own with
>> diodes or whatnot, a transistor with the base shorted to the emitter
>> works better than a diode -- I dunno why, and I don't have a lot of
>> experience, but it's been mentioned to me here before and my own
>> (limited) experience seems to bear it out.
>
>
> A transdiode is a transistor with base shorted to the collector, not
> emitter. You'll get a diode even with the emitter connection, but with
> worse performance.
>

A diode-connected transistor is actually the world's simplest feedback
amplifier.  V_CE adjusts itself to be exactly what V_BE has to be in
order to draw the exact amount of collector current applied.  That's why
they're such accurate logging devices.

They work great at low frequency and decent current levels, but even a 5
GHz transistor like the BFT25A will run out of bandwidth when you get
down to the nanoamps.  (I discovered this experimentally.) ;)

For the OP's problem, I'd vote for a log-antilog based on a matched quad
NPN such as a MAT14 or LM3046 (which is a quint).

Of course the input and output are both in volts, so you're really
computing Vref**2/Vin.  You need two V_BE's derived from Vref (either
two diodes in series or one and a 2x amplifier), subtract the Vin one,
and then exponentiate the result.  It's best to buffer the Vref side
with an op amp, because otherwise the variable current on the output
side will cause an error. (Same thing on the output of the subtraction..)

The tempco goes away to leading order, I think, because the I_S term
varies slowly with collector current, and the eV_BE/kT term cancels
since the sum of the V_BEs is the same in both branches.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs
Principal Consultant
ElectroOptical Innovations LLC
Optics, Electro-optics, Photonics, Analog Electronics

Briarcliff Manor NY 10510

hobbs at electrooptical dot net
http://electrooptical.net
```
```On Thursday, April 14, 2016 at 11:18:30 PM UTC-4, Fibo wrote:
> Hello,
>
> I'm trying to figure out the best way to go about making a -1/x function in hardware. From googling around I see 2 methods,
>
> 1. Inverting log -> Anti-log
> 2. OpAmp with multiplier in the feedback loop
>
> I have +/-5V rails available, and my input is from 0.4V to 2V (which should give me an output of (-2.5 to -0.5). All DC values.
>
> Can anyone point me in the right direction here, I'm trying to do this with as few parts (no microcontroller) and as painlessly as possible, it doesn't have to be very accurate (2-5% error it ok).
>
> Much Thanks!

I've tried doing a square root function with an analog multiplier and opamp.
It was happiest with big input voltages... as the input got smaller, the
error got bigger.

George H.
```
```On 04/15/2016 12:21 AM, Tim Wescott wrote:
> On Thu, 14 Apr 2016 20:44:56 -0700, omnilobe wrote:
>
>> Use a diode with exponential current vs voltage. Input a current to the
>> diode and measure the voltage to get a log function. Then a derivative
>> of ln(x) = 1/x
>
> But how do you take the derivative of ln(x)?
>

Put a small dither on it, and measure the AC gain.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs
Principal Consultant
ElectroOptical Innovations LLC
Optics, Electro-optics, Photonics, Analog Electronics