Need assistance in calculating resistors in a differential amplifier - Page 1
Forum section: electronics / beginners

author: mitrynicolae
author_rank: Contributor
timestamp: April 06, 2019, 07:43:24 pm
content: Hello guysI need your assistance in calculating R1 R2 R3 and R4 resistors from the attached schematic. The requirements are that at 25V the opamp should output 2V and the opamp should be powered from a single 5V supply.Also please let me know if what I am trying to achieve is correct.- if the base of the transistor is off and no battery is connected then the opamp should output 0V- if the base of the transistor is on but no battery is connected then the opamp should output 2V- if the base of the transistor is on and the battery is connected then the opamp should output a value between 0 and 2 volts depending on the battery resistance (RL is used to simulate this resistance)- if the base of the transistor is off but a 12V battery is connected then the opamp should output 0.96V- if the battery is placed by mistake in reverse and the base of the transistor is off then the output should be 0.Also please let me know the following:1. is what I am trying to achieve correct or not?2. in case of the reverse voltage on the opamp (+ and - not the supply), will the opamp survive?3. what resistors I should change with potentiometer (only one if possible) in order to have possibility to adjust the output in case the resistors are not precise4. is there any other method to measure the voltage between the specified points5. regarding my schematic, could you also post the equations that lead to the calculated values or at least how you deduce them?P.S. Please note that RL only simulates the battery internal resistance.

author: radiolistener
author_rank: Super Contributor
timestamp: April 06, 2019, 11:15:15 pm
content: Here is very nice video from Dave which explains how it works:

author: alex.martinez
author_rank: Contributor
timestamp: April 07, 2019, 12:31:56 am
content: Quote from: mitrynicolae on April 06, 2019, 07:43:24 pmYou have two batteries in the system...I have no clue of which one you are talking about...Quote from: mitrynicolae on April 06, 2019, 07:43:24 pmIt should, +-32 V of input common mode, you can check the datasheet of theLM324ADQuote from: mitrynicolae on April 06, 2019, 07:43:24 pmBy a resistor being not precise, you mean if their tolerance is too large? What it is done to avoid this is to use high component values (100 k for instance) so that the tolerance is not so critical in general. But if you worry about acurracy, grab a decent multimeter and measure the components, adding pots all over the place ends up being messy. If you want tunability, add pots on small resistors (1 k, 5 k...)Quote from: mitrynicolae on April 06, 2019, 07:43:24 pmI do not know whether you refer to mesuring the voltage in the simulator or in a physical sense...but I would suggers you that you post more info...Quote from: mitrynicolae on April 06, 2019, 07:43:24 pmThey have posted an opamp tutorial prepared by Dave, I strongly advice that you watch it and try to understand the system, rather than guessing values from a simulator.

author: mitrynicolae
author_rank: Contributor
timestamp: April 07, 2019, 07:14:23 am
content: Thank you Martinez for your time!Meanwhile I figured out the solution. The issue was in my logic. For the sake of simplicity let's consider that the supply voltage is 20 volts. I then divided this voltage to 10 and got 2V on the positive input of the opamp. Then I have set the R3 and R1 in order to match the R2 and R4. The issue was that the output voltage excedeed 2V. Which if you think about it is absolutely normal. The opamp tries to match positive input with the negative input by compensating with the output. In my case R1 and R3 acts as a voltage divider. The maximum voltage that the opamp can measure is when the positive input of the opamp is 2V and the R1 is conected "ground". This can be achieved by turning on the transistor and disconnect the load. Since the opamp will try to match the positive input with the negative input (at 2V) and since the R1 and R3 act as a voltage divider, and since R1 is connected to ground (we already demonstrated that) then we can calculate the required output.(Vout-V2)/R3 = V2/R1R1Vout - R1V2 = R3V2Vout = (R1+R3)V2/R1After applying the actual values we can determine that the Vout is aprox 2.2V which also the simulation suggested.Thank you all for the answers. Sometimes even if you know the theory you just think that it will be easier to play around with the values. It turned out that with electronics is different and you can get quickly very frustrated when in fact the solution was to take a paper and a pencil and calculate the values. After a night of sleep I found the logical gap in the design and I have recalculated the values. I have attached a schematic of the actual (working) design. I know that I should use greater resistor values in order to not waste the current but I have a lot of 1k and 10k resistors and I don't want to buy other resistors.For others who might face the same issue I also suggest this site: "https://www.electronics-tutorials.ws/opamp/opamp_5.html".@martinez the external battery is marked on the schematic with a rectangle with + and - signs having the text "ExternalBattery". (You did not see this coming)

author: mitrynicolae
author_rank: Contributor
timestamp: April 07, 2019, 07:24:56 am
content: P.S. The fine tuning potentiometer should be placed in series with R3. We all know that resistors (even at 1% tolerance) will not be spot on and we need a way to fine tune the output. In this case R3 should be 9.5k (9.53k is the closest that you can buy) and a potentiometer of 1K. This will allow a correction of 5% up or down.

author: Zero999
author_rank: Super Contributor
timestamp: April 07, 2019, 06:30:02 pm
content: In what way do you want to change the output? Are you talking about the gain or offset? In this circuit, it's difficult to alter one, without affecting the other, with just one potentiometer.What are the other sections of the LM324 being used for? Are any of them spare? If so, that would make it easier to adjust the offset voltage.

author: mitrynicolae
author_rank: Contributor
timestamp: April 08, 2019, 03:40:36 pm
content: My intention is to have a way to adjust the amplifier in case the resistors are not spot on (which most certainly won't be). Could you please let me know where to put the potentiometer in order to solve this issue? It seems that my sugestion of putting it in series with R3 is not a good solution since it affects also the gain. My intention is to have always the gain of 0.1 regardless of the resistors tolerance. Ideally the output value of the opamp should be 2 volts (when measuring 20V) but if it is 1.995 then it is no issue since the measurement error will be compensated in software. It is always easier to compensate a constant error than to compensate an unknown gain (thats way I really need an exact gain of 0.1 regardless of the input value).

author: mitrynicolae
author_rank: Contributor
timestamp: April 08, 2019, 04:09:09 pm
content: It seems that trying to compensate the opamp in order to do what I want is harder than I thought. Maybe as someone already suggested on this site, buying very low tolerance resistors is the best bet I have so far. Could you please suggest me a good store (that can deliver to Romania) and also some very low tolerance resistors (SMD package 1206) (preferably under 0.01%)?

author: Zero999
author_rank: Super Contributor
timestamp: April 08, 2019, 04:19:29 pm
content: Mouser, RS Components, Digi-Key and Farnell are the suppliers I use most often, but 0.01% tolerance will be expensive. At that tolerance, the drift also becomes significant. You can trim with a potentiometer, but when the temperature changes, the resistance will, causing the gain to drift.

author: mitrynicolae
author_rank: Contributor
timestamp: April 08, 2019, 04:28:40 pm
content: Thank you for the replay Zero999, but where to put the adjustment potentiometer. The issue is that I want to have only one adjustment potentiometer and not two or more.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: April 08, 2019, 05:08:32 pm
content: The transistor is always on, I fail to see what should happen here?The traditional method to measure internal resistance is to apply an AC current, and measure the resulting AC voltage. The circuit looks very different. A typical implementation will be simultaneously more complicated (more components required), and simpler (consisting of only a current source and a voltmeter). The source can be an oscillator and buffer amplifier or switch, and the voltmeter can be an AC coupled amplifier and precision rectifier, or a synchronous rectifier (analog switch), or...Note that a SPICE "battery" is actually an ideal voltage source, i.e., Rs = 0 by definition. You will need to find a model that describes a battery, to be able to test your circuit with something realistic.Note also that, in general, the internal resistance varies with frequency, typically in a sqrt(f) manner (this is due to ionic diffusion within the battery). This gives an impedance which is equal parts capacitive and resistive, so that it is difficult to speak in terms ofresistanceas such, even at very long time scales (which implies a large change in charge state, for which we of course expect a change in terminal voltage). At shorter time scales (~kHz), it is capacitive (the capacitance of the battery plates themselves), and at still shorter times (~MHz), inductive, and so on (wiring stray inductance, radiation losses for the wiring as random antennas, etc.).Tim

author: mitrynicolae
author_rank: Contributor
timestamp: April 08, 2019, 06:04:00 pm
content: Regarding the schematic, you can completely ignore the transistor and the battery. In fact let me add another simplified schematic. Now on this schematic, considering that the load resistor is disconnected and that the other resistors are not perfect (let's say 5% tolerance) where should I put the potentiometer in order fine tune the circuit and to obtain 2 volts on the output. I have tried several configurations (with the potentiometer in series with R3 or R1 but the output is not proportional with the input anymore.

author: rstofer
author_rank: Super Contributor
timestamp: April 08, 2019, 06:45:30 pm
content: That schematic looks a lot like a non-inverting amplifier. Does this calculator help?https://www.allaboutcircuits.com/tools/non-inverting-op-amp-resistor-calculator/Without checking the datasheet, I don't know that the op amp can get within 2 volts of ground.

author: mitrynicolae
author_rank: Contributor
timestamp: April 08, 2019, 07:16:28 pm
content: Thanks for your help, but also the online calculator showed that the R1 should exactly match the R2 (according to their schematic). Basically if the resistors are not perfect then weird voltages will appear on the opamp output.

author: Zero999
author_rank: Super Contributor
timestamp: April 09, 2019, 01:48:22 pm
content: Don't use 5% tolerance resistors, when 1% is widely available and isn't expensive.The only way to trim the gain, without adding another op-amp or affecting the offset is to set the gain slightly higher than required and add a potential divider to the input.

author: RandallMcRee
author_rank: Frequent Contributor
timestamp: April 09, 2019, 03:18:33 pm
content: Quote from: mitrynicolae on April 08, 2019, 07:16:28 pmRight. This is why you should consider an integrated difference or instrumentation amplifier. The resistors are built in and trimmed to precisely match. All kinds of benefits, go to Analog Devices site and read some app notes.

author: mitrynicolae
author_rank: Contributor
timestamp: April 09, 2019, 05:17:08 pm
content: Thank you RandallMcRee. I will open another thread starting by your idea.