# Is there a programmable variable resistor

I have a current signal that can vary in amplitude. I currently have a transresistance amplifier which uses 330 Ohm resistors.

However the amplitude of this signal can vary and I would like to be able to change the gain, when required from a micro controller.

Is there anything like an SPI part that alters resistance on command ?

• Does it matter if you change the voltage or the resistance? It's usually easier to change the voltage, by using an OP amp or DAC etc. – Lundin Apr 29 at 13:42
• there is such a thing as a motor driven potentiometer – jsotola Apr 29 at 19:40
• You can always put a motor on the shaft of a regular old mechanical tuner and rotate it mechanically. This might seem silly, but there are cases where solid state electronics might not have the desired properties (frequency, linearity, longevity, precision, cost) that you can easily achieve with a mechanical potentiometer. (dang, jsotola just beat me to it) – trentcl Apr 29 at 19:41
• Lundin: I am using a transresistance amplifier to measure small currents (circa 1mA) – Robin Apr 30 at 8:32

The term you are looking for is digital potentiometer.

Search for parts to find one that fits your needs. You can get them with up to 10 Bits of resolution. Be aware that on power-up the value might be at min or max until you send the needed value via the digital interface.

• Typically they start at around quarter-way, but there's usually a way to set a default value on startup. This default value sometimes can only be set once though! Generally as you say it's a good idea for the micro to get a good value in there before analogue power comes on (or at least before anything does anything important). – Graham Apr 29 at 23:21
• That's why it's a good idea to have them in series with a resistor whose value is low enough not to impact the performance much and high enough to avoid short-circuit. – Mast Apr 30 at 12:55

It seems you're trying to build a programmable gain amplifier. Programmable resistors, as jusaca says, exist in the shape of digital potentiometers.

However, there's also programmable gain amplifiers that you can buy like that; look for PGAs with your favourite electronics distributor (farnell, digikey, mouser, …).

Both devices don't have infinite bandwidth (and I know a student who ran into trouble exactly because they wanted to use a digital potentiometer for a 1 MHz signal, and the digital potentiometer wouldn't let that through), but it tends to be the case that PGAs have more predictable / better specified frequency responses in their datasheets.

Also, you'll want to read up on Friis' Noise Formula; the first amplifier in a chain of signal processing step dominates the overall noise performance and should therefore be as high (gain / noise figure) as possible; it might make sense to have fixed, low-noise amplification up front, and then variable attenuation (and that can be done with a digital potentiometer, or a "multiplying DAC*, or other means). Especially in RF, that's what you'll most commonly find!

As well as the solutions given above, you can use a voltage controlled resistor and drive it from a D to A. One way is to use an FET, a more obscure one is to use a light dependent resistor which is mechanically and optically coupled to an LED.

The FET approach is perhaps of limited value, as it can only be used unipolar; however the LDR method has the nice quality that the LDR is completely isolated from the control signal, and is completely bipolar.

There are a few ways this can be implemented without specialized chips.

1. Using GPIO pins as a rudimentary DAC

Design the amplifier circuit so that gain can be varied with a resistor connected to ground. This is not possible in the usual transimpedance amplifier, but easy to achieve if you add a separate non-inverting opamp amplifier circuit after it.

simulate this circuit – Schematic created using CircuitLab

In the above example, there are three GPIOs connected with 1, 2 and 4 kohm resistors. The gain can be varied by setting some of the GPIOs to output 0, and others as High-Z input pins:

GP1 GP2 GP3   Gain
Z   Z   Z    1x
Z   Z   0    2x
Z   0   Z    3x
Z   0   0    4x
0   Z   Z    5x
0   Z   0    6x
0   0   Z    7x
0   0   0    8x