Hey Cattledog,
Yes, I can definitely share with you what I did. Before I continue, I just want to let you know that this is using Arduino Due. As I mentioned before I have 7 encoders I would like to interpret.
First off declaring pins of channels A and B from the encoders.
int m1_CHA = 21;
int m1_CHB = 20;
int s1_CHA = 52;
int s1_CHB = 50;
int m2_CHA = 19;
int m2_CHB = 18;
int s2_CHA = 24;
int s2_CHB = 22;
int m3_CHA = 17;
int m3_CHB = 16;
int s3_CHA = 53;
int s3_CHB = 51;
int s4_CHA = 25;
int s4_CHB = 23;
Secondly, declaring volatile variables that represent the current position of the encoder.
volatile float m1p = 0;
volatile float s1p = 0;
volatile float m2p = 0;
volatile float s2p = 0;
volatile float m3p = 0;
volatile float s3p = 0;
volatile float s4p = 0;
Third, attaching interrupts on one of the channels of each encoder (in my case CHA). It is important to do both RISING and FALLINg in order to get quadrature counts (4x), with respecting ISR. As well as declaring the pinMode of CHB as inputs.
attachInterrupt(m1_CHA, m1_ISR_RISING, RISING);
attachInterrupt(s1_CHA, s1_ISR_RISING, RISING);
attachInterrupt(m2_CHA, m2_ISR_RISING, RISING);
attachInterrupt(s2_CHA, s2_ISR_RISING, RISING);
attachInterrupt(m3_CHA, m3_ISR_RISING, RISING);
attachInterrupt(s3_CHA, s3_ISR_RISING, RISING);
attachInterrupt(s4_CHA, s4_ISR_RISING, RISING);
attachInterrupt(m1_CHA, m1_ISR_FALLING, FALLING);
attachInterrupt(s1_CHA, s1_ISR_FALLING, FALLING);
attachInterrupt(m2_CHA, m2_ISR_FALLING, FALLING);
attachInterrupt(s2_CHA, s2_ISR_FALLING, FALLING);
attachInterrupt(m3_CHA, m3_ISR_FALLING, FALLING);
attachInterrupt(s3_CHA, s3_ISR_FALLING, FALLING);
attachInterrupt(s4_CHA, s4_ISR_FALLING, FALLING);
pinMode(m1_CHB, INPUT);
pinMode(s1_CHB, INPUT);
pinMode(m2_CHB, INPUT);
pinMode(s2_CHB, INPUT);
pinMode(m3_CHB, INPUT);
pinMode(s3_CHB, INPUT);
pinMode(s4_CHB, INPUT);
Lastly, the RISING and FALLING ISRs required. Note in order for the counts to not cancel out with one another, RISING and FALLING edges have opposite signs (increment vs. decrement)
// RISING EDGE ISRs
void m1_ISR_RISING() { if (digitalRead(m1_CHB) == 0) m1p += 1; else m1p -= 1; }
void m2_ISR_RISING() { if (digitalRead(m2_CHB) == 0) m2p += 1; else m2p -= 1; }
void m3_ISR_RISING() { if (digitalRead(m3_CHB) == 0) m3p += 1; else m3p -= 1; }
void s1_ISR_RISING() { if (digitalRead(s1_CHB) == 0) s1p += 1; else s1p -= 1; }
void s2_ISR_RISING() { if (digitalRead(s2_CHB) == 0) s2p += 1; else s2p -= 1; }
void s3_ISR_RISING() { if (digitalRead(s3_CHB) == 0) s3p += 1; else s3p -= 1; }
void s4_ISR_RISING() { if (digitalRead(s4_CHB) == 0) s4p += 1; else s4p -= 1; }
// FALLING EDGE ISRs
void m1_ISR_FALLING() { if (digitalRead(m1_CHB) == 0) m1p -= 1; else m1p += 1; }
void m2_ISR_FALLING() { if (digitalRead(m2_CHB) == 0) m2p -= 1; else m2p += 1; }
void m3_ISR_FALLING() { if (digitalRead(m3_CHB) == 0) m3p -= 1; else m3p += 1; }
void s1_ISR_FALLING() { if (digitalRead(s1_CHB) == 0) s1p -= 1; else s1p += 1; }
void s2_ISR_FALLING() { if (digitalRead(s2_CHB) == 0) s2p -= 1; else s2p += 1; }
void s3_ISR_FALLING() { if (digitalRead(s3_CHB) == 0) s3p -= 1; else s3p += 1; }
void s4_ISR_FALLING() { if (digitalRead(s4_CHB) == 0) s4p -= 1; else s4p += 1; }
Cattledog, please expand and suggest how to implement and use bitRead, I have never used it before. I hope it would be easily portable into the my code above.
Thank you,
PS: I apologize for the late response.