Uno with shaft encoder on a motor giving 384 interrupts/rev on INT0 and index (once per rev) on INT1. There is another pin-change interrupt which occurs twice during 1 rev.
At low speed, below 2500 RPM, I need to do about 25us of computation which works OK with
void setup(){
attachInterrupt(digitalPinToInterrupt(3), indexISR, CHANGE;
attachInterrupt(digitalPinToInterrupt(2), encoderISR, CHANGE;
}
This picks up the rise and fall of the index which occurs during the second quarter of the INT0 pulse on channel A of the encoder.
Above 2000RPM to 4500RPM, the computation time is reduced to about 20us and works OK with
void setup(){
attachInterrupt(digitalPinToInterrupt(3), indexISR, RISING;
attachInterrupt(digitalPinToInterrupt(2), encoderISR, FALLING;
}
I've tried many options including changing EIRCA at the end of the INT0 encoder ISR ...
void encoderISR(){
if (!HISPD){
....
}
....
if (!HISPD && dtstroke < 13043){ // above 2300RPM
HISPD = true; // high speed
EICRA = 14; // INT1,index, RISING ; INT0, encoder, FALLING
}
if (HISPD && dtstroke > 13636){ // below 2200RPM
HISPD = false; //low speed
EICRA = 5; // INT1,index, CHANGE ; INT0, encoder, CHANGE
}
}
(the variable HISPD is used in the INT0 ISR to reduce the ISR code computation time at high speeds) but none work.
I'm stuck. Can anyone help?