It is not uncommon to need an adjustable gain in an analog signal processing chain. If the adjustment is manual then it is pretty straightforward — you can use a potentiometer. When you need the adjustment under digital control then it becomes more complicated. If you need a digitally adjustable instrumentation amplifier then there are ready-made solutions such as the analog devices AD8557 from Analog Devices.
The AD8557 has an adjustable gain using digital potentiometers and a programmable offset using a digital to analog converter (DAC).
If you circuit doesn’t use an instrumentation amplifier or you need some adjustable gain after an instrumentation amplifier then you need to look at alternatives. There are some specialized solutions such as the LTC1564 which is a digitally controlled anti-aliasing filter with 4 bit programmable gain amplifier which might be useful as the stage preceding an analog to digital converter (ADC). The cut off frequency can be 10kHz to 150kHz and the gain 0dB to 24.1dB.
You can buy programmable gain amplifiers such as the Linear Technology LTC6911 which will give selectable gains of 0dB to 20dB. You need to read datasheets of such devices carefully though to make sure they meet your needs with respect to common mode input voltage range, bandwidth and noise, for example. The LTC6911 also has a relatively low input impedance as well which you might need to be careful of.
A “traditional” voltage controlled amplifier (VCA) is another option. These are totally linear devices where a voltage adjusts the gain (or attenuation) and they can have a very wide dynamic range, although that often is partly attenuation not gain. For example the Texas Instruments LMH6505 has an 80dB adjustment range but only a gain of 20dB – the rest of the dynamic range is a potentially massive attenuation. You also need to be careful of the accuracy and stability of the gain versus control voltage against temperature. These types of devices are usually based on exploiting bipolar transistor characteristics and can have a high degree of temperature dependency and inaccuracy. This is fine for some applications where you simply want to turn the gain up until you get a suitable signal or for AGC (automatic gain control), but not if you need to know what the original signal level was with any accuracy.
You can build your own VCA using transconductance amplifiers such as the Texas Instruments LM13700.
You could go down the DIY digital gain route – making your PGA using a digital potentiometer (which can be under SPI or I2C control) and an opamp. As with any design there are problems to watch out for. Digital potentiometers usually have a poor absolute tolerance so you want to try to use the potentiometer ratio for setting the gain if you want reasonable gain accuracy. That can make the gain step size rather nonlinear. However, some digital potentiometers such as the Analog Devices AD5141 have an “independent” mode where it behaves like two independent potentiometers with a common wiper. This means that the sum of the two branches don’t have to add up to the total value of 10k ohms like a normal potentiometer – each branch can be 10k. With a normal potentiometer the midway point would be 5k + 5k but with independent mode you can have 5k + 10k or 8k + 9k if you wanted. This helps avoid big gain jumps.
When considering using a digital potentiometer for gain control, it will be in the feedback of an opamp circuit and the unwanted capacitance of the digital potentiometer needs to be considered, as does the wiper resistance. Wiper resistance will affect the accuracy of the gain setting and also the maximum gain achievable but is not usually a major issue. However, the digital potentiometer capacitance can be a nuisance. The AD5141 has 25pF of capacitance on the A and B connections and 12pF on the wiper for the 10k ohm version. The wiper capacitance will appear on the input of the opamp and either the A or B capacitance will be on the opamp output. Most opamps will tolerate the 25pF on the output but the 12pF on the inverting input of the opamp can cause some gain peaking or instability. This needs to be considered in the design.
One way to check the effect is with a SPICE simulator (free simulators such as LTSPICE are available). Adding the stray capacitance to the schematic will show if there are any instability problems even if you don’t have a SPICE model for the digital potentiometer. This simple circuit simulation will show the effect.
R1 and R2 are two arms of the AD5141 and C1, C2 and C3 represent the internal capacitance of the digipot connections. With high gain (R1 low resistance) the circuit is stable but with low gain as shown the effect is quite dramatic.
The green trace is without C1, C2 and C3, the red trace is with the values shown. As you can see the circuit would be highly unstable with the digipot or even make a good oscillator. Some capacitance across R2 would help but not cure the problem completely because in this case the opamp used for the illustration does not have a large phase margin at low gain and is not happy with capacitive loads so is particularly sensitive to the digipot stray capacitance on the output as well as on the inverting input.