Pages: [1]   Go Down
Author Topic: coarse / fine potmeter function  (Read 1026 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

needed a 16 bit fine control in an experiment and I realized it with two potmeters, one for coarse and one for fine control

After some tweaking I got this more generic function

Code:
uint16_t analogR(uint8_t coarsePin, uint8_t finePin, uint8_t bits)   // bits = bits per potmeter 1..8, so the result will be twice that nr of bits.
{
  if (bits > 8) return 0; 
  uint8_t shift = 10-bits;

  // analogRead(coarsePin); // opt. to remove noise by double read
  uint16_t value = (analogRead(coarsePin) >> shift) << bits;

  // analogRead(finePin);
  return value & (analogRead(finePin) >> shift);
}

I restricted the number of bits per pot to 8 to minimize noise fluctuations.

thoughts for improvement:
* three pots? four?
* why restrict both pots to same # bits?   
* how to do odd # bits? e.g. 15 bits so I could use the sign bit for errors.

just to share
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: