1
\$\begingroup\$

Consider we have a nonlinear opamp circuit like this.

log amp

According to theory this op amp should take log of input.

I wonder whether it is possible to get a response like this :

logamp2

I tried to plot vOut versus vIn but I didn't get meaningful results.

logamp3

First try

I replaced diode with a 1N5817 schottky diode and changed resistor value to 200k. This time I got quite interesting result.

To plot transfer function on the horizontal axis I select V(n001). On the vertical axis I select v(vO) trace to plot.

logamp4

Second try

After reading @Mattman944 's answer I exported Circuit's Lab simulation results as CSV. Since my primary OS is Ubuntu and Excel or LibreOffice Calc skills are quite bad I exported data to MatPlotLib.

import matplotlib.pyplot as plt
import numpy as np
import csv

time=[]
vIn=[]
vOut=[]

with open('devre.csv', 'r') as csvfile:
    plots= csv.reader(csvfile, delimiter=',')
    for row in plots:
        time.append(float(row[0]))
        vIn.append(float(row[1]))
        vOut.append(float(row[2]))

plt.plot(vIn,vOut, marker='o')

plt.title('Log amplifier')

plt.xlabel('vIn')
plt.ylabel('vOut')


plt.show()

The result looks like this. May be there might be some way to plot data in logarithmic scale.

logamp5

To be more precise I got these example from the textbook which I study.

logamp7

In the example they ask \$v_O\$ in terms of \$v_I\$ and \$R\$ and they want us to quick sketch of answer. Also \$ \large i = I_S(e^{\frac{qv}{nkT}} - 1)\$, \$\large \frac{kT}{q} = 26mV\$ and \$ \large n\$ is between 1 and 2. These circuit parameters are given.

I solved the example on paper and sketched the output. Which looks like this.

logamp8

I wondered whether theory matches practice so I tried to simulate the circuit in LTSpice.

\$\endgroup\$
  • 1
    \$\begingroup\$ See what happens if you pick a leakier diode (like a schottky) and increase the size of the resistor. Your plot actually does look like it could be taking the log of the input, but it saturates quickly because the saturation current of the diode is quite small compared to your voltage across 15K (and so the op amp rails). \$\endgroup\$ – Los Frijoles Jun 27 at 21:20
  • 1
    \$\begingroup\$ Try selecting a particular diode model for D1, such as a 1N4148. The default model might not behave like a real diode. \$\endgroup\$ – Elliot Alderson Jun 27 at 21:22
  • 1
    \$\begingroup\$ Your Second Try matches my results, at least for > 0.1 Vin, below that and it is too hard to read the linear graph. So, if you didn't change anything else, maybe the primary issue was in plotting. \$\endgroup\$ – Mattman944 Jun 28 at 13:54
  • \$\begingroup\$ I got these results directly from Mattman944's simulation results. (First one) Since I do not have proficiency in using LTSpice yet this might be true. Also LTSpice might be using a different equation for diode current. \$\endgroup\$ – Erdem Jun 28 at 16:31
1
\$\begingroup\$

The circuit only works for positive inputs. Add an offset to your input to keep it above zero. Loops in XY plots can be formed by capacitance, but at 5kHz, it should be negligible, I can't explain the loops. Try slower input frequencies, if it was stray capacitance, the loops will change. Finally, the circuit inverts, so the output is negative.

Works in CircuitLab. If CircuitLab can plot XY directly, I don't know how, I have only been using it a few weeks. I exported to Excel and plotted it.

schematic

simulate this circuit – Schematic created using CircuitLab

enter image description here

Edit: Based on comments from Kevin White, I re-ran at 5 kHz and a loop appeared. This confirms that stray capacitance can affect the results. Simulate slow and it works good.

enter image description here

\$\endgroup\$
  • 1
    \$\begingroup\$ At low input currents the dynamic resistance of the feedback element (the diode) can be extremely high and pF capacitances can result in large time constants. Log amplifiers always suffer from this. A photodetector amplifier I one designed could take tens of seconds to settle at -90dBm optical input power (equivalent to pA photocurrent). It was much faster at higher light levels. \$\endgroup\$ – Kevin White Jun 28 at 2:06
  • \$\begingroup\$ @Kevin White - Thanks, I re-ran at 5 kHz and demonstrated that capacitance will affect the results. I edited the answer. \$\endgroup\$ – Mattman944 Jun 28 at 2:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.