I'm a hobbyist and like to design my own tools rather than buying chinese "kits" that teach nothing.
I have been needing all sorts of amplifiers for different things and usually I would just use an op amp and a few resistors to do the job but that's time consuming and I usually end up losing the resistors afterwards XD So I decided to look into making a programmable gain amplifier.
The obvious choice was using digital pots so I had a look at a few microchip application notes in order to have some idea about accuracy and stability of different designs. This one was exactly what I was searching for: http://ww1.microchip.com/downloads/en/Appnotes/01316A.pdf
If you look at figure 6 (page 15) they show a tempco compensated, wide range amplifier which uses 2 pots. I already have a few 10K MCP4652 digital pots which are also perfect for this application, but there are 2 issues:
1) There is no easy way to calculate the gain, unlike other designs, which led me to do a basic analysis to see the range of available gains (using python).
This first graph is the gain vs R1 (I didn't know how to do a 3D graph, ideally it would be a graph of gain vs R1 vs R2): Just wow! it's pretty obvious that a lot of gain values are repeated and multiple resistor values yield the same result. so I made another graph, this time it only includes gain values that are repeated more than once and how many times they have been repeated. For gains of 1 and 2, there are 256 repeats since all values of the pots works, but even for really high gain values, repeated values exist.
I'm not sure how I should go about implementing the software. easiest way seems to be removing the duplicates and sorting the list, then storing it in the MCU memory, then using a lookup table to find the nearest gain to the desired value. this will also allow going through the list iteratively with a manual encoder or similar! but this will use a ton of memory. Please let me know if there are better ways of doing this. Edit: there are a total of 39896 different gain values. if stored as floats (each takes 4 bytes), they will take 159584 bytes (almost 156KB), each of the gain values needs two resistor values and since the pot has 257 taps, they need to be int or unsigned int, tripling the memory usage (468KB)! an external EEPROM solves that but that is added cost. Calculating the next higher gain value and the resistor values needed for it seem like a good choice, but I don't think that's possible, especially since the highest resistor combination is most likely not achieved which I discussed in the next part.
2) the more important issue would be the current through R1+R2. the pot is rated for an absolute maximum of 10mA current. for an op amp powered from +/-18V (a very typical supply voltage) this can easily happen if the resistor values are too low. I think using 100K pots instead of 10K, and only saving the highest combination of resistor values for a particular gain should solve that, but again, if there is another way to limit the current, please let me know. I know op amps "can't drive much current" but they can most certainly drive 10mA with ease.
Here is a graph showing current through the resistors when minimum resistance combination is used (18V supply, 10K pots): The maximum current is 3.5mA as you can see. Now the same graph, just using the maximum resistance combination possible: This can exceed 400mA! the op amp can't drive that much current, but this is surely susceptible to damaging the pot. If I want to pre-compute the list, I should be careful to not choose small values.