# Peak detector and LM324 not working

Trying to make second circuit.

Here is my outputs
(source: cs608722.vk.me)

In1+ connected to ground, OUT1 blue and after diode red

In1+ signal red and Out2 blue
(source: cs608722.vk.me)

Why cap charges if there is no signal.. Capacitor is 0.1uF Plot's data is from Arduino, 5V-1023 0V-0 LM324 supply from arduino +5V and 0V

The capacitor charges because the LM324 inputs have a small current flowing out of the, called the bias current. All op-amps have some bias current, but the LM 324 has more than most.

It's typically about 20nA, so a 100nF cap will charge about +0.2V/second.

• Ok, thanks. Maybe there is some workaround? and why max charge is not 5V? Should I supply 0-7V? – a_vasilkov May 31 '14 at 4:57
• How do you want it to behave? The circuit has no reset so the output voltage will always increase. You could use a much larger capacitor which would slow the rise. – Spehro Pefhany May 31 '14 at 5:01
• @a_vasilkov - If you look at the data sheet for the LM324, ti.com/lit/ds/symlink/lm324.pdf, page 4 has electrical specifications. Fifth item down is Voh, high level output voltage. Note that, for mA current output, a 5 volt supply will provide no more than 3.5 volts. As the capacitor approaches peak voltage you will need less current, so the 324 can actually go a little higher, but still. And there is also the diode drop to consider. I did tell you that you need a couple of volts extra for a 5 volt signal, remember? – WhatRoughBeast May 31 '14 at 11:15
• The simplest workaround is to change the opamp. Replacing the LM324 with a TL084 will cut bias currents to 30 pA, and your voltage rise will be about 1000 less. But you still need a reset function. – WhatRoughBeast Jun 1 '14 at 14:16

What is your time scale? For peak detectors with any but the shortest hold times, I use FET input op-amps (hold times on the order of a second or more if you do everything right). Otherwise the bias currents will produce what you see. You can use a pot and add a small value to one of the inputs to zero the offset on an LM324. Or use a much bigger cap and an emitter follower before the cap to get higher current and fast charging. In precision circuits, use a polypropylene low leakage cap.

May need some capacitance across D2 for stability. Select C for speed.

(Are you really getting advice from that guy who spends 20 minutes testing design software without using any docs?)

• 1ms between signals and 2ms between readings Serial.println(analogRead(A0)); delay(1); Serial.println(analogRead(A1)); delay(2); – a_vasilkov May 31 '14 at 5:10
• @a_vasilkov Doesn't your code give a 3ms total delay between readings? Either way, your plot is a couple seconds long and an LM324 peak detect (or an integrator - which is what it is doing while waiting. You just need it to be integrating zero.) will definitely ramp to max + or - in that time frame without compensation. – C. Towne Springer May 31 '14 at 5:48
• So what do I do if there is no signal like 1-10 mins and then it start. Oh! guess somehow I should connect cap to ground while signal is zero.. and maybe you know how to get cap signal to 5V? If I apply 0-7V to amp and arduino can read only 5V max signal.. I will fry it :( – a_vasilkov May 31 '14 at 5:56
• @a_vasilkov Yes, you need an analog switch or FET to short the cap to ground for reset or when you know there is no signal to track. Safest I think to reset when needed rather than keep shorted. You need a "rail-to-rail" op-amp and the LM324 is not. It will not get near the 5V on output. Here is a list from Analog Devices analog.com/en/precision-op-amps/… You can look through them for a dual package and single supply. TI also has great op-amp. Just search "rail-to-rail op-amp". – C. Towne Springer May 31 '14 at 6:08
• There are definitely better peak-detector circuits that use two op-amps. If I knew how everyone was drawing schematics I could post one. – C. Towne Springer May 31 '14 at 6:10