user4103: I'm trying to calculate the coming RPS from rotary encoder. I am  trying to get it by checking the status with digitalRead. However, I can not get more than 6 RPS. Any solution? I will be obliged for your help.
Following is the code.
float rps;

void setup() {
  Serial.begin(9600);
  DDRC &= ~_BV (1); // pinMode (A1, INPUT);
}

void loop() {
  static int lastReedState;
  static unsigned long lastTransition;
  int reedState = (PINC & _BV (1)) == 0; // digitalRead (A1);
  // On a rising transition of the reed switch:
  if (reedState == LOW && lastReedState == HIGH) {
    // HIGH LOW measuring the low period
    // Compute time since last valid transition.
    unsigned long now = micros();
    unsigned long revolutionTime = now - lastTransition;
    // measuring the High period
    // Compute the RPS
    rps = 1.00 / (12.00*revolutionTime) *1000000.00;
    // 12 is rotary encoders resolution
    // Remember this transition.
    lastTransition = now;
  }
  // Remember last state.
  lastReedState = reedState;
  Serial.println(rps);
}


user3917: Consider using code similar to that shown in answers to the following questions: Reading from a KY-040 rotary encoder with Digispark; and Read RC receiver channels using Interrupt instead of PulseIn; and Can external interrupts be OR'd together on the '328 (Uno)?.
The first answer illustrates a fast-operating state machine to handle quadrature-encoded signals, ie rotary-encoder inputs.  
The second answer illustrates handling of multiple encoders via a single interrupt routine, using a pair of two pin-change-interrupt (PCI) pins per encoder.  The method assumes pins of a pair are in the same port.  Most Arduino IO pins are PCI capable; some are not; on some models of Arduinos, some PCI pins aren't brought out to headers, or aren't recognized as PCI by the IDE, as noted in the question Why PJ0 and PJ1 are not reporting as PCINT pins.
The third answer includes code from the first two, and also has a sketch that displays a table of PCI vectors and masks.  This table assists in planning pin layouts to reduce ISR overhead.  For example, if you have half a dozen encoders, you might attach three of them to six pins on one port (and one vector), and the other three to six pins on another port (and another vector).  Or you might put two encoders on each of three ports.  The latter method might run, on average, a little faster (eg a microsecond or so per ISR invocation).

4103: <p>I'm trying to calculate the coming RPS from rotary encoder. I am  trying to get it by checking the status with <code>digitalRead</code>. However, I can not get more than 6 RPS. Any solution? I will be obliged for your help.
Following is the code.</p>

<pre><code>float rps;

void setup() {
  Serial.begin(9600);
  DDRC &amp;= ~_BV (1); // pinMode (A1, INPUT);
}

void loop() {
  static int lastReedState;
  static unsigned long lastTransition;
  int reedState = (PINC &amp; _BV (1)) == 0; // digitalRead (A1);
  // On a rising transition of the reed switch:
  if (reedState == LOW &amp;&amp; lastReedState == HIGH) {
    // HIGH LOW measuring the low period
    // Compute time since last valid transition.
    unsigned long now = micros();
    unsigned long revolutionTime = now - lastTransition;
    // measuring the High period
    // Compute the RPS
    rps = 1.00 / (12.00*revolutionTime) *1000000.00;
    // 12 is rotary encoders resolution
    // Remember this transition.
    lastTransition = now;
  }
  // Remember last state.
  lastReedState = reedState;
  Serial.println(rps);
}
</code></pre>
 3917: <p>Consider using code similar to that shown in answers to the following questions: <em><a href="https://arduino.stackexchange.com/a/16420/3917">Reading from a KY-040 rotary encoder with Digispark</a></em>; and <em><a href="https://arduino.stackexchange.com/a/18221/3917">Read RC receiver channels using Interrupt instead of PulseIn</a></em>; and <em><a href="https://arduino.stackexchange.com/a/19109/3917">Can external interrupts be OR'd together on the '328 (Uno)?</a></em>.</p>

<p>The <a href="https://arduino.stackexchange.com/a/16420/3917">first answer</a> illustrates a fast-operating state machine to handle quadrature-encoded signals, ie rotary-encoder inputs.  </p>

<p>The <a href="https://arduino.stackexchange.com/a/18221/3917">second answer</a> illustrates handling of multiple encoders via a single interrupt routine, using a pair of two pin-change-interrupt (PCI) pins per encoder.  The method assumes pins of a pair are in the same port.  Most Arduino IO pins are PCI capable; some are not; on some models of Arduinos, some PCI pins aren't brought out to headers, or aren't recognized as PCI by the IDE, as noted in the question <em><a href="https://arduino.stackexchange.com/q/16551">Why PJ0 and PJ1 are not reporting as PCINT pins</a></em>.</p>

<p>The <a href="https://arduino.stackexchange.com/a/19109/3917">third answer</a> includes code from the first two, and also has a sketch that displays a table of PCI vectors and masks.  This table assists in planning pin layouts to reduce ISR overhead.  For example, if you have half a dozen encoders, you might attach three of them to six pins on one port (and one vector), and the other three to six pins on another port (and another vector).  Or you might put two encoders on each of three ports.  The latter method might run, on average, a little faster (eg a microsecond or so per ISR invocation).</p>
