hi everyone kindly help me regarding incremental encoder coding,
i am using Hohner SERIES11 encoder (Resolution up to 5.000 pulses per turn
External diameter 58 mm
Shaft Ø 10 mm
Protection class IP65 according to DIN EN 60529) datasheet attached
I want read-only clockwise Direction pulses and give output the same pulses on any IO pin, I refer below the attached code from 1. Arduino Playground - RotaryEncoders. i select IO pin 12 on arduino Pro-mini board (custom made )
in sample code, it's working fine, code is reading CW and CCW pulse fine and giving only CW output same,
but my project is read-only Clockwise (forward direction pulse) and give mirror output and when encoder on reverse counting it should count that pulses and store temporary (in temporary memory, EEPROM and SD card If needed) and when it comes again in CW direction it should -- Minus that reverse pulses and should not give output, when it will come to the last location - it should give output again CW only ,
for example CW pulses is max 5000
enoder start form 0 to CW 2500 pulse>>>>>>>>>>it will stop [ need led output on/off only CW direction]
then CCW it will rotate in reverse 500(500 is not fix number) pulses (this time LED output should off) this 500 pulse should store
Again encoder will rotate in CW direction 500 pulse - this time LED output should be off, and should minus this 500 pulse from memory , when it comes on the last location(2500), program should give led output on/off again CW direction only. -500 pulse and + 500 pulse are offset and it is not fixed its 'n' variable number.
i want request kindly help me about coding ( mainly without EEPROM and SD card interface )
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
sample code
#define encoder0PinA 2
#define encoder0PinB 3
int LED1 = 12; // I m using this for IO Output
volatile unsigned int encoder0Pos = 0;
void setup() {
pinMode(encoder0PinA, INPUT);
pinMode(encoder0PinB, INPUT);
pinMode(LED1, OUTPUT);
// encoder pin on interrupt 0 (pin 2)
attachInterrupt(0, doEncoderA, CHANGE);
// encoder pin on interrupt 1 (pin 3)
attachInterrupt(1, doEncoderB, CHANGE);
Serial.begin (9600);
}
void loop() {
digitalWrite (LED1,LOW);
}
void doEncoderA() {
// look for a low-to-high on channel A
if (digitalRead(encoder0PinA) == HIGH) {
// check channel B to see which way encoder is turning
if (digitalRead(encoder0PinB) == LOW) {
encoder0Pos = encoder0Pos + 1; // CW
digitalWrite (LED1, HIGH); ///////////////////////////////////////////////////// LED output ON/off
}
else {
encoder0Pos = encoder0Pos - 1; // CCW
digitalWrite (LED1,LOW);
}
}
else // must be a high-to-low edge on channel A
{
// check channel B to see which way encoder is turning
if (digitalRead(encoder0PinB) == HIGH) {
encoder0Pos = encoder0Pos + 1; // CW
//digitalWrite (LED1,HIGH);
}
else {
encoder0Pos = encoder0Pos - 1; // CCW
//digitalWrite (LED1,LOW);
}
}
//digitalWrite (LED1,HIGH);
Serial.println (encoder0Pos, DEC);
// use for debugging - remember to comment out
}
void doEncoderB() {
// look for a low-to-high on channel B
if (digitalRead(encoder0PinB) == HIGH) {
// check channel A to see which way encoder is turning
if (digitalRead(encoder0PinA) == HIGH) {
encoder0Pos = encoder0Pos + 1; // CW
digitalWrite (LED1,HIGH);
}
else {
encoder0Pos = encoder0Pos - 1; // CCW
digitalWrite (LED1,LOW);
}
}
// Look for a high-to-low on channel B
else {
// check channel B to see which way encoder is turning
if (digitalRead(encoder0PinA) == LOW) {
encoder0Pos = encoder0Pos + 1; // CW
digitalWrite (LED1,HIGH);
}
else {
encoder0Pos = encoder0Pos - 1; // CCW
digitalWrite (LED1,LOW);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
encoder max frequency is 150khz kindly suggest supported arduino board or microcontroller
S11_EN_01web.pdf (975 KB)