Notice: RCTime won't work for Pot
Kirk Fraser
Posts: 364
Simulating the RCTime command from the BS2 cannot accurately measure a 10K pot because the maximum value changes significantly when the circuit heats up. No need for reply, this result is for anyone searching for RCTime in the future. Here's the code:
To get a position value from a Potentiometer, consider using the Pot as a voltage divider feeding an A/D chip like MCP3208, thanks to Daniel Harris. That will be discussed in another thread.
PUB RCTIME (Pin):Duration | ClkStart, ClkStop {{ Reads RCTime on Pin returns discharge time in 12 bit form actually 69-4086 cold, 69-2593 hot }} dira[Pin]~~ ' Set as output outa[Pin]:=1 ' Set high Pause(10) ' Allow to charge DIRA[Pin]~ ' Set as input ClkStart := cnt ' Save counter for start time waitpne(1 << pin, |< Pin, 0) ' Wait for opposite state to end clkStop := cnt ' Save stop time Duration := (clkStop - ClkStart) * 468 / 10_000
To get a position value from a Potentiometer, consider using the Pot as a voltage divider feeding an A/D chip like MCP3208, thanks to Daniel Harris. That will be discussed in another thread.
Comments
Switching to using a pot as a voltage divider feeding an A/D chip doesn't necessarily fix your problem. It will help near the mid-range position because the pot resistance on either side of the wiper will change by similar amounts and the ratio will remain similar. Nearer the ends of the pot's range, the ratio will shift with temperature changes and you'll have significant errors because the resistance changes proportionately with temperature and there's more resistance on one side of the wiper.
This doesn't sound correct Mike. The total resistance of the POT may drift, but in a voltage divider scenario, with the POT connected to the supply rails and the center tap being the output, the output should remain consistent assuming you are feeding a high impedance input.
C.W.
1) Shaft nut tightness for panel mount models.
2) Grounding of metal objects attached or nearby.
3) Temperature, in my case, the difference between room temperature at 5AM and noon.
Beyond that I am no expert, so I hope the voltage divider configuration works. My goal is to achieve rotary position sensing that is reliable. I am aware of some other options like using a trimmer capacitor or optical encoder. I am not aware of a small size optical encoder that can deliver 12bits. I've heard laser encoders are very expensive and haven't seen anything on building your own.
I haven't yet tried to reconfigure the BS2 diagram to a full voltage divider - it may be faster than continuing to work on the Serin and Serout software for the A/D chip.
There should be a low-ohm resistor in series with the pot.
For those demanding applications, a multi-turn (10-turn) pot would be a good idea.
Sometimes people expect a lot from a pot.
I can well imagine that a cheap potentiometer could have problems with shaft nut tightness. I have trouble with the notion of so much sensitivity to grounding nearby, particularly with a 10K pot. I could see it with a 1 megOhm pot, but 10K is a fairly low impedance and I've not seen that kind of sensitivity before. Depending on the length of the wires to the pot, you may need to use a twisted pair for that wiring.
Pots are not necessarily sensitive to ambient temperature. It depends on their construction. Thin film resistances are usually less sensitive to temperature although there are wire-wound pots that are constructed to minimize their temperature sensitivity.
Some types of capacitors are very temperature sensitive and you need to choose the type of dielectric and the capacitor construction properly for the kind of temperature stability you need. The manufacturer's specs will tell you the temperature coefficient.
I've not seen a small enough 10 turn pot. Think of fitting it into a space the size of your finger knuckle.
"Garden variety" pots were a mistake for that reason too. The pot which can fit is
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=P12426CT-ND
Mike,
Perhaps not all pots have all 3 problems at the same time. Those are accumulated experiences.
Thanks for the tip on choosing the correct capacitor.
With this configuration, you can measure either the charge time or the discharge time -- or both -- for each leg.
-Phil
Wow! That's one more on the list of things to try. Thank you.
Of course the degree of warmth causing variations is relative - it's about 65 to 75 I guess with fewer operations while at 65 and more attempts at 75. Neither hot or cold in the absolute sense.
with the exception, some values are reported when ground and Prop input pins are shorted by a continuity test, which are of course wildly irratic.
Please suggest how to get values to report Pot changes like for other circuits. I'm using 220 resistors between the Pot and Prop and a standard 104 capacitor in Phil's circuit.
Now on to get the result to PWM...
Try this program with the differential circuit:
It measures the RC time on both sides of the pot. Notice the longer charge time. That's because you're charging the cap through more than just the 220R resistors.
-Phil
On my setup your code does something but I can't recognize what. The Serial Terminal posts a gibberish wrap with no noticable change when turning the pot. I tried some tweaks like changing the _xinfreq to 100_000_000 which is supported by my 6.25MHz crystal but to no avail. Thanks for trying to help.
Kirk
Well, use this, then:
_xinfreq is the frequency of the crystal, not the system clock.
-Phil
Thanks for the education on _xinfreq. It does work, but the total varies by at least 3 in the second digit without moving the pot wiper. Somehow the theory behind Jon's code is more stable. Can you explain why?
There's also something unexpected about the _clkfreq which failed the serial communication when set to 6_250_000 with the Baud rate set to 115200. At that rate 100_000_000 works. So looking into the FullDuplexSerial object there's a line bit_ticks := clkfreq / baudrate which useage may redefine the meaning of clkfreq even if it's crystal frequency for determining milliseconds in rxtime(ms)?
Kirk
I wasn't on about ambient temp variation, just that we're talking about a bloody pot. Eh, maybe it's one of those newfangledy, non-mechanical, infinite cycle, gold standard pots.
What do you reckon the accuracy of RCTIME is, anyway.
Jon's code eliminates any uncertainty from variable hub access times inherent in Spin programs. It will give you the most consistent results for a single resistance but does not do the ratiometric measurement that mine attempts in order to eliminate temperature variations. But how much precision do you need? +/-30 out of, what? 56000?, is only .052%.
PJ,
I once had a digital bathroom scale that I disassembled and traced the circuitry for. It used a General Instruments PIC NMOS processor. The A-to-D conversion from the strain gage bridge was done via an RC-time conversion, since those early PICs did not have built-in ADCs. Yet, it produced very accurate and consistent results.
-Phil
My desire has always been for 12 bit precision, one position in 4096 but I couldn't come close before. I don't know if I'll have to add ratiometric to Jon's readpot program. Today's temperature change wasn't enough to cause any effect. Thank you.
Kirk
In intervening years I got additional help to flesh out the opAmp circuit you designed and found it failed because for some reason the IRL530 needs PWM instead of a constant voltage level. PWM appeared to work on BS2 before I burned two of them out with poor bi-level ground design so I switched to the cheaper Props after wasting time with a Microchip microcontroller. So PWM is my next quest. Anyway the readpot program by Jon McPhalen earlier on this thread should replace all attempts to use RCTime for pot reading on a Propeller.
Kirk