Hi Jack, thanks for answering.
I have been watching the debug code you mentioned, and the output has changed since things went south.
I added some Serial.print statements of my own.? After watching the debug output for a while, I wanted to know what was going on in SetEncoderDirection:
void SetEncoderDirection() {
? encoderDirection = 0;
? newPosition = rotary.read();
?if (newPosition != oldPosition) {
? ? ?Serial.print("Old: " );
? Serial.println(oldPosition);
? ?Serial.print("New: " );
? Serial.println(newPosition);
?}??????????????????????????????????????????????????????? // Move this one from here....
? if (newPosition != oldPosition) {
? ? if (newPosition > oldPosition)
? ? ? encoderDirection = 1;
? ? else
? ? ? encoderDirection = -1;
? ? oldPosition = newPosition;
? }
}
...and also here, at the top of your debug block:
#ifdef DEBUG?
?Serial.print("Direction: " );
? Serial.println(encoderDirection);? ? ? ? ?
Serial.print("Examine Fast Tune: Start = ");? ? ? ? // May be useful for setting Fast Tune rate
Serial.print(fasttuneStart);
Serial.print("? ?end = ");
Serial.print(fasttuneEnd);
Serial.print("? diff = ");
Serial.println(fasttuneEnd - fasttuneStart);
#endif?
With this in place, I turned the encoder one detent stop, and you see that SetEncoderDirection was called three times.? I kept doing this, slowly, and you can see from the serial monitor output below that even though I am turning the encoder int he same direction, the encoderDirection is variously 1 and -1.? Every 3rd turn the frequency is just not updated at all, but with the vacillating encoderDirection, the freq. goes up 100Hz and down 100Hz.? I thought maybe a bad solder connection was causing a kind of "echo" in the circuit, so I re-flowed the solder to pins 18, 19 and 20.? I have tried a couple of encoders with the debounce caps installed (but who knows, maybe I have a drawer full of bad ones).? I was reading your followup article on encoders and when I got to the end where you suggest always to look for the last thing you think might be wrong, I even changed the connection wires.? Last thing? that I can think of is to swap out the Arduino mini, which I will get to in a day or so (ugh, all those header pins to solder).? If you can suggest anything else, let me know.? Serial output follows:
First turn here:
Old: -1
New: 0
Old: 0
New: -1
Old: -1
New: 0
Direction: 1
Examine Fast Tune: Start = 3324? ?end = 11398? diff = 8074
Old: 0
New: -1
Old: -1
New: 0
Old: 0
New: -1
Direction: -1
Examine Fast Tune: Start = 11539? ?end = 31281? diff = 19742
Old: -1
New: 0
Old: 0
New: -1
Old: -1
New: 0
Direction: 1
Examine Fast Tune: Start = 31422? ?end = 40482? diff = 9060
Old: 0
New: -1
Old: -1
New: 0
Old: 0
New: -1
Direction: -1
Examine Fast Tune: Start = 40623? ?end = 48869? diff = 8246
Old: -1
New: 0