Electronic – Controlling op amp gain with an mcu, would this work

microcontrolleroperational-amplifier

I need to be able to control the gain of an op amp with an mcu.
I know the obvious way is to use a digital potentiometer or an op amp which was already designed for this purpose.

I am wondering if this will do the trick:

schematic

simulate this circuit – Schematic created using CircuitLab

basically the mcu can use the mosfet to switch another resistor in parallel to R2 which would increase the gain from 2 to about 27 in this example.
So i'm thinking to have an array of mosfets, maybe 3 in total or so.
Would that work ?
I realize this would effect the high pass filter of C2-R2.

Another way of doing the same thing is putting R4 in series under R2 and shorting it out with the mosfet.

Which way is preferable ?

Thanks in advance !

Best Answer

Since you've run a simulation, go and do an AC sweep to see where the MOSFET capacitance starts to increase the gain (should be MHz, looking at it).

Also, for high signal levels (greater than a few hundred mV input), with the MOSFET off, the MOSFET body diode will cause huge distortion on the negative half cycles. A change in bias could prevent that, but watch out for 'click' effects on gain change if that is important to you.