By continuing to use this site, you agree to our use of cookies. Find out more
Forum sponsored by:
Forum sponsored by Allendale Oct 22nd

DRO Z-Axis /4th axis "combiner"

All Topics | Latest Posts

Search for:  in Thread Title in  
Kealan O'Carroll26/04/2019 17:42:16
9 forum posts
6 photos

Hi all,

I've recently added a Ali-Express DRO to my Archdale 18" Mill. I was facing the problem of only having one Z-Axis and not knowing whether to attach it to the knee or the quill, so I bought a 4th glass scale from the seller and added a scale to both axes.

The DRO display only has one input for each axis, so I got an arduino nano via ebay along with a small enclosure and some RS232 cables. The two input cables attach to the scales and the output goes to the DRO display. The arduino calculates which scale is moving in which direction, sums them for an absolute position and then outputs that to the display so both the knee and quill can move in opposite directions at the same time and the DRO Z-position will remain correct.

Component parts came to about a tenner + labour time of assembling it and figuring out the code. It's possible to move the scales fast enough to out-pace the arduino and 'lose' steps, but my scales are 1 micron rather than the usual 5 micron so that's effectively limiting the maximum speed by 1/5th and even at that it's still capable of keeping the position correct up to about 100mm/sec so as long as I keep the quill retract speeds sensible I think it'll be okay.

The arduino gets its power from the 5V output pin on the DRO which supplies the glass scales, so no batteries / plug is required.

I'm an absolute amateur when it comes to the arduino stuff so it may be possible for someone to make the code much more elegant / run much faster but this does me for now.

20190426_171735.jpg

Kealan O'Carroll26/04/2019 17:42:33
9 forum posts
6 photos

Code here:

 


/*
Code by Kealan O'Carroll, April 2019
Encoder.h library by PaulStoffregen
http://www.pjrc.com/teensy/td_libs_Encoder.html

Code intended for an arduino nano with the following wiring:
Pins 2, 4 : Scale 1 inputs
Pins 3, 5 : Scale 2 inputs
Arduino Pins 7, 8 : Outputs to DRO A and B pins. (Pins 6 and 8 on a DSUB9 type plug)

*/

#define ENCODER_OPTIMIZE_INTERRUPTS
#include
Encoder scale1(4,2); //Wire first scale A & B quadrature lines to arduino Pins 2 and 4
Encoder scale2(5,3); //Wire second scale A & B quadrature lines to arduino Pins 3 and 5
//If either of the scales reads in the wrong direction, reverse the pin numbers above (e.g. (4,2) changes to (2,4)

long pos2 = 0;
long pos1 = 0;
long delt = 0;
long oldpos1 = 0;
long oldpos2 = 0;
long delt1 = 0;
long delt2 = 0;
bool outA = LOW;
bool outB = LOW;

void setup() {
DDRD = DDRD | B11000000;
DDRB = DDRB | B000001;
PORTD = B00000000; // sets digital pins all Low
PORTB = B00000000; // sets digital pins all Low
}

void loop() {

pos1 = scale1.read();
pos2 = scale2.read();

delt2 = pos2 - oldpos2;
delt1 = pos1 - oldpos1;
delt = delt2 - delt1;

while (delt > 0) {
if (outA == LOW && outB == LOW) { //if 8 is low and 7 is low
PORTD = B10000000; //push 7 high
PORTB = B000000; //leave 8 low
outB = HIGH;
delt--;
}
else if (outA == LOW && outB == HIGH) { //if 8 is low and 7 is high
PORTD = B10000000; //leave 7 high
PORTB = B000001; //Push 8 high
outA = HIGH;
delt--;
}
else if (outA == HIGH && outB == HIGH) { //if 8 is high and 7 is high
PORTD = B00000000; //push 7 low
PORTB = B000001; //Leave 8 high
outB = LOW;
delt--;
}
else if (outA == HIGH && outB == LOW) { //if 8 is HIGH and 7 is LOW;
PORTD = B00000000; //leave 7 LOW;
PORTB = B000000; //push 8 low
outA = LOW;
delt--;
}
}

while (delt < 0) {
if (outA == LOW && outB == LOW) { //if both are low,
PORTD = B00000000; //leave 7 low;
PORTB = B000001; //Push 8 high
outA = HIGH;
delt++;
}
else if (outA == LOW && outB == HIGH) { //if 8 is low and 7 is high;
PORTD = B00000000; //push 7 low
PORTB = B000000; //Leave 8 LOW
outB = LOW;
delt++;
}
else if (outA == HIGH && outB == LOW) { //if 8 is high and 7 is low;
PORTD = B10000000; //push 7 high
PORTB = B000001; //Leave 8 HIGH
outB = HIGH;
delt++;

}
else if (outA == HIGH && outB == HIGH) { //if 8 is high and 7 is high;
PORTD = B10000000; //leave 7 high;
PORTB = B000000; //Push 8 LOW
outA = LOW;
delt++;
}
}
oldpos1 = pos1;
oldpos2 = pos2;
}

Edited By Kealan O'Carroll on 26/04/2019 17:44:17

SillyOldDuffer26/04/2019 18:52:27
4790 forum posts
1011 photos

I'm impressed Kevin, good idea and clever implementation.

Just a thought, the bit twiddling to drive the output makes the logic harder for others to follow and may not be necessary in this application. I suspect the main performance bottleneck is the Nano only having two external interrupt pins slowing the encoder library down. Likely the hardware and library are stopping your code following very fast traverses rather than your high-speed implementation. Might be possible to compute the output slightly faster, but I suspect switching to a processor with 4 external interrupts (like the Mega) would rocket propel the whole thing.

Have to say I'd be unbearably smug if I'd got that to work - well done you!

yes

Dave

Michael Gilligan26/04/2019 19:15:51
avatar
14158 forum posts
618 photos

If Dave is impressed ... just think how I feel

MichaelG.

Andy Carruthers26/04/2019 20:22:12
avatar
257 forum posts
23 photos

Very well thought out and nicely done!

Ian P26/04/2019 20:59:18
avatar
2224 forum posts
90 photos

I too am impressed. Apart from the original idea the execution is an wonderful example of something made in a cost effective, fit for purpose manner. It looks robust but not over engineered and even using moulded on connectors saves cost and time.

If I had two encoders (linear or rotary) on any axis I would want definitely one of these

Ian P

Neil Lickfold26/04/2019 21:25:23
573 forum posts
102 photos

I have a 3 layer read and also want a scale on the column. This will be useful indeed. Thank you so much for sharing.

Neil Lickfold

Les Jones 126/04/2019 21:32:15
2096 forum posts
144 photos

I built a similar device many years ago for my Seig X3 mill and find it very useful. Mine works with the original Chinese scales (2 x 24 bit protocol). Mine is based on a Pic16f628 with a 4 line by 20 LCD display, It displays the reading from each scale and the sum of the readings.

Les.

Paul Lousick27/04/2019 02:45:38
1199 forum posts
499 photos

Hi Kealan, I also want to fit a 4th scale to my mill.

My intention was to use a manual RS232 switch to change from the column scale to the quill scale and use my existing 3-axis display. The more expensive displays allow for a combined Z-axis reading but out of my budget.

Are you able to post details and circuit for your project. I have a little knowledge about electronics but know nothing about Arduino's.

Paul.

Les Jones 127/04/2019 08:38:29
2096 forum posts
144 photos

Hi Paul,
There is no real need for a circuit as Kealan gives the connections at the start of his program.
These are the lines that give the information.

Code intended for an arduino nano with the following wiring:
Pins 2, 4 : Scale 1 inputs
Pins 3, 5 : Scale 2 inputs
Arduino Pins 7, 8 : Outputs to DRO A and B pins.

The only other connections will be the power to the Arduino.

You will have to make sure that the signal level from the scales is the same as the signal levels on the version of Arduino that you use'

Les.

Edited By Les Jones 1 on 27/04/2019 08:42:47

Edited By Les Jones 1 on 27/04/2019 08:43:14

Kealan O'Carroll05/05/2019 09:35:56
9 forum posts
6 photos

Hi chaps,

As Les has said, the wiring is in the comments of the code, but Ive put a diagram below.
As per Dave's comment you might be better off with an arduino mega or something with 4x interrupt pins if you want it to run faster

wiring.jpg

All Topics | Latest Posts

Please login to post a reply.

Magazine Locator

Want the latest issue of Model Engineer or Model Engineers' Workshop? Use our magazine locator links to find your nearest stockist!

Find Model Engineer & Model Engineers' Workshop

Support Our Partners
Ausee.com.au
ChesterUK
Eccentric July 5 2018
Warco
Eccentric Engineering
TRANSWAVE Converters
cowbells
Meridienne; London MES
Allendale Electronics
emcomachinetools
Subscription Offer

Latest "For Sale" Ads
Latest "Wanted" Ads
Get In Touch!

Do you want to contact the Model Engineer and Model Engineers' Workshop team?

You can contact us by phone, mail or email about the magazines including becoming a contributor, submitting reader's letters or making queries about articles. You can also get in touch about this website, advertising or other general issues.

Click THIS LINK for full contact details.

For subscription issues please see THIS LINK.

Digital Back Issues

Social Media online

'Like' us on Facebook
Follow us on Facebook

Follow us on Twitter
 Twitter Logo

Pin us on Pinterest