Skip to main content

Reply to "Recommendation for a Potentiometer with Stops (Detents)"

Incremental rotary encoders tell you movement and direction.  They do not tell you absolute position.  For example when you turn your computer on it doesn't know where your mouse is initially positioned.  For position a starting point must be assumed or derived from another source like a reset button, limit switch or and index mark.

What you would use for this application is an absolute encoder.  For ten positions you would need 4 bits.  This can be done with a four pole rotary switch.  Some switches do this directly: numeric thumbwheel switches provide a 4 bit BCD output (binary coded decimal).  You would need 4 digital inputs to read these.

Back to the potentiometer:

This page has sample code.  https://wiki.dfrobot.com/Rotar...ule_V1__SKU_SEN0156_

The conversion from analog input reading to a finite position is very simple.  The analog input is sampled.  Then the reading is compared in turn to a list of threshold values until it finds the value that exceeds the reading.  In the example, a value up to 630 represents 1, up to 680 is 2, up to 750 is 3, etc.  These thresholds must account for tolerances in the resistances and A/D readings.

int adc_key_val[12] ={630,680,750,810,845,860,890,905,920,940,950,980};

// Convert ADC value to key number
int get_key(unsigned int input)
{
    int k;
    for (k = 0; k < NUM_KEYS; k++)
    {
      if (input < adc_key_val[k])
     {
          return k;
        }
   }
       if (k >= NUM_KEYS)k = -1;
       return k;
}

OGR Publishing, Inc., 1310 Eastside Centre Ct, Suite 6, Mountain Home, AR 72653
800-980-OGRR (6477)
www.ogaugerr.com

×
×
×
×
×