1

I have a sliding potentiometer and whilst its a linear one, it is not completely linear. I wanted to know if there was a way to filter out the linearity variance using mathematical operators on a microcontroller.

  • 5
    Yes, microcontrollers can do math. – hobbs Jul 16 '21 at 13:33
  • Why does it need to be linear? Is this just a control or is it being used as a sensor? You would need to connect it to an encoder so you have measurements to linearize against. How can you tell it's not linear in the first place without measuring position? Is it really that nonlinear? Wipers also stick. – DKNguyen Jul 16 '21 at 13:33
  • 1
    How nonlinear is the potentiometer? How nonlinear do you want it to be? And do say "completely" or "exactly", we need actual numbers for these values. – Elliot Alderson Jul 16 '21 at 13:35
  • @ElliotAlderson think its 20%. I would like it to be as non linear as possible. – BigBadBatta Jul 16 '21 at 13:46
  • @DKNguyen Yes its being used as a sensor. I have a device that can perform accurate linear movements to test against. – BigBadBatta Jul 16 '21 at 13:48
  • 1
    Your previous comment is in contradiction with your post. Is the pot too linear or not linear enough? I suppose it doesn't matter if you already have a measurement setup. Just map your actual output to your desired output to a table with interpolation and the output can be *whatever* you want. Or curve fit the table if you want to get fancy. Mind the stiction when approaching the same point from opposite directions. – DKNguyen Jul 16 '21 at 13:53
  • *I would like it to be as non linear as possible* - use a switch. – Andy aka Jul 16 '21 at 13:54
  • Sorry i meant as linear as possible, my mistake @Andy aka – BigBadBatta Jul 16 '21 at 14:01
  • @BigBadBatta Have you connected it to the MCU in a linear fashion, or in some non-linear fashion? You should provide information how you have connected it and where, and how are you measuring the non-linearity - are you sure that it's the pot that is non-linear, or the device you are using to measure it? – Justme Jul 16 '21 at 14:04
  • 3
    Get a better quality potentiometer.$$$$ If you really need 'perfect' linearity, you'll be much better served using an encoder rather than a potentiometer. The pot will drift with time, an encoder won't. – Kyle B Jul 16 '21 at 14:28
  • "As linear as possible" suggests that you want state-of-the-art hardware and may be quite expensive...is that really what you need? – Elliot Alderson Jul 16 '21 at 19:05
  • What value potentiometer it is? Too high value and microcontroller may not read it reliably. Which microcontroller or ADC? – Justme Jul 16 '21 at 19:11

1 Answers1

2

Well, what you're asking for is called calibration: so calibrate!

Run your potentiometer to know positions, measure the observed resistance, probably in the shape of a voltage at an ADC (ideally, with exactly the microcontroller and circuitry you're using in the actual measurements).

Do that in fine enough steps that give you a table to map (some observed) resistances to corresponding positions. Save the table in your microcontroller's code. That's it: From there on, it's just measuring a resistance, looking its neighbors in that table up, and interpolating between them to find the best estimate for position. Considering the locally linear nature of resistance, that interpolation is probably just a linear function.

If the relationship between distance and what your ADC measures is significantly non-linear in nature, of course you'll have to adjust your interpolation algorithm (or, at least, you could do better than linear interpolation).

Marcus Müller
  • 88,280
  • 5
  • 131
  • 237