Page 1 of 5

analog inputs: op-amp + divider - Russian - now MCP6004

Posted: Mon Oct 07, 2013 7:56 pm
by AndreyB
Digikey BOM (registration required)
Oshpark board

Most of the signals are 5 volts, STM32 ADC runs at 3 volts. We need some divider and here is the alpha version of my board. This is a 10 channel board, but only the 1st and 2nd channel are complete in this edition - I just need to get my hands on a board and see if I can solder 0805 or if I should stick to 1206.

Based on LMV324IDT

Anyway, here it is:

Image

Full project is available at the repository
Schematic
Full package for ver 0.2

quad op-amp:
LMV324ID

Re: analog inputs: op-amp + divider

Posted: Sun Oct 13, 2013 12:03 am
by AndreyB
I was pointed out that the amp already has the diodes - "Input terminals are diode-clamped to the power-supply rails. Input signals that can swing more than 0.5V beyond the supply rails should be current limited to 10mA or less", so my own clamping is not needed.

Also, the way input signal goes through two resistors (10K and 150) totally ruins my original intention of a low-pass filter made of a 150 Ohm resistor and a 0.01uF capacitor. Version alpha 2 fail :)

Re: analog inputs: op-amp + divider

Posted: Mon Oct 14, 2013 7:33 am
by erich
Keep the input protection. It's much better to blow out an external diode then the a/d inputs.
I use a TVS diodes, in a quad unipolar 3.3v package for protection.
I also don't bother with the buffer opamp. I have a 'universal' input with an input resistor, a pull up and down and a cap to ground, followed by the TVS diodes. Because I use the same board on multiple applications I don't have any specific values. I just choose appropriate values for whatever I have it plugged in to.

Re: analog inputs: op-amp + divider

Posted: Tue Oct 15, 2013 11:40 am
by Sergey89
TVS and Zener diodes has a large leakage current. Low leakage diode is more preferred device (BAV199 for example).

Re: analog inputs: op-amp + divider - Russian

Posted: Tue Oct 15, 2013 5:04 pm
by kb1gtt
BAT199 has is a bit long in the tooth relative to reverse recovery time coming in at 3uS. I have used the BAT54 for similar with a reverse recovery of 5nS. I also like that the voltage drop on the BAT54 is lower. It drops .1V at 1mA where the BAT199 drops .9V. When I used the BAT54, my goal was to limit current to 5.3V with a 5V rail. The 2uA leakage of the BAT54 is negligible relative to the mA signals that are being passed through the sensing circuits.

Re: analog inputs: op-amp + divider - Russian

Posted: Tue Oct 15, 2013 5:12 pm
by AndreyB
My primary question now is what to do with the current limiting resistor R6.1 and the low-pass filter made of R1.4 and C1.1

Should I simply drop the 150 resistor and make the capacitor 100 times smaller to match the current limiting resistor, so that the same 10k resistor would be limiting current and working as part of the RC filter at the same time?

Re: analog inputs: op-amp + divider - Russian

Posted: Tue Oct 15, 2013 5:25 pm
by Sergey89
If you do not plan to use external clamping diodes you can simply remove R1.4, otherwise you need to use R1.4 to protect internal clamping diodes.

Re: analog inputs: op-amp + divider - Russian

Posted: Wed Oct 16, 2013 10:21 am
by kb1gtt
The 150 ohm and .01uF are a very high cut off low pass filter. Those are commonly used on the output of the op-amp. The op-amp is a high gain device, when making a rapid change it can cause some high frequency ringing. This clamp simply blocks high frequency RF from coming out of the op-amp.

Because you are using an op-amp as part of you input buffer circuit, I would suggest considering a Sallenkey configuration setting your cut off frequency to something like 1kHz to limit the input signals. Reference can be found here http://sim.okawa-denshi.jp/en/Sallenkey3Lowkeisan.htm

Generally you want to analog filter out high frequencies to prevent aliasing and such. If you expect the signals you are looking at to be with-in 0-5V the MCU ADC impedance is generally fine for this kind of circuit. So the op-amp is not required for things like TPS or MAP, as the input will be high impedance for a 0-5V signal. The issue is if you want to look at a larger signal, like a fuel injector which may spike to 40V or a spark circuit that may spike to 500V. Once the clamping diodes activate, the input becomes low impedance and will manipulate the circuit instead of just sniffing the circuit. It appears the op-amp can allow a 30V input signal while using a 5V rail. I should get around to testing this out myself, as there are many variations in how op-amps deal with the inputs. Often the circuits used to allow rail to rail will prevent the input from being able to go beyond .3V from the top rail. So one has to be very picky about the op-amp when using it to sniff high voltage signals.

Re: analog inputs: op-amp + divider

Posted: Fri Oct 18, 2013 8:34 pm
by erich
Sergey89 wrote:TVS and Zener diodes has a large leakage current. Low leakage diode is more preferred device (BAV199 for example).
if 15pf and <1ua leakage is too much input loading, you're not reading automotive sensors.

Re: analog inputs: op-amp + divider - Russian

Posted: Tue Nov 05, 2013 2:55 pm
by AndreyB
Here is how the assembled board looks like
Image

The board files have an error - the GND zone turned to be three unconnected zones, this explains the jump wire fix.

Another issue is with these uber-cheap op amps - http://www.ebay.com/itm/230740855657 - either some of them were bad or maybe I am burning some of them while soldering, but I have already replaced one.

By the way the soldering paste recommended by Jared was a blessing.

Here is the todo list for the next revision:
0) GND fill zone issue needs to be fixed
1) 0805 is totally fine in terms of soldering, this would get the board smaller (i.e. cheaper)
2) three pins for VCC input are probably a bit too much, two should be enough
3) a dual GND test pin is needed
4) all resistors should be named consistently
5) all resistors should be placed consistently
6) seeed pcb assembly service? at 10 cents for assembling an SMD resistor it's worth a try
7) wider tracks? not sure
8) need to change board shape to fit in 5x5cm to make the board cheaper on seeed?

Re: analog inputs: op-amp + divider - Russian

Posted: Mon Nov 18, 2013 1:55 am
by AndreyB
Status update: @ has started some rework of this board. We will try to use quad op-amps instead of dual op-apms and test seeed studio PCBA service so that they actually assemble at least the most challenging part of the board for us.

This work-in-progress version is available at https://svn.code.sf.net/p/rusefi/code/trunk/hardware/adc_amp_divider/

Re: analog inputs: op-amp + divider - Russian

Posted: Thu Nov 28, 2013 4:21 pm
by AndreyB
We are pretty close to the new version, this time it would be 12 channel since we are using LMV324IDR quad op-amps and the plan is to have seeedstudio solder them for us

Image

Re: analog inputs: op-amp + divider - Russian

Posted: Fri Nov 29, 2013 12:10 pm
by Sergey89
It's ok but you need to change the value of the elements. Divider must have an impedance > 10 kOhm to provide rail to rail output voltage swing. But high impedance before the ADC requires more cycles to complete the analog to digital conversion. Protection resistor before external clamping diodes can have an impedance > 1 kOhm. I think 10 kOhm is a good choice. Resistor after clamping diodes can have an impedance about 1 kOhm (it's safe in many cases). Capacitor with protection resistors is used to provide low pass filtering for the input signal. You can calculate the value of the capacitor if you know the required frequency.

f = 1/(2*pi*R*C)

Re: analog inputs: op-amp + divider - Russian

Posted: Fri Nov 29, 2013 4:55 pm
by abecedarian
russian wrote:Most of the signals are 5 volts, STM32 ADC runs at 3 volts. We need some divider and here is the alpha version of my board. This is a 10 channel board, but only the 1st and 2nd channel are complete in this edition - I just need to get my hands on a board and see if I can solder 0805 or if I should stick to 1206.

Anyway, here it is:

Image

Full project is attached and it is also available at https://sourceforge.net/p/rusefi/code/HEAD/tree/trunk/hardware/adc_amp_divider/
Curious as to why run a voltage divider into a unity gain op-amp as opposed to using the op-amp itself to do the voltage division?

Makes more sense to do that, and clamp voltages on the output than doing that on the input.

Re: analog inputs: op-amp + divider - Russian

Posted: Mon Dec 02, 2013 4:39 am
by AndreyB
abecedarian wrote:Curious as to why run a voltage divider into a unity gain op-amp as opposed to using the op-amp itself to do the voltage division?
Simply because this design was easier for my plain non-electrical brain. Simple op-amp with no gain and a simple divider, the simplest design possible. AFAIK gain circuit would be same number of components, right? I guess we have not changed that since there is not much difference.

Re: analog inputs: op-amp + divider - Russian

Posted: Mon Dec 02, 2013 4:45 am
by AndreyB
Status update: the 12 channel board is ready, we need a volunteer to order it :) http://oshpark.com/shared_projects/dzio5F9M

Re: analog inputs: op-amp + divider - Russian

Posted: Tue Dec 03, 2013 12:20 am
by kb1gtt
abecedarian wrote:Curious as to why run a voltage divider into a unity gain op-amp as opposed to using the op-amp itself to do the voltage division?
There are pro's and con's with any approach. If you front end resistor divide, then multiply via op-amp gain, you also amplify the op-amps offset voltage. So if the op-amp has a 10mV offset, and you multiple by 2, you now have a 20mV offset to deal with on the signal going to the MCU. You can add a POT to one side of the op-amp to create a slight bias, which allows you to remove the offset, however you still have to deal with long term drift, which can be a blah. With a 10bit ADC and 5V rail, you get 5mV per bit. So 20mV would equate to 4 clicks. However if you voltage divide at the output of the op-amp, you take the 10mV offset and chop it in half to 5mV. This is now in the noise floor of the ADC, and no trim POT or software processing is required to adjust for the op-amp offset.

Re: analog inputs: op-amp + divider - Russian

Posted: Thu Dec 12, 2013 6:48 am
by Mad Max
Sorry guys but this schematic will no work well.
With any clamping diodes you reduce OP-input voltage.
So at OP-out you will have same voltage as input (3,3V f.e.)
Then you divide it twice(to 1,65V f.e.)
Also I don't understand need of pull-up resistor at input?
It's a good noise- collector from power supply.

In my opinion we need much simple schematic using LM324- input, pull-down resistor 10kOhm, RC- filter (10 kOhm, 10-47 nF)
It will be enough even for 50V input voltage. Input diodes are strong and there no need additional clamping. Believe me.
Output- divider 5.6/10 kOhm (k=1,78; 5/2,8V).
That's all!

Re: analog inputs: op-amp + divider - Russian

Posted: Thu Dec 12, 2013 7:38 am
by Sergey89
This schematic works well but it really can be simplified by omitting the diodes. If you omit the diodes you need to ensure that the OPAMP can handle the specified clamping current through the internal ESD protection diodes.

The pull-up resistor is required for a thermistor.

LM324 can't be used because it does not have rail-to-rail inputs and outputs.

Re: analog inputs: op-amp + divider - Russian

Posted: Thu Dec 12, 2013 7:48 am
by Mad Max
Ah, sorry. Lm234 I mean.
About pull-up resistor ok. It's mean that dependent on exact channel we will use pull-up or pull-down resistor but not booth together.

Re: analog inputs: op-amp + divider - Russian

Posted: Fri Dec 13, 2013 1:51 am
by kb1gtt
Beware the rail to rail bits of many op-amp limit the input voltage to less than V+1, so an op-amp powered by 5V will shunt current to the 5V rail if you exceed 6V on the input. This will cause the rail to pull up from 5V if you don't have something pulling it down.

Re: analog inputs: op-amp + divider - Russian

Posted: Thu Jan 02, 2014 11:01 am
by davidbuzz
Is there any particularly strong reason you are using an op-amp on each input channel? I'm looking at all those, and just thinking I could do away with them, and most of the the associated circuitry ( like all those doides too). I was thinking, that if you want a high-impedance input ( so any attached circuitry like the main ECU, when you still the original in htere) by using just one mosfet, and one resistor on each channel. ( it's a buffer circuit, like an op-amp, but less passives etc).

http://en.wikipedia.org/wiki/Buffer_amplifier

Re: analog inputs: op-amp + divider - Russian

Posted: Thu Jan 02, 2014 12:35 pm
by AndreyB
Historically the main reason was yes high impedance and using it parallel to the stock ECU. Also amplifying to make sure the ADC is charged.

The 'parallel to stock ECU' phase is mostly over, but we would still need a voltage divider on most circuits - unfortunately stm32 adc is 3.3 volts :(

As for the next step, a simpler analog input board is in the works - it would probably have op-amps is half of the channels

Re: analog inputs: op-amp + divider - Russian

Posted: Thu Jan 02, 2014 2:09 pm
by davidbuzz
russian wrote:Historically the main reason was yes high impedance and using it parallel to the stock ECU. Also amplifying to make sure the ADC is charged.

The 'parallel to stock ECU' phase is mostly over, but we would still need a voltage divider on most circuits - unfortunately stm32 adc is 3.3 volts :(
..

Actually, a mosfet does away the need for a voltage divider too. a common-drain mosfet ( http://en.wikipedia.org/wiki/Common_drain ) , where V+ is 3.3v would be adequate, so long as the chosen mosfet's V[sub]GS[/sub] is rated to allow the appropriate input voltages ( ie you can put any nominally high voltage on the mosfet's input, and it's output will only go between 0 and 3.3v). All the mosfet needs to be considered "on" is an arbitrary voltage called V[sub]GS[/sub] , which can be quite varied, depending on the mosfet ( typically anywhere from 2 to 20 volts ) , which essentially means "above that voltage is ON, below that voltage is off". I'd think that if the rotary sensors are nominally outputing a 5v pulse, then anything over 2 volts ( or 3, or 4, whatever ) could be considered "on"...?

Re: analog inputs: op-amp + divider - Russian

Posted: Fri Jan 03, 2014 10:56 am
by kb1gtt
When you have an 8V or 12V analog signal with little chance of exceeding 12V, a resistor divider or the common drain amplifier would work well, as you are looking just for a scaling, or impedance matching. For most automotive analog sensors, I don't know the impedance and it seems relatively non-important, so for simplicity sake I would generally use a resistor divider, followed by a clamp and low pass filter. One place this falls a bit short, is when you have a signal that can get much higher. For example, an injector driven by a voltage clamped MOSFET. The injector is 12V however the MOSFET voltage protection is often clamped around 40V to 70V. If you use a resistor divider followed by a clamp, when the clamp activates you have a low impedance, which shunts energy away from the signal wire and skews the signal being read. The issue was that we needed to look at a 12V signal with potentially up to 100V spikes.

The solution that was sought out was to use an op-amp which allows for a much higher impedance. A MCU ADC with 10k series resistor will not produce good results. However an opamp with 10k series will impedance match good enough. This meant that when the a larger signal was present on the input, and the clamp activated, the impedance was still 10K instead of 1K or less. The 10k impedance prevented manipulation of the signal, and allowed russian to work in parallel with the OEM ECU. I helped russian with the board layout for this op-amp based analog input, but I wasn't a huge fan. I prefer a much simpler approach when you know the signal, and I prefer a more universal input when you need a more universal input.

For the simpler analog inputs like TPS, ICT, ect, I prefer what I have posted in this schematic http://daecu.googlecode.com/svn/Hardware/trunk/KICAD_Project_TRK-MPC5634_P3-P4-ETPU_IO_proto/TRK-MPC5634_ETPU_IO-board-sch_RA.pdf on page 3, top left 4 circuits. I don't like the diode clamps as they shunt energy to the + rail, which can cause the + rail to rise if there is no load to pull it down. In that design, op-amp U26B was connected to a precision 5V reference such that the 5V was push/pulled to 5V and would not lift when 20mA was shunted to the + rail by the diodes when clamping. Those circuits are looking to be safe when connect to 14V like you might see if you make a mistake in wiring and wired the battery direct to an input pin, while the signal that is normally looked at is between 0-5V. So voltages between 0-5V pass with only a little 1kHz low pass filtering, while above 12V is reasonably low impedance shunted away, limiting the input to 5.3V max.

I have what I believe is a better clamp circuit, which I plan to use instead of that U26B op-amp. I have posted that clamp here http://daecu.googlecode.com/svn/Hardware/trunk/MCU_pin_protect_PCB_1channel/IO_protect_1x_schematic.pdf see middle section with Q1 and Q2. I have physically built that and I am trying to get in the basement to test it out, but have had issues with time constraints. I have my fingers crossed again to get a chance this weekend.

If that clamp circuit preforms as my simulations claims it will, it's my plan to spin a more refined analog board for russian. One that includes the above mentioned 4 circuits (with revised clamp circuit), plus a couple universal input circuits as noted in the second link.

Re: analog inputs: op-amp + divider - Russian

Posted: Fri Jan 03, 2014 1:37 pm
by hasse.69
Your da man KB1GTT.
The more i read the more i understand i need to know more.
But your schematics with examples is nothing short of brilliant.
Kudos to you for explaining.
=)
Very best regards , Hasse.

Re: analog inputs: op-amp + divider - Russian

Posted: Fri Jan 03, 2014 2:20 pm
by davidbuzz
Am I correct in saying that the use of optoisolators driving the injectors, and op-aps on the inputs becomes less of a concern, if you aren't trying to actually *read* high-voltage signals on a digital input or ADC? I've got no plans to connect the 12v side of the injectors ( which has noisy high-voltage back EMF, agreed ) to any of the microcontroller inputs, so I'm just still not seeing that it's "essential" to the operation of a as-basic-as-possible setup....? Of course I do think opto-isolating the injectors from the microcontroller is a cheap protection against bad wiring ( 8ft of 14ga wiring on an injector? Just make it 10ga wire, or make it 1/2 the length, and the problem's gone. )

Re: analog inputs: op-amp + divider - Russian

Posted: Fri Jan 03, 2014 10:37 pm
by kb1gtt
Thanks for the pat on the back. I try to document not only what is needed to manufacture a device, but I also put some effort into documenting the design intent. I see it like comments in a program.

For the injector, it depends on if you are trying to control an injector, or measure an injector. When controlling an injector, you generally need to be concerned with the high-ish currents lifting the low side, which can change when the injector pintel actually delivers fuel. So lets say you have a 5mS pulse, and you drive it with 3.3V, and if the MOSET needs 2.5V at the gate referenced to the drain, if you lift the low side by .7V due to a small wire, you'll fail to turn on at all. Or if you only lift by say .5V, the on and off edges are typically rounded, and this .5V lift can cause a 5mS pulse from the MCU turn into a real world 4mS pulse at the injector. Those are two common reasons to use a MOSFET driver or opto coupler to buffer the MCU. An opto coupler can often drive a much higher voltage, or maintain a more consistent real world pulse at the injector. Another reason for the buffer is to increase the isolation voltage. The MOSFET is a single failure mode before voltage spikes can propagate up to the MCU. Opto couplers can offer a second layer before upstream issues happen. It can be better for one injector to fail, and allow the ECU to shut things down, than it is to let a spike cause unknown things to happen.

However that's not how this applies to this tread top "analog inputs" op-amp + divider - Russian". What russian was trying to do was to measure the pulses on the OEM system, then create the same pulses with his software. The issue he had was that the input had to be 100V tolerant, while he was looking for a 12V signal. He started with the shunt diodes, however that cause the injectors to fail to work. The issue was two fold. One was that when the injectors fired which caused a kick back, or over voltage protected event, the diodes would go low impedance which would manipulate the injector pulse. As well the injectors energy was dumped into the + rail which cause a variety of problems. The solution was to make a circuit that was high impedance and 100V tolerant, such that when the diodes clamped the voltage, the energy drawn away from the injector was minimal and the energy dumped to the + rail was minimal. This caused the problems to go away.

So now that russian has it working an engine, and he is no longer sniffing the injectors, he can use different simpler circuits. I've nearly got a draft ready for him to review, yippee snow day finally giving me a chance get some stuff done. I'm looking to offer the typical inputs for TPS, temperature, ect. Then also offer some universal inputs that can be used to sniff up to 500V which means you can measure the primary side of a coil. My goal is to make a development IO board that allows a developer to measure unknown signals. This generic input circuit is well protected and can easily measure from low mV signals to larger 500V signals.

Re: analog inputs: op-amp + divider - Russian

Posted: Thu Jan 23, 2014 6:45 pm
by hasse.69
So now i have ordered version 2.
Maybe i should have waited...... :?

//Hasse.

Re: analog inputs: op-amp + divider - Russian

Posted: Thu Jan 23, 2014 6:50 pm
by AndreyB
hasse.69 wrote:Maybe i should have waited...... :?
Why? v 0.02 is pretty cool & powerful.