Coupler Upgrade

by Ivan Hamilton 3/31/2009 7:49:00 PM

I was keen to attach my home brew servo motors and see the mill move. The shaft on the mill's screws is 17mm, whilst the motor's 12mm shafts are designed for a small chain gear (small section of keyed  shaft and a left hand thread), and I needed to grasp below this.

Since I'm coupling the motor directly to the shaft, a figured a coupler with a little flex was in order. My immediate solution was some vinyl hose and a pair of hose clamps. Affixing and tightening the coupler was tricky. The uneven shaft sizes (17mm & 12mm) made it difficult, and I destroyed several hose clamps trying to get it tight enough. That would work for a little while, but it wasn't able to handle the torque and would eventually twist in the middle. I added some support in the middle with a section of hard plastic tube to help prevent this.

But the length of the vinyl tube was too great, and its twisting added extra backlash to the system. Not only that, the backlash amount was unpredictable, increasing during use as the vinyl warmed up. It was always meant to be an interim solution, and the purchase of a 1m length of Ø40mm acetal rod ($55AUD) was the start of something better.

Technically, this was my first CNC machining experience. It was only 2 axes, and involved numerous manual interventions, but to see it moving automatically to perform the desired machining operation was very rewarding.

I've already made two couplers (X & Y), and shortly will make a third to automate the quill (Z). With that, I'll have full 3 axis control and should only need to stop for tool/fixture changes.

Currently rated 1.5 by 150 people

  • Currently 1.476735/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


CNC | Mechanics

DIY Servo Controller - Initial Mill XY Test

by Ivan Hamilton 9/13/2008 7:35:00 PM

After months of putting it off, I jumped in and slapped two motors on to my mill.

I've already identified that the XY mechanisms on my mill aren't going to be up to the task (they have excessive backlash in both the bearing mount & the nuts).

Therefore, it's not worth spending too much time on the installation, as I'll need to redo it when I upgrade the mechanisms. I still hadn't done a "real world test" on my DIY servos & controller, and was keen to see the mill's table move.

Enter the angle grinder, 2 short pieces of RHS and some hose clamps...

So, what did I learn?

Keyboard: The wireless flexible keyboard I got is great. Chuck it where you need it.

Current Draw: It's not unusual in my 1:1 setup to see the motors draw 10A @ 12V. Hopefully this should drop when we switch to 36V. w

H-bridge Temperature: The H-bridge chips got hot. Real hot. I couldn't keep my finger on the heat sink, hot. Since pairs of H-bridges share heat sinks, I swapped the Y axis onto a different pair than the X axis. Then they both got hot... How hot? Not that hot: 57°C. I put a small fan near and let it continue to run: 32°C (ambient was 25°C). Not neccessary, but a larger heat sink or small fan would keep it cool.

PID Tuning: The inertia & friction of the table's screws changed the tuning requirements quite dramatically.

Encoder Inputs: Since I only used 2 of 4 servo channels on my controller, the other 2 encoder inputs were left floating. Phantom transitions on these lines fire interrupts and unnecessarily consume controller time.

Limit Switches: This was a simple test, and no limit switches were installed. Luckily, the flexible coupling slipped when it attempted to go beyond the table's travel. Limit switches are a must.

DIY Flexible couplings: OK, small length of hose with hose clamps. While there is some twist in the soft hose I used, when you consider the 0.2mm of existing screw backlash (@ 3mm/rev) equals 24°, the <10° of hose twist & <6° of servo error is quite acceptable (for now).

The Z axis hasn't had anything done yet, but that's OK. Baby steps. Although it would be easier, I don't want to automate the quill since it's got a lot of play in its rack & pinion setup. I should get moving on the ball screw upgrade and automate the column.

Even with only the X & Y axes done, the machine is transformed. I'm happy to perform any required Z movement manually for the time being.

All in all... I'm pleased, and it's quite exciting (chips will fly soon).

Currently rated 2.1 by 18 people

  • Currently 2.055556/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


CNC | Electronics | Mechanics

My Cordless Drill - Death of nickel-cadmium (NiCd), arrival of lithium-ion (Li-Ion)

by Ivan Hamilton 7/10/2008 11:48:00 AM

A few years ago low-cost rechargeable drills/drivers hit the market. I purchased a nice GMC 18V driver with two batteries.

It's given good service over the years, but:

  • the batteries don't hold as much charge as they used to
  • the batteries don't hold their charge as long as they used to
  • recently, the "charger" (timer & battery clip) died
  • recently, the plug-pack transformer died

The drill itself is perfectly fine, and I've worked around the charger & plug-pack issues, but the time had come... the batteries died completely.

Professional cordless tools often have replacement parts available, but my drill was only a consumer level item and years later, is completely superseded. A number of people have had success rejuvenating cordless tools by "repacking" the batteries. Often, the battery packs for these tools consist of a number of series wired "Sub-C" cells (18V = 15 x 1.2V Nickel-cadmium cells). At $3-$5 per Sub-C, that's $90-$150 for both packs. After making such an investment, a much smarter (and safer) charger would be justified. If the charger is not "smart" (i.e. it cannot detect when the battery is fully charged), then overcharging is likely, which will damage the battery.

With a new 18V drill + two batteries available for AU$99, repacking didn't make economic sense. Armed with the experience from my first, my wish-list was:

  • 18V - I like the power from the 18V driver, and want to keep that. 
  • Geared - My ungeared driver wasn't fast enough for drilling wood or plastic, but I still need power for driving screws.
  • Low self discharge - Sometimes I won't use it for weeks, I want it ready to go.
  • Smart charger - If I need to charge a half used battery for use tomorrow, I want to not think about it (and not  damage the batteries).
  • No hammer action - Even with the hammer action disabled, hammer drills have an amount of axial play that interferes with accurate bit placement.

Any geek worth his salt knows a little about batteries (phones, laptops, etc): Nickel-cadmium (NiCd) then nickel metal hydride (NiMH) then lithium-ion (Li-Ion) then lithium ion polymer (Li-Poly) cells. The latest professional cordless power tools have started to use lithium-ion (Li-Ion), and in my scouting around I found the Bosch PSR 18 LI-2.

What do I like?

  • At AU$250, it's much cheaper than other Li-Ion drills on the market at the moment.
  • The lithium-ion battery is only about half the size & weight of comparable NiCd batteries.
  • 18V power
  • 2 speed gearbox
  • 85 percent of the charge is retained, even if it has not been used for four months.
  • Charging station is automatically switched off when the battery is fully charged (with no memory effect, these batteries can be recharged at any time without reducing their charge capacity.
  • Interrupting the charging procedure does not damage the battery.
  • Not a hammer drill (no axial play)

With all the smarts included to prolong the life of the battery, I figure it should give twice the value of a $99 Nickel-cadmium (NiCd). Time will tell...

Currently rated 1.7 by 66 people

  • Currently 1.666666/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Mechanics | Pragmatism

DIY Servo Controller - Four Axis Tangential Test

by Ivan Hamilton 5/19/2008 2:57:00 PM

I've setup Mach3 to drive the 4th axis tangential to the XY plane. This feature is used by vinyl cutters and such where the tool's orientation must follow the direction of travel. This includes lifting the tool before large changes (>45°), and lowering it before continuing.

This setup allows me to test my 4 axis servo controller in a "real world" situation. The motion appears a little jerky, but this appears to be Mach3 coming to a full stop before changing the 4th axis' direction (The RoadRunner test is not good for this since it's composed of lines and not arcs).

I've started making the mounts for the motors, but there is more tuning and testing to be done before final mounting of these motors on the mill.

When I'd picked up the motors, they had some heft. So out of interest, I put those motors on the scales... a total of 3kW (4HP) and 16.5kg (more than airline carry-on allowance).

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


CNC | Electronics | Mechanics

'Cause one's not enough; I ain't a wimp, I'm a pimp.

by Ivan Hamilton 5/4/2008 3:59:00 PM

With another motor available for testing, I decided to configure my controller to run two motors. I also mounted the motors, so they wouldn't roll under acceleration and fall on the floor (again).

Ooh... two motors. Yeah... my servo controller can run more than a single servo. The Pololu driver board I have has two H-bridges, so with 1 controller board and 1 driver board, I can control two motors.

I also fixed a bug in the quadrature decoding routines that was causing incorrect amounts of movement to be calculated. To see if something had changed, I was incorrectly comparing the current raw quadrature state against the previous decoded state. Whoops!
With my 1,200 step encoder, now moving 1,200 steps now gives one clean rotation. Do 120,000 steps and you get 100 rotations, stopping at the exact same spot.

The PID parameters still aren't tuned. Hence the overshoot and slow final approach. I'm yet to even start working out a simple reliable tuning method. I don't want to hand tune the free-standing motors through trial and error, only to do it again once they're fitted.

Much more testing still needed...

Currently rated 1.5 by 4 people

  • Currently 1.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


CNC | Electronics | Mechanics

Now I'm counting every minute, Every single minute.

by Ivan Hamilton 5/2/2008 4:44:00 PM

I'd mentioned previously about my efforts to fit a rotary encoder to my DC motor. It was my first attempt at this, and also my first attempt at any real machining with my mill.

I've since done this on another motor (or three), and with the benefit of hindsight (and some measuring equipment), it was much easier, quicker and less painful. I thought I'd detail my experiences here, for the benefit or anyone trying this themselves.

Thanks must go to Richard J. Kinch for his original article.

This is your single shaft DC motor.
We want to fit an encoder (and the extra shaft it needs).

  You'll need a nice flat spot to mount the encoder.
This motor has nice circular raised area, but there is some logo & writing in the way.

Most motors have 2 longitudinal bolts. Remove these and get ready to take the end plate off.

HELPFUL HINT!! Be ready for parts to fly everywhere. The brushes are spring loaded, and once free of the commutator, they will want to spring out.

After removing this, you'll see the end of the shaft that you want to extend.

Notice the counter sunk hole in the end? This is where the shaft is held when it was initially made. This is what will guide our new hole.


You're going to put a hole in the end plate for the new extension shaft to exit.

Find the center of the bearing mount within the end plate.

HELPFUL HINT!! Don't guess the center position. Find the center with accurate measuring tools.


Put the hole in the end plate.

I went for 1mm larger (5mm) than my shaft (4mm).


The mounting face needs a clean up.

Mount the end plate, and prepare to mill.

  After a quick face mill, you should have a lovely clean mounting area.

Simply slipping the end plate on (with the springs removed and brushes just tucked out of the way), makes for a good sanity check.

You should see the shaft's center hole neatly in the middle of your new hole.


To drill the hole in the shaft, we're going to rotate the shaft and hold the drill bit stationary. This will cause a "self-centering" action, and help keep our hole straight and centered.

I used the motor's own power (you'll need the motor reassembled to do this).

HELPFUL HINT!! During the conversion you'll need to reassemble the motor (to a working state) a couple of times (you'll might even convert a couple of similar motors). Do yourself a favor and find a quick way to refit the end plate. I bent up a few paper clips to make brush retainers, which made fitting the end plate a breeze. Find a good way at the start, and you'll save lots of time and frustration.


Center your drill bit over the motor. With the motor stationary, drop the bit in and see if it bends toward the shaft's center hole. Adjust until you're in the center.

HELPFUL HINT!! Check the rotation direction of the motor. Made sure it's spinning anti-clockwise from the bit's perspective.

HELPFUL HINT!! Use a good quality sharp bit. It will be easier on the motor, and make the job quicker.

HELPFUL HINT!! Use a variable supply so you can adjust the motor speed. My first attempt was with a fixed supply at the motor's rated voltage. The very high speed simply cooked the drill bit.

Drill with short "pecks", as there is limited area between the shaft, bearing and end plate, and you'll want to bring out as much swarf as possible.

HELPFUL HINT!! Use a powerful magnet to help remove swarf. Put the magnet against the bit, or a nail and dunk it in the shaft hole to drag swarf out.

I drilled a hole about 10mm deep into the shaft.


With the shaft drilled, clear the swarf out of the motor.

HELPFUL HINT!! When removing the drilled end plate, hold the motor with the drilled end plate on the bottom. This way the swarf will fall out, and not in to your motor. With care (and luck), you won't need to remove the armature to clean out the swarf.


HELPFUL HINT!! That strong magnet you used to remove swarf when drilling, can help clean up the end plate afterward.

HELPFUL HINT on the HELPFUL HINT!! A plastic bag over the magnet will make removing the tiny filings from the magnet very easy.


Get your extension shaft ready.

If turning your own, made sure you're very accurate. Especially if the encoder wheel is press-fit.

You need to be smaller than the hole you drilled, but not smaller than the bore needed for the encoder.

I found that at 0.05mm above or below 4.0mm, the shaft would jam in the drilled hole, or be too loose for push-on encoder.


Clean the new shaft & hole. Put a drop of super-glue in the shaft's drilled hole and insert the shaft.

If a little glue doesn't ooze out, remove the shaft, and add another drop.

Refit the end plate (brushes not needed) to help judge the concentricity of the new shaft.

Spin the motor (manually is fine) and watch the new shaft. If it's off center, give it a slight nudge.

Let the glue dry a little (not fully), and re-align the shaft.

Allow the glue to cure.


Center the encoder's PCB.

The US Digital encoders have a placement tool, a tube which has an internal diameter equal to the shaft size. The tool's ends have a slight taper to center the board.

  Mark the centers of the screw holes on the end plate with a punch.

Drill and tap the mounting holes.

In my case, I drilled 2mm holes and tapped in M2.5 threads.

  Mount the base & PCB. Center with the centering tool.
  Insert and tighten the screws, and then remove the centering tool.

Mount the encoder wheel.

My encoders are the E4P push-on type. The US Digital encoders have a tool to push the encoder wheel on just the right amount. (The tool stops on the base tabs)


The encoder wheel is now fitted. Time for a final inspection.

My shaft was a little short in this case, but the wheel doesn't carry any load, and has a good grip on over most of its length.


Install the top cover, and you're done.

E4P - US Digital E4P encoder (US$20)
300 - cycles per revolution - 1200 pulses
157 - 0.157" (4mm) shaft
M - metric screws



Currently rated 1.8 by 35 people

  • Currently 1.8/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


CNC | Electronics | Mechanics

If you're on the highway and Road Runner goes beep beep

by Ivan Hamilton 4/29/2008 11:10:00 AM

The servo controller I've been building is meant to interface to a motion generation system. In the hobby CNC world, that's probably Mach3 or EMC2.

Mach3 uses the parallel port to generate signals that describe motion. It's often referred to as DIR+STEP signals. One line is the direction, the second is pulsed for each increment of movement. My servo controller was written to interpret these signals, but I didn't have a parallel port on my "legacy free" desktop to test this. A trip to the PC shop got a 2 Port PCI parallel port card (a Sunix 4018A Multi-I/O Adapter) for $35 (I could get one a few bucks cheaper, but the cheap shop had around 25 people queued at the counter!).

Unfortunately the Sunix card isn't just a "standard" parallel port. It doesn't appear at IO address 0x378 & 0x278 like a "standard" port (these are the addresses set by default in Mach3). Being a Plug & Play card, the IO addresses are assigned by the BIOS/OS. Windows XP's Device Manager shows the addresses the card had acquired.


I was hoping that the few ranges it had were still IO compatible with a standard parallel port. I entered 0xC000 as the port address into Mach3, attached the CRO to the port, and jogged the axis. Success!

A couple of wires were added from the parallel port break out board to my controller, and a test was in order.

The background is the standard Mach3 screen. Lower left is the motor. Lower right is the serial terminal output from my controller. The terminal output is: [0] positional error, desired position, output strengthtemp diag numbers

The error sits at around 30 and peaks at 100. The motor is fitted with a 1200 pulse encoder (Mach3 configured for 0.25"/rev screw), meaning that's 9-30 degrees (0.16-0.55mm) out respectively. That's not bad for a system that's not been tuned properly (at all really - Kp=100, Ki=100, Kd=0).

I've added simple serial command processing to the controller, and you can adjust the PID parameters on the fly now. This will certainly help in getting the final tuning values.

More thorough testing is still needed. I need to push it until it breaks, and see what it can withstand. I also need to do some "quality" PID tuning. But for the moment... I'm a little pleased with myself.

Currently rated 1.5 by 34 people

  • Currently 1.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Electronics | Mechanics | CNC

I know you think I could be great with just a few adjustments

by Ivan Hamilton 4/27/2008 3:15:00 PM

Tuning the PID values for the servo controller is going to mean getting an easier method of communication with the device.

At the moment, to adjust anything, I change a variable in the source code, recompile, and reflash the controller chip. Not easy for quick testing of a minor change. Especially, since it means removing the chip from the prototyping breadboard, inserting it into the development board for programming, and moving it back again for testing. Argh!

I am going to need data coming out to judge the performance of the controller (measure errors, etc). I am also going to need data going in to quickly adjust parameters. I had added some simple serial output (for a quick debug), but this will need better management as the system is quite timing critical (the current serial output routine blocks signal processing while it waits to send the bytes out).

A few quick adjustments saw the outbound data buffered and dispatched only when the UART is ready to accept it. An inbound buffer was also created for inbound commands. A simple set of commands were implemented, and now pressing "A" & "S" in a terminal window rotates the motor forward or backward 1 revolution (1/6th revolution for lower case). "Z" will return the motor to its "zero" position.

The controller now regularly outputs the current position, desired position, and output value. Before launching into PID tuning, I might run a few tests to check that the encoder decoding routines function accurately, etc. I'd like to test the control decoding, but I've just realised... I don't have a system with a parallel port!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Electronics | Mechanics | CNC

Gonna stand my ground, won't be turned around

by Ivan Hamilton 4/25/2008 6:12:00 PM

I already had my controller connected to the motor driver and to the motor. What was missing was the position feedback, and with my encoder fitted, the first test with feedback was ready.

I'd already written most of the controller code including the quadrature decoding necessary to understand the encoder's output. I patched in the encoder's lines to the controller, and set a low voltage for the motor driver. Setup done... I gingerly switched it on.

Nothing happened. So, I bumped the shaft and the motor took off. I had considered the possibility that I would get the encoder's output and the motor's input reversed. Knowing this, I reversed the motor leads.

Nothing happened. I bumped the shaft...nothing happened. I tried to turn the shaft... I couldn't. Success! I connected a shifter to the shaft and turned it. The motor pushed back. Considering the PID controller had no tuning, I was quite surprised by the initial response.

This static system was a little uninteresting, so I added a simple increment in to a timed routine to give it some movement. The results were very rewarding, and raised a couple of areas of concern.

Cogging. This demonstration makes the cogging extremely visible. The controller pushes through the natural attraction to one "cog" position, and once it reaches the influence of the next, it races toward it (and then the controller slowly recovers).

Large deviations from the desired position (like an idiot pushing a shifter on the shaft) recover very quickly, but the smaller ones are very slow at the moment. At this point, it's important to remember that the PID parameters have not been tuned at all. In fact, you can see the effect of the default (1) values in this situation:

Proportional - The further away from the desired position the more power applied - gets results quicker
Integral - The longer it's away from the desired position the more power applied - overcomes a constant opposing force (cogging torque, rubber band)
Derivative - The quicker it's approaching the desired position the more power removed - dampening to help stop overshoot

Tuning, tuning, tuning! The key to success here is tuning the unit. Just one problem, the tuning is specific to the circumstance of the unit. For example, in current no-load conditions the parameters would need to be set to respond quickly enough to over come the cogging jolts. But at its final destination, there will be pulleys, belts, shafts and screws attached. All of these components will add inertia and friction, greatly changing the characteristics of the system. The cogging torque may well be irrelevant when lifting a 100kg machining head with a badly lubricated screw. Irrespective of what is relevant where... I do need to devise and document a simple and repeatable tuning method for this controller.

I dream of a single button...

Currently rated 3.0 by 5 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Electronics | Mechanics | CNC

Back, back forth and forth

by Ivan Hamilton 4/25/2008 12:31:00 AM

Having completed my machining exercise, I fitted the rotary encoder to the motor and had a play.

First thing was to check the encoder even produced any output (I could have broken it). I added 5V and plugged A & B into the CRO. Two lines at 0V... not good. I touched the shaft, and the lines wobbled. Yippee! So I powered the motor via an adjustable supply, to see what it looks like when running.

Things learned:
* My 36V motor will turn with just 0.5V applied (that's cool)
* At very slow speed with no load, the motor has some serious cogging

Next... plug it into my servo controller.

Currently rated 3.5 by 2 people

  • Currently 3.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Electronics | Mechanics | CNC

Powered by BlogEngine.NET
Original theme by Mads Kristensen

About the author

Name of author Ivan Hamilton
"My inner nerd can beat up your inner nerd."

E-mail me Send mail



<<  October 2021  >>

View posts in large calendar

Recent comments





    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2021

    Sign in