Connecting Glass DRO Scales to The Controller

Tuesday, January 7, 2014

After the two posts describing the DRO setup for my Sieg X3 mill, I’ve received a ton of emails asking for more details. It appears that a number of people are having issues with the glass scales. Additionally, there has been a lot of interest in the simplified version of the interface board. I think a more detailed follow up is in order.

A Bit of Theory

Glass DRO scales are a form of an incremental quadrature encoder, as are magnetic scales and many shaft encoders. Although the physical implementation differs between the different types, the underlying principle is very similar. Most quadrature encoders use some sort of code track that consists of a series of equally spaced marks that move past one or more sensors. The changes in color, reflectivity or transparency cause the sensor’s reading to fluctuate. Depending on the design of the processing circuitry the output can have sinusoidal, square or “double ended” square form. By detecting and counting the a controller can infer the distance traveled and calculate the relative position or rotations per minute, etc.

Small optical encoder, using a graduated disk and an IR diode/phototransistor pair

To visualise how this work you can make a simple “device” as shown below. It’s a narrow piece of square-ruled graph paper with back stripes two squares wide, and another piece with two squares cut out that serves as a reader with two sensors. As you slide the stripe through the reader and count the number of times the first sensor reads “black”, you’ll be able to tell how far the stripe has moved. Now pay attention to what happens the second sensor at that moment. You will notice that if you move the stripe one way, the second sensor is white, but the if you pull the stripe in the other direction, the sensor will be black. Detecting change from white to black gives you resolution down to one inch (in this case), but if you implement a simple state machine and detect every transition on both sensors your resolutions will be 0.25”. In a nutshell this is precisely what happens inside the glass scales, except the stripe is much finer.

A crude implementation of optical encoder should help to visualize the principle at work

Practical Implications

There are several practical considerations that will influence your interface hardware when working with quadrature encoders. The most basic parameter is the working voltage of the scales. The vast majority of quadrature encoders I’ve encountered run at 5V, but there are some that run at 12V or 24V and even higher. As long as the voltage is higher than 3.6V or lower than about 2.6V, you will need to implement some sort of level shifting circuit. Second important characteristic is the output waveform. Most industrial grade encoders have built-in circuitry that conditions the signal from the sensors. The common glass scales that you’re likely to come across [on eBay, DRO Pros, etc.] output a clean square wave with 50% duty cycle, as do many rotary encoders. Some less expensive shaft encoders lack any signal processing circuitry. All they have inside is an optical disk, an infrared diode and two phototransistors, and if you’re lucky, they might have a current limiting resistor for the diode. If that is the case, the output from the two sensors will be sinusoidal and will need to be amplified and converted to a square waveform. It’s not uncommon for the levels to be different between the two channels as well.

Finally, some of the more expensive DRO scales use “double ended” output. In addition to the common A and B channels with 0V to 5V signal, there are two complementary channels, A’ and B’, whose outputs mirror that of the main channels with 0V to -5V signal. On the receiving end A is summed with A’ and B with B’, which cancels out any line noise. These scales are less common and more expensive but offer great noise resistance.

Interface Hardware

Interfacing quadrature encoders to the MSP430 Launchpad board can pose two kinds of problems. If the output voltage is too low (i.e. is lower than MSP430’s “high” threshold), the microcontroller will not detect or at least miss the pulses coming from the scales. On the other hand, if the voltage is higher than 3.6V, there is a really good chance that the microcontroller's inputs might be damaged.

Simple resistor voltage divider
(Image courtesy of Wikipedia)

The voltage shifter/Interface board described in one of my earlier posts was designed to take care of both issues. The LM339 comparators used on that board can handle pretty wide range of pulse voltages, convert sinusoidal waveforms to square waves and even filter brief line glitches. This way, as long as you provide the correct voltage to the scales and the comparator ground references, the board will output clean 3.3V pulses that are safe for MSP430. This flexibility comes at a cost of complexity, though, so for my DRO controller I decided to cut some corners. I know that the scales I was using output very clean square signal that won’t exceed 5V (because I’m providing regulated 5V from the power supply). As I said, it’s very important to bring that voltage to a level that will be safe for MSP430 microcontroller, but that can be done using a simple resistor voltage divider. The idea is to use two resistors connected in series between the scales output and the ground as shown in the schematic. If you choose the resistors so their values have a ratio of ⅔, the voltage at the “V out” point will equal 5V * ⅔, or 3V. For my setup I used 20 Kohm and 33 Kohm resistors, which converted the output to about 3.2V, which is almost ideal for the MSP430 microcontroller.

Connection

If you choose to use the simplified setup, you will need two such dividers per scale (one for each of the two channels). The values I choose were dictated by what I had in my resistor box. As long as the ratio stays close to ⅔, you have some wiggle room but I wouldn’t want to use resistors whose combined values are much lower than 5 Kohm. One caveat though: make sure that the divider is connected to the common ground or the voltage divider won’t work and you have a good chance of zapping your microcontroller.

Now the tricky part: there is no standard connection pinout. Different DRO manufacturers use different connector and different pinouts. When I was researching my Easson glass scales I discovered that even the scales from the same manufacturers can have different pin function. To be safe, you will need to obtain this information from the seller or the manufacturer.

Pin functions for my Easson DRO scales
(image courtesy of Easson)

Once you obtain the pin diagram, you will need to identify and connect the following lines:

LaunchPad's TP1 provides convenient 5V supply 
  • 5V - positive power supply to the scales (might be market Vcc). This line needs to be connected to TP1 on the Launchpad
  • 0V - “ground” for the scales circuitry. This pin needs to be connected to the Launchpad’s ground.
  • “Gnd” (or “Ground”) - this is the scale’s frame and can be connected to the same point the 0V is connected.
  • A and B - these are the two channels that will provide the pulses to the controller. These need to be connected [through a voltage divider] to the Launchpad’s input pairs. These are: P2.0/P2.5, P2.1/P2.4, P2.2/P2.3/ XIN/XOUT for X,Y,Z and W axes respectively. It doesn’t matter if you flip A and B lines for each pair, though. All it will do is invert the readout, but that can be changed in the TouchDRO settings.

48 comments :

  1. Howdy Yuriy,

    Excellent project and APP

    On the W axis what would be the pin connection for ttl quadrature scales?

    Thanks again!

    ReplyDelete
    Replies
    1. Take a look at this post: http://www.yuriystoys.com/2014/01/dro-interface-pin-functions-for-msp430.html
      Thank you
      Yuriy

      Delete
  2. Yuriy.
    This is a fantastic project, which I have looking at or a few months. I have a Cowells Mill which I am looking at fitting with magnetic scales. Basically because they are very very slim with small read heads. These are 5V TTL Quadrature devices and can get either 1 or 5 micron resolution. The connecting cableswith 9 pin serial connections. They have a 9 pin D type serial connector (pins 1=n/c, 2=0v, 3=n/c, 4=screen, 5=n/c, 6=A, 7=+5v, 8=B, 9=Z). Could you possibly clarify the resistor voltage divider connections with a schematic as I am struggling to fully understand how they are wired in.

    Many Thanks,

    Colin

    ReplyDelete
  3. Colin,
    Take a look at this Wikipedia article: http://en.wikipedia.org/wiki/Voltage_divider.
    You want R1 to be something like 200 Ohms and R2 300 Ohms. You will need a divider for each line (two per scale). That's all there is to it.
    Thank you
    Yuriy

    ReplyDelete
  4. Yuriy,
    I have 3 newall spherosyn scales and was told they are proprietary to their DRO displays . This scale has a round 7 pin connector with 5 wires actually connected to the pins: white, black, yellow, green and red covered with a braided shield. I have an oscilloscope and some test equipment if I could be led in the right directions to see if these scales would work with your design.

    It is awesome that people like yourself are willing to share your hard work that is put into these designs.

    Very much thanks,
    Steve

    ReplyDelete
    Replies
    1. Steve,
      There aren't that many formats out there. If you can find quadrature output on those scales, they will work fine with the "Quadrature" firmware.
      If your scope can do screen captures, I can probably help you more.
      Thank you
      Yuriy

      Delete
    2. Yuiry,
      Thank you for your reply.

      I spoke to the manufacture of new all today and was given the pin out of my scales.

      1 - Black Hi Drive Single
      2 - Yellow 1 Khz Single
      3 - Red +12v
      4 - White Lo Drive Single
      5 - Green 0v

      I was told that my scales (newall spherosyn M2G) do not have a quadrature output, but does produce a sine wave that is proprietary to their DRO heads. Could these scales work with one of your design.

      Thanks again,
      Steve

      Delete
    3. Yuriy,
      Did you have any thoughts on the newall scales.

      Steve

      Delete
    4. Steve,
      I wasn't able to find more info on the scales, but if they don't provide quadrature signal, there is no easy way to interface them with TouchDRO. There might be converters on the market, but they will likely be pretty expensive.
      Thank you
      Yuriy

      Delete
    5. Yuriy,
      thank you again for your reply. Would the Dro Pros magnet scales be compatible with your quadrature design. The reasone I ask than just go with the glass scales; after watching the Dro Pros video on youtube they seem to be accurate, low profile and can easily cut to fit. I'm looking for accuracy overall. I just started a machinist class and picked up a old clausing lathe on the cheap
      Steve

      steve

      Delete
    6. Yes. Z axis on my lathe uses a magnetic scale (5 micron resolution) and it works really well.
      Thank you
      Yuriy

      P.S. Congrats on the Clausing lathe. Those things are great.

      Delete
  5. Yuriy,
    Nice Website & Project! I was looking for something like this, and this seems perfect.

    I'm interested in the quadrature version, do you have a schematic of the overall interface between the encoders and the '430? I see it is described across a few of the pages, but an overall view would be very helpful.

    If not, no big deal, just thought I'd ask.

    Thanks,
    Pete

    ReplyDelete
    Replies
    1. Pete,
      No, I haven't made one. If I get to it some time soon, I will post in here.
      Second image on this page http://www.yuriystoys.com/2013/10/voltage-shifter-circuit-for-mixed-scale.html has the schematic for one axis, though. The rest are identical.
      Thank you
      Yuriy

      Delete
    2. Hi again. I built up a quick demo version of your design, and it works quite well. I need to package it nicer, but wanted to be sure before investing too much time. One quick question, on your qudrature implementation do you count each edge high and low going on both channels as a true quadrature? Some scales spec lines per mm or inch, but if you count each edge transition it is actually four times that. I have a set of DC scales where I noticed that and just wanted a sanity check. I read through your posts but didn't catch that anywhere. Thank you too, nice project. I just need to find the time to finish cleaning get it up and install it permanently. Thanks again.

      Delete
    3. Hi,

      Any chance you could post a photo or diagram of the quadrature version. The basic and mixed scale are easy to understand as there are photos available, but I am having trouble with the quadrature version. Thank you

      Delete
    4. HI,
      Did you see this page: http://www.yuriystoys.com/p/msp430-launchpad-quadrature-dro.html ?
      There are several links to posts with more details.
      Thank you

      Delete
    5. Hi,

      Yes I have seen it, all it seems to mention is the voltage shifter circuit using theLM339 Comparator, which I don't think is needed for the glass scales? I am using ditron scales.

      You mentioned the resistor voltage divider, which I believe I need to use 4 resistors in total on each axis, 2 will be for A channel and 2 will be for B channel.

      But in the parts list it mentions you need 4 300 ohm and 4 200 ohm, so it has me a little confused.

      Thank you

      Delete
    6. Hi,
      4 of each would be for 4-axis setup. For 3 axes you'd need only 3 each.
      For Ditron scales you can use any two resistors with 3:2 ratio.
      Thank you
      Yuriy

      Delete
    7. Hi,

      You mentioned this above "If you choose to use the simplified setup, you will need two such dividers per scale (one for each of the two channels)"

      So going by this 8 300 ohm and 8 200 ohm are needed for a 4 axis setup.

      Thank you

      Delete
  6. Yuriv,
    I would like to interface 3 easson glass scales with Mach 3 cnc, can you post the schematic for the comparator/schmidtt trigger circuit?

    Thanks,
    Max

    ReplyDelete
    Replies
    1. Yes, you're right.
      Apparently I can't do preschool arithmetic :)

      Thank you
      Yuriy

      Delete
  7. I am trying to build a DRO using a MSP430 connected via USB and have a couple of questions.

    The scales I bought are glass type with a generic no name but model is JCXF5 from thedrostore.com. I built the voltage divider but the voltage I was measuring on the output was 2.2V. The output before the divider is 3.4V, the scale is getting 5V input. I also bought a USB To TTL Adapter/Converter PL-2303HXA to connect to the tablet.

    When I first connected it to the tablet after changing the settings to USB connection and 9600 baud and trying to connect Android DRO crashes to the desktop. Trying to see what was working I connected to a windows PC using hyperterminal, all that came up was x0,y0,z0,w0 over and over again.

    Thinking the voltage divider is not needed due to the 3.4V output of the scales I jumpered them and plugged straight into the MSP430. Now on hyperterminal the x gets a number when I move the scale. So everything there must be working.

    So my questions are. Do some scales input 5V and output 3.4V or am I measuring incorrectly? (I am measuring from ground on the MSP430 to A or B on the scale output pin.

    Why is Android DRO crashing when connecting via USB? I am running android 4.0.4, it is a Galaxy tab 10.1.

    Is the PL-2303HXA chip suitable for usb connection to the MSP430?

    Can I power the MSP430 through the USB to TTL adapter as it seems to work that way when connected to the PC?

    ReplyDelete
    Replies
    1. Richard,
      PL-2303 is not supported. The USB driver literally support only *some* Arduino boards and the FTDI chip that comes on the older one. That's it. USB support is very rudimentary and I'm actually seriously considering removing it from the next version. It creates more problems than it's worth.
      In your case you have a Bluetooth-enabled tablet, so there is no reason to use USB.
      Regards
      Yuriy

      Delete
    2. I was not planning on using the Galaxy Tab 10.1 as it is my house tablet. I purchased a cheap chinese one that does not have bluetooth built in. It needs a power supply I am waiting on so I tried the galaxy tablet as a trial run. As these cheap tablets tablets can be bought new for under $30 I was going to make it a permanent installation and try to connect through USB.

      Delete
    3. OK, that makes more sense. In that case you want to get a FTDI232 breakout board (from sparkfun, for example). There is a number of those with "fake" FTDI chips on them, so try to get one from a reputable source, though.

      Delete
    4. Thanks, I have ordered one of them and will see how it works. I did think of trying a USB bluetooth dongle, but research indicated this tablet does not have the necessary drivers installed and to install drivers in Android means you have to rebuild the whole operating system.

      Delete
  8. Would one of these work to step the 5V signal from the scales to 3.3V for the controller?

    https://learn.sparkfun.com/tutorials/bi-directional-logic-level-converter-hookup-guide

    ReplyDelete
  9. This is very interesting and useful information. Thank you very much!
    Does anyone here have experience with Futaba CJ glass scales and how to interface them?

    Thanks.

    ReplyDelete
  10. Sir;
    Since you are a genius at programming etc. Would it be possible to use the onboard ADC to read scales with sine / cos output allowing interpolation between steps. I can send you a few scales to experiment with.....

    ReplyDelete
    Replies
    1. Gernoff,
      No, the chip doesn't have the "horse power" to do the interpolation fast enough. Your best bet is used interpolation box(for example Heidenhain EXE 610 or alike). They aren't cheap, but I've seen quite a few go under $100 on ebay.

      Delete
  11. My experiences so far on connecting via USB to the MSP430 via a cheap cheap tablet.

    I do have it working. I used this to connect to USB. http://www.ebay.com/itm/251996323186

    Connected it up the same as a bluetooth module.

    As this tablet wants to power the MSP430 through the USB cable, I cut the +5V line on the USB cable.

    The tablet would not recognise it so I downloaded this app https://play.google.com/store/apps/details?id=com.ftdi.j2xx.hyperterm and installed. Connecting the usb cable and the app wanted to open the port, so I cancelled that, opened DRO and put the settings to USB, clicked connect and the app crashed with an error message, then connected and worked as it should.

    I cannot get the voltage divider to work as the diagram shows, but I have been told 2 red LED's in series will drop the voltage down to around 3V.

    ReplyDelete
  12. Can any one tell me how to determine which wire is which?

    Or would someone do a resistance map of their DIN7 ie the resistance between all pin combinations so I can compare it to my scales. Elt made by Elbo of Italy.

    ReplyDelete
  13. I was looking into DROPROS magnetic scales. Their site indicates the particular protocol they use, being RS422. It appears there are Arduino shields specific to this manner of signal. Have you investigated if such a combination would work to enable that chipset to work with these scales? In reading your site I don't think I've come across the reason why we must use the MSP430. Or rather I haven't seen why an Arduino is incompatible.

    ReplyDelete
    Replies
    1. You don't need to use MSP430.I chose MSP430 because it's easier to write code for and debug than Arduino and costs a lot less. I'm sure the decoder chips will work just fine with Arduino, but I don't have time to write code for it. With that said, building a controller with MSP430 and six voltage dividers (two resistors each) will cost about $20 (USD) for the Launchpad, BT module and size resistors. Arduino itself is $30 and the shields I've seen cost about as much as well for two axes.
      Regards
      Yuriy

      Delete
    2. It seems the uno board and bt module to which your site links are on sale at present. That puts the cost for those at $22. The shield I found is $15.

      https://www.tindie.com/products/Conceptinetics/rs485-rs422-shield-for-arduino/

      Reading the specs on the shield seems to indicate its usefulness in industrial networks, supporting up to 256 devices. A cursory search on serial based networks like profibus indicates that in this kind of setup only one device can transmit at a time. In a multiple axis setup I would expect the need is to handle the input signals simultaneously. Do you have any advice offhand as to how this board might function given multiple axes?

      I suppose this is where I need to gain more experience. I haven't done much with the hardware level to date. I may just go ahead and purchase this setup just to experiment with Arduino programming. I can fall back on the MSP430 if it doesn't work out.

      Delete
    3. That shield wont work for the scales. You need this kind of shield: http://www.robogaia.com/3-axis-encoder-conter-arduino-shield.html
      Basically you need quadrature decoders (counters), and if you wan to use differential signal, you'll need differential line receivers in front of the counters.

      Delete
  14. Hi,
    how about measuring speed? For example, if I connect to your quadrature board 3 scales with resolution 2um. What is maximal measuring speed in axis? Thank you. Konstantin.

    ReplyDelete
    Replies
    1. Konstantin,
      I tested the firmware with 16 KHz signal. Pre-made board (which uses proper input stage) can go faster. That gives you at least 32mm/second with 2 micron resolution.
      Regards
      Yuriy

      Delete
  15. Hello Yuriy,

    I love your project, and have been reading through it for a couple days now. Before I pull the trigger and order these scales. http://www.ebay.com/itm/172615641284?_trksid=p2060353.m1438.l2649&ssPageName=STRK%3AMEBIDX%3AIT

    I was curious if these would work https://www.amazon.com/gp/product/B00LUU9RG2/ref=ox_sc_act_title_1?ie=UTF8&psc=1&smid=A1THAZDOWP300U

    else would I have to pin-out to make sure of the proper connections.
    https://www.amazon.com/uxcell-Terminal-Adapter-Connector-Breakout/dp/B00WW6P636/ref=sr_1_sc_3?s=electronics&ie=UTF8&qid=1492728932&sr=1-3-spell&keywords=dsb+pin+out

    I'm looking to purchase your assembled 'Adapter Board Only' and am hoping that I don't require any further assembly. To clarify, would I need to make a voltage shifter as well? I'm looking into doing the X, Y, and two scales on the Z axis. One for the quill, another for the lower knee.
    Eventually looking into the tachometer function.
    It's stated the board has that function. Would it work with an NPN Hall sensor. Something like this? http://www.ebay.com/itm/Blue-4-Digital-LED-Tachometer-RPM-Speed-Meter-NPN-Hall-Proximity-Switch-Sensor-/282354914039?hash=item41bdaa12f7:g:rM0AAOSwtfhYm9Fw

    ReplyDelete
    Replies
    1. William,
      Either DSUB9 connector will work. First one is board mount, so soldering to it will be a bit fiddly.
      That tachometer setup will be way too complicated. First of all, the sensor needs 12V IIRC to work properly.
      Regards
      Yuriy

      Delete
    2. Thank you,

      The assembled board would already have the D9's installed correct?
      As well as the fourth axis input would function as my secondary Z. Allowing both quill and knee to be computed?

      Delete
  16. Hello! I'm building the mixed scale controller with voltage shifter, and will use it with chines scales. But in the text you say that you tested with glass scales also. And you say that the 1000uf capacitor is for glass scales.

    But the glass scales isn't supported yet?
    Quote: "The hardware is designed to work with 5V quadrature encoders [glass scales] but the firmware doesn’t support their input yet."

    When is the firmware ready for glass scales?

    ReplyDelete
  17. Hello Yuriy, thanks for teh excellent writeup! I just have a quick question... I'm trying to interface to an Easson glass scale with an Arduino Mega. I get the quadrature decoding on channels A and B (with ref. to your DSUB 9 image) using pin interrupts, but can you tell me what the R channel is used for? I see from the datasheet that it provides an infrequent pulse but can't find any clue on what extra information can be gained. Can you help?

    Best,

    Tim

    ReplyDelete
  18. can you name the motor that you used in first picture?

    ReplyDelete
    Replies
    1. That was a custom HP printer motor. I don't remember what model of printer it came from.

      Delete
  19. Yuri:

    I've just ordered your Quadrature controller for use with my Easson clone scales. My scales use the 422A connection. My question is do I also need to build the voltage shifters for each scale?

    It's possible that I've mis-read, or misunderstood various posts that I've found on your site. One of those "read everything" but I don't have the background knowledge to know if the "2013 posts" apply to the "2019 controller board".

    Thanks again for your time and expertise,

    Chris D.

    ReplyDelete
  20. HI Yuri, Does the mixed scale firmware cater for mixing quadrature with other types of scale? I have a lathe I want to fit a glass scale to the cross slide and a cheap Chinese scale to the saddle. Greta app and site by the way. Thanks Geoff

    ReplyDelete
  21. Any chance your magic box can go from single sine wave to quadrature?

    ReplyDelete