Rotary Encoder - Need help with 'scaling'

Hi

First of all a couple of links

I'm using a EC-11 Encoder from here http://www.ebay.co.uk/itm/200834097586

And I'm using the encoder library here Encoder Library, for Measuring Quadarature Encoded Position or Rotation Signals

My problem is concerning, for want of a better word, 'scaling'. Using the sample code as given with the library I have the encoder working. The encoder has 30 detents (I've counted them hehe) and 24 pulses per 360 degrees, but I can't get my head around how to convert those values so my human action of going from one detent to the next only creates an increment or decrement in software of only 1.

At the moment one detent is producing two increments/decrements most of the time, with one inc/dec occasionally.

Thanks in advance for any help.

At the moment one detent is producing two increments/decrements most of the time, with one inc/dec occasionally.

How? I don't see any code to prove that assertion.

At the moment one detent is producing two increments/decrements most of the time, with one inc/dec occasionally

At first sight it sounds like the switch in the encoder is bouncing and producing false outputs which are being counted but it could equally be a problem in your code.......

To eliminate the effect of contact bounce, people usually put R/C filters on the outputs of encoders like this, as in the following circuit:

        //Encoder reading
        long newPosition = myEnc.read();                   // Read the encoder       
              if (newPosition != oldPosition) {            // Is it NOT what it was before? ie has it changed

                                                           // If it has changed
                    if (newPosition < oldPosition) {       // So if it has changed and it has gone down in value
                    //lcd.setCursor(13, 0);                // Goto row one, 13 character
                    //lcd.print("DW");                     // Display DW
                    
                        if (band == 0) {                   // Are we on 40M?
                        freq += fstep;                     // Frequency = Frequency + Frequency Step
                        ad.setfreq(freq);                  // Set the Output
                        dispfreq = 12001500 - freq;        // Change the display frequency
                        }
                        else {                             // 15M it is then
                        freq -= fstep;                     // Frequency = Frequency - Frequency Step
                        ad.setfreq(freq);                  // Set the Output
                        dispfreq = 12001500 + freq;        // Change the display frequency    
                        }
                    
                    }
                    else {                                  // If its not gone down in value it must have gone up
                    //lcd.setCursor(13, 0);                 // Goto row one, 13 character
                    //lcd.print("UP");                      // Display UP
                   
                        if (band == 0) {                    // Are we on 40M?
                        freq -= fstep;                      // Frequency = Frequency + Frequency Step
                        ad.setfreq(freq);                   // Set the Output
                        dispfreq = 12001500 - freq;         // Change the display frequency
                        }
                        else {                              // 15M it is then
                        freq += fstep;                      // Frequency = Frequency + Frequency Step
                        ad.setfreq(freq);                   // Set the Output
                        dispfreq = 12001500 + freq;         // Change the display frequency  
                        }
                  }
                
              //lcd.setCursor(8, 0);                          // Goto row one, 8 character
              //lcd.print(newPosition);                       // Display the encoder position
              oldPosition = newPosition;                    // Save the new position as the old position
              }

That's the code, pretty much the same as the example shown in the library. Its part of a VFO system for a Radio, The commented out lines allow me to place raw values on the LCD for testing purposes. Using the inputs 2 and 3 as suggested as well.

I've taken a closer look at the movement, its two increments for every detent with one odd count every now and again. The odd single count is probably the de-bouncing error so it's just the 'scaling' I need help with I guess.

I am not clear what your problem with scaling is. If newPosition changes by one 24 times for each 360 degrees then each detent is 15 degrees. What is it that you want to scale ?

Incidentally, your code is very clumsy with much of it repeated. Once you have determined which way the encoder is moving, checked the band and adjusted the frequency then you should be able to have one common block of code, or a function, to carry out the required actions.

AndyHipkiss:
The encoder has 30 detents (I've counted them hehe) and 24 pulses per 360 degrees

That sounds peculiar. I'd have thought that they would be the same number, or at least that the number of pulses would be greater than the number of detents (and hopefully by an exact multiple). As described, you would get less than one pulse per detent which seems inconsistent with the way you describe getting one or two pulses per detent. Do you have any sort of data sheet or description to confirm that's the intended behaviour?