DC motor control with absolute encoder


I have a motor with encoder. 3 of the 5 cable to receive our engine (blue-orange-yellow) of the DC motor encoder cable for the other two power inputs. 5 V encoder supply Orange, Blue graund, Yellow Encoder signal output. I do not know how to do this I want to read the speed of the motor. I found an example similar to this but this is the one for 2 channel. Absolute encoder on how to speed read? Thank you in advance for your help.

/* Read Quadrature Encoder * Connect Encoder to Pins encoder0PinA, encoder0PinB, and +5V. */

int val; int encoder0PinA = 3; int encoder0PinB = 4; int encoder0Pos = 0; int encoder0PinALast = LOW; int n = LOW;

void setup() { pinMode (encoder0PinA,INPUT); pinMode (encoder0PinB,INPUT); Serial.begin (9600); }

void loop() { n = digitalRead(encoder0PinA); if ((encoder0PinALast == LOW) && (n == HIGH)) { if (digitalRead(encoder0PinB) == LOW) { encoder0Pos--; } else { encoder0Pos++; } Serial.print (encoder0Pos); Serial.print ("/"); } encoder0PinALast = n; }

http://robotus.net/wp-content/uploads/2012/07/japan-servoco-encoder-motor.jpg http://catalog.nidec-servo.com/digital/english/general/pdf/DME34_4.pdf

You will need to find the interface specification for your particular 'absolute encoder'. Do you have the manufacturer and model number of the motor or encoder? Do you have an oscilloscope you can use to look at the encoder signal? Without more data it's impossible to guess what might be coming out that wire.

MODEL: DME34BE50G Company: Japan Servo CO LTD. Web Site: http://catalog.nidec-servo.com/digital/english/general/b_dme/

Motor Feature: http://catalog.nidec-servo.com/digital/english/general/pdf/b_dme_ftrs.pdf ( Mine the Optical Revolution Sensor ) Technical Data: http://catalog.nidec-servo.com/digital/english/general/pdf/b_technical.pdf Catalog: http://catalog.nidec-servo.com/digital/english/general/pdf/DME34_4.pdf Figure: http://robotus.net/wp-content/uploads/2012/07/japan-servoco-encoder-motor.jpg

I don't have an oscilloscope :(

The catalog says that the ‘BE’ means an optical rotation sensor. The catalog says that the optical sensor gives 24 pulses per revolution. It is not an absolute encoder. It is not even a quadrature encoder. It will tell you how fast the motor is turning but not which direction. To measure speed, look for the time between pulses or the pulses over a time interval.

Blue is Ground
Orange is +5V Power
Yellow is pulse output

Here’s some example code that might help in calculating RPM from the pulses:

volatile unsigned long time = 0;

const int countsPerRevolution = 4;

const int rpmCount = 5;
int rpmArray[rpmCount];
int rpmIndex = 0;
int rpmTotal = 0;

void setup()
  //Digital Pin 2 Set As An Interrupt
  attachInterrupt(0, fan_interrupt, FALLING);
  for (int i=0; i<rpmCount; i++)
     rpmArray[i] = 0;

  Serial.println("Current RPM:");

//Main Loop To Calculate RPM and Update LCD Display
void loop()
  int rpm = 0;
  if(time > 0) {
    rpmTotal -= rpmArray[rpmIndex];
    rpmArray[rpmIndex] = 60000000UL/(time * countsPerRevolution); 
    rpmTotal +=  rpmArray[rpmIndex];
    rpmIndex = (rpmIndex+1) % rpmCount;
    rpm = rpmTotal / rpmCount;

//Capture The IR Break-Beam Interrupt
void fan_interrupt()
  static unsigned long time_last = 0;
  unsigned long now = micros();
  time = (now - time_last); 
  time_last = now;

Thank you so much, you are king :)