A decoder from a motor has 2 square wave outputs that deliver 256 pulses/revolution (duty cycle 1:1). The two outputs are 90 degree out of phase for direction information.
I want to count pulse, in one direction up, in the other down. Towards this aim I attach to the first decoder output following routine:
void countStep(){
if(digitalRead(_CIN2)){_pos++;} else {_pos--;}
}
"_CIN2" is the second decoder output and "pos" the counter variable.
This works well until up to approx. 16kHz.
But for higher frequencies it counts in the wrong direction.
I first guessed, that the phase r