Rotary Encoder B-106-23983 how to read??

LINIX Brushless, VEXTA Brushless, RC Servo, DC Geared, Linear, Stepper, Tamiya.....

Rotary Encoder B-106-23983 how to read??

Postby fendy90 » Tue Nov 20, 2012 9:24 pm

hey there, im using arduino in coding the (Rotary Encoder B-106-23983,
1.is there any coding for arduino to determine or serialprint out the RPM of the encoder?
2.what is the value coming out from the yellow wire as shown in data sheet?? is it value of pulse frequency?
im currently using this code
CODE: SELECT_ALL_CODE
int ledPin = 13;                // IR LED connected to digital pin 13
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
int val1 = 2;

// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void rpm_fun()
{
   //Each rotation, this interrupt function is run twice, so take that into consideration for
   //calculating RPM
   //Update count
      rpmcount++;
}

void setup()
{
   Serial.begin(9600);
   lcd.begin(16, 2);  // intialise the LCD

   //Interrupt 0 is digital pin 2, so that is where the IR detector is connected
   //Triggers on FALLING (change from HIGH to LOW)
   attachInterrupt(0, rpm_fun, FALLING);

   //Turn on IR LED
   pinMode(ledPin, OUTPUT);
   pinMode(val1,INPUT);
   digitalWrite(ledPin, HIGH);
 

   rpmcount = 0;
   rpm = 0;
   timeold = 0;
}

void loop()
{
   //Update RPM every second
   delay(1000);
   //Don't process interrupts during calculations
   detachInterrupt(0);
   //Note that this would be 60*1000/(millis() - timeold)*rpmcount if the interrupt
   //happened once per revolution instead of twice. Other multiples could be used
   //for multi-bladed propellers or fans
   rpm = 30*1000/(millis() - timeold)*rpmcount;
   timeold = millis();
   rpmcount = 0;

   //Print out result to lcd
   lcd.clear();
   lcd.print("RPM=");
   lcd.print(rpm);
   Serial.println(rpm);

   //Restart the interrupt processing
   attachInterrupt(0, rpm_fun, FALLING);
  }
fendy90
Greenhorn
 
Posts: 2
Joined: Tue Nov 20, 2012 8:03 pm

Re: Rotary Encoder B-106-23983 how to read??

Postby low5545 » Thu Dec 06, 2012 5:53 pm

The rotary encoder have 3 outputs, A, B and Z. Both A and B will output 500 pulses per revolution. But by comparing both A and B you can know whether it is turning CW or CCW (refer to User Manual). According to the user manual, Z just outputs 1 pulse per revolution, suitable for simple projects.

To get the speed in RPM, you need to measure the time interval between each pulse from A/B. As we know, A/B outputs 500 pulses per revolution. So for each pulse it runs 0.002 revolutions (1 rev/500). Therefore dividing 0.002 by the time interval (in seconds) you will get the RPM.

Hope this helps!
low5545
Discoverer
 
Posts: 70
Joined: Wed Jul 27, 2011 5:55 pm
Location: Kuala Lumpur


Return to DC Motor

Who is online

Users browsing this forum: No registered users and 4 guests

cron