Shop OBEX P1 Docs P2 Docs Learn Events
Accurate Position Sensor Please — Parallax Forums

Accurate Position Sensor Please

Kirk FraserKirk Fraser Posts: 364
edited 2006-04-23 06:48 in BASIC Stamp
I got an A/D chip, TLC 2543 hooked up to a Stamp to read position of a potentiometer which was looking good.· Then I discovered a problem with the variability -- with no shaft motion, the debugger reports A/D numbers varying by 100 or so which equals about 7.2 degrees, which overlaps the positions I need to sense.· An electrician said the electricity doesn't always go in a straight path which causes the variations.· So please point me to an unusually·accurate small size pot that would report solid positions.· Or if there's a chance that something else is needed like using coaxial cable to cut down on noise, let me know.

I did locate an alternative off-shelf position·encoder but at $450 I·ask for something more like a pot.

Thanks,
Kirk Fraser

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-01 00:54
    Have you considered an encoder instead of pot?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • John R.John R. Posts: 1,376
    edited 2006-04-01 01:01
    You could look at this from a few perspectives, depending on the full nature of your problem. I am gathering that you want to sense radial motion.

    First, you could look for more sensitive/stable electronics.

    Second, depending on what the full range of motion you need to sense is, you could also look at some mechanical advantages, such as using a gear train so that each degree of movement of your input is multiplied to the pot (or other sensor) by the gear ratio. This would make the "drift" less of a problem.

    In combination with a gear train (or just two gears), you could also use a multi-turn pot.

    If you could "home" the device before sensing, you could also abandon the pot, and go with an encoder. These will report pulses that you can count and track where you are. Because they are digital, you save the A/D conversion. The drawback is that they only report "relative" movement, so you need to know where you started from. (Hence the requirement to home the device before sensing.) In your application I'm assuming that the shaft will be rotating in both directions, you'll need an encoder capable of not just giving you pulses, but also direction. Not a problem, but if you do the encoder "home grown" it will take a little more work. There are a number of kits for rotary encoders, including this one from our favorite supplier:

    http://www.parallax.com/detail.asp?product_id=28107

    There are others from the usual suspects of robotics parts.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.

    8 + 8 = 10
  • Kirk FraserKirk Fraser Posts: 364
    edited 2006-04-01 06:33
    John, thanks for interpreting Jon.· I'll try it.
  • Russ MillerRuss Miller Posts: 25
    edited 2006-04-01 07:01
    Hi Kirk,

    Something doesn't sound right here. 7 degrees or 100 counts of noise out of 4096 is far worse than you should expect for the cheapest potentiometer available when the wiper is stationary. Is the potentiometer set up as a voltage divider (one end of the element high, the other low and the wiper to the A/D converter), is the overall element resistance low compared to the A/D input impedance (1k to 10k perhaps), is the A/D reference voltage stable? Do you get nice quiet reading (perhaps 0 to 5 counts of noise) if you replace the pot with a fixed resistor divider near the ADC?

    If the environment is electrically noisy you might have to filter the signal before it goes to the ADC and if it is located far away you might use and buffer amplifier close to the pot and/or shielded cable.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-04-02 20:25
    Hi Kirk,

    I agree 100% with Russ. These is something fishy. Is the potentiometer perhaps located out on the end of a long cable, or something like that?

    You quoted the following: "An electrician said the electricity doesn't always go in a straight path which causes the variations.". This is either hokum, or very profound. hmmm.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • John R.John R. Posts: 1,376
    edited 2006-04-03 18:08
    I think the electrician was thinking of AC, and the fact that AC travels in sine waves wink.gif

    In reality, either the electrician was pulling your leg, doesn't know what he's talking about, or had someone deliver some type of safety message that really stuck. (The safety message being something along the lines of the power will not always leak out where you expect it to.)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.

    8 + 8 = 10
  • Kirk FraserKirk Fraser Posts: 364
    edited 2006-04-03 20:06
    Russ: Thanks for spotting the possibility that the problem can be solved without throwing away my parts. The filter idea was expanded below.

    Tracy: Well, I can't live with short leads -- they're about 2 feet on my prototype but in the real application they'll need to be about 6 feet. I can use twisted pair networking cable if advisable.

    John: After tearing apart one plastic pot, the position of the leads made the statement look feasible -- the path of least resistance could vary within 2% based on exact contact points on the plastic, heating the plastic, etc. However, being a relative novice, I don't really know.

    All: My plastic pot manufacturer, Bi Technologies had their head EE look at my circuit and suggested replacing the 330 ohm resistors with 0.1 uF capacitors (between the wiper line and ground). I'll try that and post the result.

    Another suggestion by a former Tektronix Ph.D. was to go with digital pots but I wasn't able to find one with adequate resolution.

    Jon: Off-shelf shaft encoders seem to be exhorbitant at $450 or so across two manufacturers but I ordered Parallax's version just in case. It would seem that some of the technology in a mouse could be used -- especially an optical mouse -- by someone with your skill.
  • Kirk FraserKirk Fraser Posts: 364
    edited 2006-04-04 13:35
    The addition of the 0.1 uF capacitor improved the results immensely. The range of error is about the same but the frequency of error is now low enough that I can take three samples, calculate the further out and discard it, leaving good position data.

    So Tracy I suggest updating your website on TLC 2543 so the input protection resistors are replaced or augmented with 0.1 uF capacitors. (I realize I may have made a mistake in resistor placement but now we know 0.1 uF capacitors are needed.)

    I ordered the Parallax encoder as suggested above and continue to look for other solutions but I'm probably going to use the current solution for now and try to improve on it with a seperate reference voltage supply, better wiring, and perhaps extra capacitors along the line.

    Thanks everybody!
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-04-04 17:50
    Hi Kirk,

    Capacitors often help with noise problems. I leave a place on circuits boards for them, but don't include them automatically. There are lots of situations where they are not appropriate.

    In your situation, where the potentiometers are located distant from the input, an RC filter along with shielded twisted wiring could help greatly with the noise problem, as you have seen. The noise problem is most likely 60 hertz pickup from the powerlines. Or it could be electrical hash noise from your proportional valves. The shielding would reduce the amount of noise coupled electrically, twisting would reduce the amount coupled magnetically, and the RC filter (with 1/2piRC value < the noise frequency), would reduce residual levels. But you don't want RC so large that it limits the responsivity of your system. Keeping the noise out in the first place is the best bet. If the noise is coming from the valves and the potentiometers are close to the valves, that is a difficult situation for shielding. The potentiometers themselves then should be located inside a metal shield, and the valves too, separately, with good grounding.

    Encoders are nice, because they are digital and do not suffer from analog noise problems.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Kirk FraserKirk Fraser Posts: 364
    edited 2006-04-04 18:59
    Hi Tracy,

    I realize there are lots of encoders out there but the ones that say they have 12 bit resolution or higher cost $150-$500 which is way too much and usually too large. The Parallax unit and similar are more affordable but the resolution is unknown at least I didn't find it before ordering. The price is such that it might be best for me to put a Stamp or something near each potentiometer or encoder to create a digital signal as I definitely do not want mistakes to occur as a result of position glitches. You may remember but other readers don't know yet that my project is a hydraulic robot thus consequences of error are more significant than on a toy.

    Where would you suggest I look for more education on the RC filter? I assume it's pretty simple but I don't yet know even how to detect the noise frequency -- the Stamp debugger restarts slow from a pause then scrolls by at a fairly good speed but I don't know what each line represents in terms of frequency so I can count the lines between errors. Because it's slow enough to read, I suspect it's a speed independant of my laptop's 1Ghz CPU and could be independant of the 40 pin Stamp's speed too. But you are probably right on it being 60Hz because in this stage of test the valves aren't operating. So if we assume it's 60Hz then your formula would give a resistor value of R = 1 / 0.5piC / 60 right or would it be R = 1 / (0.5piC - 60) where C is 0.1 uF? Then the result of 0.1 or 0.01 depending on the formula doesn't give a recognizable resistor value. So what am I don't wrong?

    Kirk
  • CuriousCurious Posts: 1
    edited 2006-04-04 20:03
    I agree....use an encoder, they much easier to use.
  • Russ MillerRuss Miller Posts: 25
    edited 2006-04-05 05:57
    Kirk said...
    Where would you suggest I look for more education on the RC filter? I assume it's pretty simple but I don't yet know even how to detect the noise frequency -- the Stamp debugger restarts slow from a pause then scrolls by at a fairly good speed but I don't know what each line represents in terms of frequency so I can count the lines between errors. Because it's slow enough to read, I suspect it's a speed independant of my laptop's 1Ghz CPU and could be independant of the 40 pin Stamp's speed too. But you are probably right on it being 60Hz because in this stage of test the valves aren't operating. So if we assume it's 60Hz then your formula would give a resistor value of R = 1 / 0.5piC / 60 right or would it be R = 1 / (0.5piC - 60) where C is 0.1 uF? Then the result of 0.1 or 0.01 depending on the formula doesn't give a recognizable resistor value. So what am I don't wrong?

    An oscilloscope is a great tool for looking at signals like these becasue you can see the shape and period of the noise.

    There are probably better places to start for filter information, but this gives some of the terminology[noparse]:http:[/noparse]//en.wikipedia.org/wiki/Low-pass_filter

    In the calculation you have to watch out for the capacitance units. The formula needs Farads, 0.1uF is 0.1x10^-6 Farad
    f = 1/(2piRC) so R = 1/(2piCf) = 1/(2* 3.14 * 0.1x10^-6 *60) = 26k Ohms
  • Kirk FraserKirk Fraser Posts: 364
    edited 2006-04-06 08:34
    Hi Curious,

    Got any specific encoders that will deliver 12 bits i.e. greater than 1 degree resolution AND won't break the bank? I ordered the Parallax encoder but don't know its resolution yet -- I expect it will be easy to use. But since this is important both now and after the project is done, I'm trying every way I learn of until I get a stable cost effective solution.

    Hi Russ,

    The worst case I captured in a debug terminal with the .1 uF but without the 26K resistor is this sequence:
    ... 328 328 116 325 328 443 330 328 .... unhooked from any mechanical influence. This is even worse than I'd noticed before but it does smooth out well enough to sample every three outputs, reject the worst, and have a good result.

    And with the 26K resistor installed, it seemed to act slightly worse, which must be why the BI engineer didn't suggest a resistor.


    I received the Parallax Boe Bot Digital Encoder Kit and it is primarily an LED and photodetector pair with flanges for the Boe Bot. It is another thing to think about until I get an ideal solution decided on. Perhaps I can make something work having several of the pairs and a grey-code wheel.

    I'm not trusting enough of the 3 sample discard one strategy on the pots as it seems like any stray signal might be picked up. Certianly a better cable might help and I'll work on that too.

    Kirk
  • Russ MillerRuss Miller Posts: 25
    edited 2006-04-06 13:30
    Kirk, that noise is pretty bad and I still think there is a fundmental problem. Do you have other channels on the A/D chip that are working better? Does the data change when you rotate the pot shaft, and does a voltmeter (set for DC volts) show the voltage corresponding to the data? You could see results like this if the pot was not actually tied to the input that the A/D is sampling, either because the the wiring is incorrect (I've done that) or the software is selecting the wrong channel (done that too). As a first step I'd disconnect the pot and try hooking the a/d input to the vref pins (thru a few hundred ohm resistor to protect the chip against mistakes) and verify that the a/d reads 4095 when the input is tied to +vref and 0 when it's tied to -vref.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-04-06 17:45
    Kirk,
    >> ... 328 328 116 325 328 443 330 328 .... unhooked from any mechanical influence.

    Was that done with the potentiometer out on the end of a cable? What is the ohms resistance of the potentiometer, and where was the potenitometer in its travel when you took those readings? If the full scale is 0 to 4096 counts, then a reading of 325 would be pretty near one end. I'm not quite sure what you mean by "unhooked from any mechanical influence".

    Noise problems would be less if you use a relatively low value of potentiometer. I.e., a 5kohm pot would have less noise pickup problem than 500kohm. That depends too on how noise is getting into the wiring.

    Another test: set your multimeter on the AC volts sensitive range (200 mV) and see if there is AC present at the Stamp that the meter picks up. You may need to use short shielded wires on the voltmeter. Monitor the Stamp debug at the same time and see if attaching the meter leads changes the reading. Does your hand position in relation to the system change the reading? As Russ said, an oscilloscope can be a great help in cases like this, to isolate noise sources and to troubleshoot the circuit wiring.

    Do attend to the shielding of the wiring. It could make a big difference.

    In cases where I have residual 60hz noise in Stamp data, I have PBASIC take 8 analog readings in a row, timed so that the whole sequence takes 16.7 milliseconds. That is one cycle at 60hz. Then average those. That strategy samples the waveform at points that will create an average that rejects the 60hz noise. That also helps with high frequency uncorrelated noise. But it is still important to get the best signal possible at the inputs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Kirk FraserKirk Fraser Posts: 364
    edited 2006-04-06 21:29
    Hi Tracy,

    The 10K pot is as you wrote nearer 0 at 325 than the 5118 maximum for this full 360 rotation pot which was free-standing held by the wires attached and nothing attached to the shaft or mount.

    The AC test showed some interesting voltages when initially hooking up but with one lead solid on the ground and the other at various points on the Stamp it always settled down to 0.000 volts and remained there.

    I hooked up a cheap digital Tek scope and found an odd sine wave large on the left tapering to zero on the right but after applying aluminum foil shielding it looked more like 60 Hz hum with variation back to the original wave based on my body position. Some variants were removed by disconnecting my computer.

    As mentioned earlier, the bad reading sequence was worst case -- with the 0.1 uF capacitor installed results stayed very near 328 most of the time making the interferrence harder to detect. So far I haven't been able to spot a simultaneous error on the debug display and anything else.

    It looks like your 8 sample average with the 0.1 uF capacitor and maybe shielding should work fine. I thought about the shaft encoder solution and it would take a desktop IC fab to get the LED's down to my size requirements as the only off-shelf solution I've seen that fits all my needs was quoted around $500. So the A/D solution we've been working toward for quite a while is the one I'll use.

    Thanks,
    Kirk
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-04-07 16:53
    How long are the "wires attached"? Are they twisted into close proximity to one another at 2 to 3 twists per inch? When you add the aluminum foil "shielding", did you wrap it tightly around the twisted wires and connect the foil to ground at the Stamp end only, right at the point where the ground wire from the pot attached? Is the ground wire from the pot attached as close as possible to the ground pin on the BASIC Stamp?

    I am asking these leading questions, because they are fundamental for instrumentation wiring.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Kirk FraserKirk Fraser Posts: 364
    edited 2006-04-10 17:45
    I'm ordering shielded twisted wire to comply with your advice.· I'm considering USB wire may be easiest if I can locate seperate connectors.· Thank you very much!

    Kirk
  • Kirk FraserKirk Fraser Posts: 364
    edited 2006-04-22 09:44
    After waiting almost 2 weeks for an order of shielded Cat-5 wire, I canceled the order and used some on-hand shielded cable that is much more expensive having 12 conductors plus the shield. Unfortunately it works worse with the central 3 wires used for the pot and the capacitor is applied at the Stamp end as is the shield ground. This is both with and without the 8 cycle average in the Stamp program.

    So, I'm going to try chips at the pot on a double sided board -- first the A/D chip (if this works I'll get a cheaper chip later) which will communicate the serial bus and if that doesn't work, I'll add a programmable chip to do the averaging before transmitting through the automotive wire.

    The problem is this unit will control a hydraulic assembly that must not fail lest a human get hurt. So it has to work all the time or fail gracefully. Random induced error doesn't make this look easy. So if I can't get any improvement with chip proximity, I'll have to spend the money for a shaft encoder.

    Kirk
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-04-22 11:38
    Kirk -

    Did you connect the metallic outer shield at one end ONLY, as Tracy suggested? If not, disconnect the "far" end, and please run the trial again.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Kirk FraserKirk Fraser Posts: 364
    edited 2006-04-23 06:48
    Bruce,

    Yes I did as Tracy suggested. The cable is about 6ft. long reflecting the end application. The shield is braided wire.

    Kirk
  • Kirk FraserKirk Fraser Posts: 364
    edited 2006-04-23 06:48
    Bruce,

    Yes I did as Tracy suggested. The cable is about 6ft. long reflecting the end application. The shield is braided wire.

    Kirk
Sign In or Register to comment.