Hey guys,
I am using a quadrature decoder chip to decode the position of a 600PPR open collector outputs quadrature encoder. The reason I am using a quadrature decoder was because I was having some error in the position counter when interfacing directly with the arduino so I was hoping simplifying things down to simple up/down pulses provided by the decoder chip would increase the reliability of things on the arduino side.
A problem that I have run into (and I think resolved, but i'm not sure how) is that the position counter seems to work okay but will randomly jump to a whacky number. It usually likes to jump to 255 for some reason. After pondering and reading I saw that I did not have a resistor in place that adjusts the duration of the pulses provided by the chip to the arduino when placed between two legs of the chip. With absolutely no resistor in place, an open circuit in fact, I think the pulses were either too fast to be recognized by the arduino (is that possible?) or I was exhibiting some kind of behavior similar to when you don't add a pull down resistor to a digital input, and it fires randomly.
Not only was the counter messing up when I didn't have the resistor in place, but the arduino would randomly just stop working.
Anyway, I added a 1Mohm resistor which should have corrected the circuit and lengthened the pulses to the arduino to ~2-3us which I imagine is long enough if not too long.
I realize I rambled here, but is it possible to have a pulse too short for the arduino to pick up? Should things have still been working normally without having the resistor mentioned? Maybe it was a problem with my code?
Here is the datasheet for the quadrature decoder:
link
Here is my code:
volatile int counter=0;
void setup()
{
Serial.begin(9600);
pinMode(2, INPUT);
pinMode(3, INPUT);
attachInterrupt(digitalPinToInterrupt(2), countup, FALLING);
attachInterrupt(digitalPinToInterrupt(3), countdn, FALLING);
}
void loop()
{
Serial.println(counter);
delay(100);
}
void countup()
{
counter++;
}
void countdn()
{
counter--;
}