Ratiometric potentiometer input
I'd like to have a knob on the front panel of a controller where the user can tune a proportional value between 0 and 100%. I know, all those "modern" products (radios, scopes...) use those encoder type input devices with 16 or 64 positions per revolution. But I like the feel and touch of a real potentiometer much better. It has a hard stop at 0 and 100% and an optional "snap" at the 50% center position. Or you can put a pointer on the knob and a scale on the panel and tell exatly where you are without looking at some other display.
The P1 has no built in ADCs so the simplest solution is to use an RC decay circuit to measure resistance.
This requires only one pin. The strategy is
1. discharge the cap by driving the pin low.
2. let the pin float and measure the time until the input becomes high
The time is proportional to the resistance. The problem is that the capacitance has a tolerance of 10% and the full scale resistance of the pot also has 10 or even 20%. The time also depends on the input threshold voltage, so the overall tolerance is >20%. It would require some sort of calibration to reliably detect the 0, 50 and 100% positions.
My next idea was this circuit:
1. drive both pins low
2. wait until the cap is discharged (takes longer, >5RC time constants, say >2ms)
3. drive pin P2 high, let P1 float
4. measure the time t1 until P1 input becomes high
5. drive both pins low, wait until discharged
6. drive pin P1 high, let P2 float
7. measure the time t2 until P2 input becomes high
The position of the pot wiper can be calculated as t1/(t1+t2). As this is truly ratiometric the tolerances of R and C should have no influence on the result. There are some imperfections like P1 and P2 don't have exactly the same threshold voltage. But it should be at least much better than the first circuit. However, now we need two pins.
Or we could do it this way:
P1 and P2 act as sigma/delta ADC with a counter in feedback mode. P3 can be used for self-calibration by driving it low or high for calibration or let it float for measurement. The internal resistance of the driver of P3 together with R7 and R4 add some error. The calibration does not pull R6 exactly to ground or to 3.3V. But most of this error can be compensated by using an equivalent current source model. Disadvantages are: 3 pins required, much more complex calculations.
Of course, it would be much easier to just take a P2 and forget about all those hassles. But I like challanges, especially using clever software to replace complex or expensive hardware.
Does anybody have better ideas?
Nice to have would be...
- around 1% accuracy and 10 bits resolution
- 10 or 20 samples per second
- no calibration procedure where the user needs to turn the knob. Automatical calibration once at startup or on-the-fly are OK.