what is the code for getting angular output from DC servo quad encoder with arduino?
motor(RMCS 2294)
KKARTHIKRAJA:
what is the code for getting angular output from DC servo quad encoder with arduino?
motor(RMCS 2294)
The same as the code for getting the the information out of any quad encoder.
The encoder is not likely to provide its absolute position but if you start from a known position and count how many times its output changes then given that you know how many times the output changes in 360 degrees then you can work out its position.
Have a look at this code for reading an encoder
Code copied from //http://playground.arduino.cc/Main/RotaryEncoders#Example3
#define encoder0PinA 2
#define encoder0PinB 3
volatile int encoder0Pos = 0;
void setup()
{
pinMode(encoder0PinA, INPUT);
pinMode(encoder0PinB, INPUT);
// 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);
byte in1 = 7;
byte in2 = 8;
byte pwm = 9;
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(pwm, OUTPUT);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(pwm, 255);
}
void loop()
{
if (encoder0Pos % 100 == 0)
{
Serial.println(encoder0Pos);
}
}
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
}
else
{
encoder0Pos = encoder0Pos - 1; // CCW
}
}
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
}
else
{
encoder0Pos = encoder0Pos - 1; // CCW
}
}
// 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
}
else
{
encoder0Pos = encoder0Pos - 1; // CCW
}
}
// 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
}
else
{
encoder0Pos = encoder0Pos - 1; // CCW
}
}
}
It is rude to hijack someone else's thread.
As a newbie - read the sticky guides to using the forum at the top of each section.
It will bear well as you become a regular participant on these pages.
Thread split.