# Controlling op amp gain digitally simulate this circuit – Schematic created using CircuitLab

LM358

positive rail: 24V

negative rail: -1.250V

Input voltage: -1.250 - ~20V

• Is this the right way to switch between gain of 10 and no gain (simple buffer)?

• $$\G = 20/2.2 + 1 = 10.09\$$ still not a 10, is there a better combination of standard resistors values to achieve gain of 10?

• Why not simply use either a programmable gain amplifier that you control from the MCU, or simply a DAC, in this case, a multiplying DAC, following a fixed-gain amplifier? That would be very easy to do, since you already have an MCU pin. – Marcus Müller Nov 8 '19 at 18:34
• It would help to provide requirements for the circuit: power supplies, input voltages, bandwidth, etc. As for choosing particular resistors, this voltage divider calculator is useful. – Null Nov 8 '19 at 18:35
• how do you deliver negative voltage here? – user2497 Nov 10 '19 at 21:54

Better approach: simulate this circuit – Schematic created using CircuitLab

The control is opposite from yours — when the low, the gain is 1, and when high, the gain is 10 (note the modified resistor values). In this configuration, the MOSFET is perfectly happy to have both positive and negative voltages on its drain, as long as the signal voltage is not high enough to turn on the body diode. Otherwise, you'll need to use a bilateral switch (IC).

• The voltage will be around 24V, is it too high? – ElectronSurf Nov 8 '19 at 18:51
• Yes, that's too high for the body diode. It's also too high for any commonly-available switch IC, so the relay is probably your best bet. – Dave Tweed Nov 8 '19 at 21:47
1. It's a pretty terrible way. The BJT has some offset and the base current will affect the output. A MOSFET would work better, but only for positive outputs, and the MOSFET has to have a low enough Vgs(on).

I would suggest using an analog switch, but the details depend on the power supply rails and input logic level. In particular you should avoid running any current (other than op-amp bias current) through the switch, so something like an SPDT switch is best. You might also have to add a bit of capacitance in the negative feedback path to ensure good phase margin.

2. 16.2K for R2 and 1.05K in series with 750 ohms for R1 has zero nominal error and uses standard E96 values. Alternatively 18K for R2 and 2K for R2 uses standard E24 values and only two resistors.

• How about a relay? – ElectronSurf Nov 8 '19 at 18:31
• Yes, a mechanical relay would work fine, provided it's a type designed to switch rather low voltages and currents reliably. – Spehro Pefhany Nov 8 '19 at 18:33