PDA

View Full Version : Encoder Library bug?



BillC
01-15-2014, 02:29 PM
I was getting some strange results with the encoder library ( Version 1.1), seemed like it would count fine in one direction and mess up in the other. I was using a 2500 PPR encoder which means 10000 counts per rev and using the Z phase to trigger display of position. I seen this in Encoder.h:

static void update(Encoder_internal_state_t *arg) {
---snip a bunch of lines---
switch (state) {
case 1: case 7: case 8: case 14:
arg->position++;
return;
case 2: case 4: case 11: case 13:
arg->position--;
return;
case 3: case 12:
arg->position += 2;
return;
case 6: case 9:
arg->position += 2;
return;


For cases 6 and 9 that looks like it should be arg->position -=2; instead. I must admit I am kinda new to Arduino and C but I have been programming for a few years. I can read C better than I can write it but I am learning quickly, they typo just stuck out when I was reading. I thank you for making the Encoder library cause I would not be able to to many of the projects I had planned without it (current project is a cut to length machine with 25+ year old controls). I have used PLCs in the past and want to try a few Arduinos for the small stuff.

Thanks again
Bill C.

PaulStoffregen
02-09-2014, 01:49 AM
Yes, definitely a bug. I've updated the code.