Reviews about: Incremental encoder / Handwheel ZSS600-100B-5L
- Evaluation
-
- Author:
- Manfred K.
- Date:
- Wednesday, July 3, 2024
- Review:
-
I bought this for a geocaching toy safe, to emulate a mechanical three disk combination lock. I ran into problems with incorrect counts of pulses, depending on the direction of rotation. I found that each line ( A and B was only giving correct pulses in one direction, contact bouncing was bad in the other direction. So I used line A for ccw and line B for cw.
After that the encoder was giving correct counts of pulses.
Here for those who care, test sketch for arduinio.
#include Arduino.h
const int LineA = 2; //ext int Pin2 (Int0), Encoder Spur A
const int LineB = 3; //ext int Pin3 (Int1), Encoder Spur B
const int debounceTime = 100; // microseconds
volatile unsigned long TempdebounceTime = 0;
volatile int dial=0;
volatile int dialBuffer=0;
void setup() {
pinMode(LineA,INPUT); //Line A encoder
pinMode(LineB,INPUT); //Line B encoder
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(LineA),ISR_Wheel0,RISI-
NG); //One click of the encoder, counts down
attachInterrupt(digitalPinToInterrupt(LineB),ISR_Wheel1,RISI-
NG); //One click of the encoder, counts up
}
void loop(void)
{
if(!(dial == dialBuffer))
{
Serial.println(dial);
dialBuffer=dial;
}
}
void ISR_Wheel0() //One click of the dial line A (green LED), only counted if direction is ccw (line B / yellow LED already high), counts down
{
if(micros() -TempdebounceTime debounceTime) //debouncing time passed
{
TempdebounceTime = micros();
if( ((PIND & (1LineB))) && ((PIND & (1LineA))) ) ////only if Line B gelb/yellow LED is already high, LineA is tested again to prevent bouncing errors
{
dial--;
if(dial=-1) dial=99; //roll over
}
}//if debounce
} //ISR_Wheel()
void ISR_Wheel1() //One click of the dial line B (yellow LED), only counted if direction is cw (line A / green LED already high), counts up
{
if(micros() -TempdebounceTime debounceTime) //debouncing time passed
{
TempdebounceTime = micros(); //Debounce time met
if(((PIND & (1LineA))) && (PIND & (1LineB))) //only if Line A green LED is already high. LineB is tested again to prevent bouncing errors
{
dial++;
if(dial=100) dial=0; //roll over
}
}//if debounce
} //ISR_Wheel()
- Product:
-