Output of a TTL Linear Glass Scale

Thread Starter

Dritech

Joined Sep 21, 2011
869
Hi all,

I am planning to buy a TTL Linear Glass Scale digital-readout (similar to this)

I intend to wire the scale directly to a microcontroller instead of using the DRO Below proceeding with interface.
Before purchasing, I would like to know the actual pin-outs and ways of how I can interpret the output as a value of measurement.
Does anyone have any experience with using these TTL linear glass scales?
 

kubeek

Joined Sep 20, 2005
5,731
No experience, but for simplicity and reliability I would expect quadrature output. Step/direction might be another possibility, but would be way more susceptible to noise from the machine. Last viable would be a serial connection, but that I would guess would spit out absolute position and require more cooperation in processor in the scale, but I think that is used only in digital calipers that actually have the button to reset the reading to 0.
 

MaxHeadRoom

Joined Jul 18, 2013
21,201
If it says TTL then it is most likely and usually 2 channel optical in quadrature output.
There is the Pic 2331/4431 for e.g. that has a MFM, Motion Feedback Module for quadrature interpretation.
I have worked with scales for some makes, the manual should have the pin-out.
Max..
 
Last edited:

LesJones

Joined Jan 8, 2017
2,687
I agree with Max that they are almost certainly quadrature outputs. They DO NOT give absolute position. You use the outputs to increment a counter when they move in one direction and decrement it when it moves in the other direction. The resolution of the scales governs how far they move for each increment / decrement of the counter. I have used a PIC16F690 to decode quadrature signals.

Les.
 

Sensacell

Joined Jun 19, 2012
2,587
Do chose an MCU that has dedicated encoder hardware ( Mchip parts with QEI for example) which makes the task of keeping up with encoder signals easy.

High-resolution scales output rather high-frequency pulse trains, it's hard to avoid missing counts with software polling/interrupt techniques.
 

DNA Robotics

Joined Jun 13, 2014
571
As Max said, It is quadrature output on A, B & ground. There is a pinout toward the bottom of that link.

I have done that a few times. The best was recently with an Arduino Nano and this LCD.

Serial 2 X 16 LCD Display for Arduino Item #: 31164 MP Sale: $8.95

It is accurate even as fast as I can move the table. EXCEPT, if the scale is right on the transition edge, machine vibrations can make it count a lot of erroneous pulses. Here is the whole sketch. Modified for this application. If you can fix that problem, please send it back to us.
More info here Arduino Quadrature Decoder digital readout
You will need the digitalWriteFast.h and LiquidCrystal_I2C.h libraries.

C:
/*
*Quadrature Decoder
*/
#include "Arduino.h"
#include <digitalWriteFast.h>  // library for high performance reads and writes by jrraines
  // see http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1267553811/0
  // and http://code.google.com/p/digitalwritefast/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display
//LiquidCrystal_I2C lcd(0x20,16,2);  // Alternate LCD address of 0x20 if 0x27 doesn't work
//LiquidCrystal_I2C lcd(0x3F,16,2);  // Alternate LCD address of 0x3F if 0x27 doesn't work
// It turns out that the regular digitalRead() calls are too slow and bring the arduino down when
// I use them in the interrupt routines while the motor runs at full speed.
// Quadrature encoders
#define InterruptA 0
#define InterruptB 1
#define PinA 2
#define PinB 3
volatile bool ASet;
volatile bool BSet;
volatile bool APrev;
volatile bool BPrev;
float Ticks = 0;
float OldTicks = 0;
void setup()
{
  lcd.init();  // initialize the lcd
  lcd.backlight();
  Serial.begin(9600);
  // Quadrature encoders
  pinMode(PinA, INPUT);  // sets pin A as input
  pinMode(PinB, INPUT);  // sets pin B as input
  attachInterrupt(InterruptA, HandleInterruptA, CHANGE);
  attachInterrupt(InterruptB, HandleInterruptB, CHANGE);
// So it starts with current condition
  ASet = digitalReadFast(PinA);
  APrev = ASet;
  BSet = digitalReadFast(PinB); 
  BPrev = BSet;
 
Ticks = 0;
}
void loop()
{
//  Serial.print("Encoder Ticks: ");
//  Serial.print(Ticks);
//  Serial.print("\n");
  lcd.setCursor( 0, 0 );  //Top left
  lcd.print(Ticks * 0.00019685 ,4);  // To 4 decimal place 1/5080 on linear scale
  lcd.print(" Inches ");
  lcd.setCursor( 5, 1 );  //Second row left
  lcd.print(" MM "); 
  lcd.print(Ticks * 0.005 ,3);  // To 3 decimal place 25.4/5080 on linear scale 
  lcd.print("  ");
OldTicks = Ticks;
}
// Interrupt service routines for the A quadrature encoder Pin
void HandleInterruptA(){
  BSet = digitalReadFast(PinB);
  ASet = digitalReadFast(PinA);
 
  Ticks+=ParseEncoder();
 
  APrev = ASet;
  BPrev = BSet;
}
// Interrupt service routines for the B quadrature encoder Pin
void HandleInterruptB(){
  // Test transition;
  BSet = digitalReadFast(PinB);
  ASet = digitalReadFast(PinA);
 
  Ticks+=ParseEncoder();
 
  APrev = ASet;
  BPrev = BSet;
}
int ParseEncoder(){
  if(APrev && BPrev){
  if(!ASet && BSet) return 1;
  if(ASet && !BSet) return -1;
  }else if(!APrev && BPrev){
  if(!ASet && !BSet) return 1;
  if(ASet && BSet) return -1;
  }else if(!APrev && !BPrev){
  if(ASet && !BSet) return 1;
  if(!ASet && BSet) return -1;
  }else if(APrev && !BPrev){
  if(ASet && BSet) return 1;
  if(!ASet && !BSet) return -1;
  }
}
 
Last edited:

Reloadron

Joined Jan 15, 2015
5,608
One of the pages for the scale shows the DB 9 pin out.
1 is +5V
2 is 0V
3 is A
4 is B
5, 6, 7, 8, and 9 are blank (no connection)

Each etched glass scale is for a different axis such as X, y, and Z axis. So that is the pin out for the linked scale. All scales are not the same.

Ron
 

MaxHeadRoom

Joined Jul 18, 2013
21,201
You can also get them with a fiducial marker at one end of the scale, this is essentially a return-to-zero point for power up reference.
Max.
 

Thread Starter

Dritech

Joined Sep 21, 2011
869
Hi all, thanks a lot for the useful information. I will buy the scale and monitor the outputs. So an Arduino is not recommended for capturing the output of this encoder?
 

DNA Robotics

Joined Jun 13, 2014
571
What I posted there for you works fine with Arduino Nano except for the vibration issue, which will be there on any micro controller. BUT, your machine is probably tighter than mine. It may not be a problem for you.
 

MaxHeadRoom

Joined Jul 18, 2013
21,201
Vibration is usually caused by backlash, CNC machines that use scales as well as motor encoders, split the PID loop between the scale and the encoder, this reduces or eliminates the 'hunting' effect when backlash is present..
Max.
 

AllTech

Joined May 11, 2020
1
Hello,

Just a little word to say you a big thank you for sharing this code! I modified it with direct port manipulation to try to optimize as much as possible, and it now decode an axis of my milling machine! Despite the machine being old and big (1T600), and the fast travel really fast, it is not missing a single step in 500mm.

Kudos to you!
 
Top