It looks that i have similar problem but i dont think its directly connected with speed, maybe partly.
This post is update to my last post where i have used basic rotary arduino encoder.
The encoder that i use now is the same as the one in video accept mine has 400 PPR.
All together it works great but for some unknown reason it's loosing or adding steps.
Am using this encoder for counting liquid flow ( pump ). and there is no way i can recreate test scenario.
E.g. if i pour 1 liter i can see that the motor shaft of the pump, has turned 10 times.
Based on this i have define number of impulses. So, i turn 10x and you can see on display 001.00 and this is correct, BUT if i turn next 10 turns or 20 or 50, there is no way i can get 002.00 , 005.00 etc values.
I always get something between like 001.44 / 005.31 etc. It is important to mention that there may be some "wrong" full turns but there is no way that he misses so much steps.
Can some one explain why is this happening ?
We have cut all the delays and only thing that has left is the part where we send/read data from raspberry.
The code in attach is the main test code, but if necessary i can send whole working code ( with display output ).
//------------- main TEST code -----------------
//---- there no code snippet on chromium in ubuntu 12-- --
volatile unsigned int temp, counter = 0; //This variable will increase or decrease depending on the rotation of encoder
void setup() {
Serial.begin (9600);
pinMode(2, INPUT_PULLUP); // internal pullup input pin 2
pinMode(3, INPUT_PULLUP); // internalเป็น pullup input pin 3
//Setting up interrupt
//A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 on moust Arduino.
attachInterrupt(0, ai0, RISING);
//B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 on moust Arduino.
attachInterrupt(1, ai1, RISING);
}
void loop() {
// Send the value of counter
if( counter != temp ){
Serial.println (counter);
temp = counter;
}
}
void ai0() {
// ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH
// Check pin 3 to determine the direction
if(digitalRead(3)==LOW) {
counter++;
}else{
counter--;
}
}
void ai1() {
// ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH
// Check with pin 2 to determine the direction
if(digitalRead(2)==LOW) {
counter--;
}else{
counter++;
}
}