Archive for the ‘CNC’ Category

A3977 Stepper Driver REQUIRES Non-Inductive Sense Resistors

Monday, August 13th, 2007

The stepper motors I’m using to build my CNC machine are rated for 2.5A. Now, when they’re holding one position, it’s easy to deliver 2.5A of current. But when the motors are rotating, their coils are being energized one at a time in sequence.

The coils are inductive, and inductors resist changes to current. So when a coil is first energized, it takes a moment for the current to build up to capacity. As a result, with a simple stepper driver, the faster you turn the motor, the less of the time each coil gets full current, and the weaker the motor gets.

The Allegro Microsystems A3977 stepper driver chip I’m using to control my stepper motors overcomes this by running at a (much) higher supply voltage than needed to deliver 2.5A, and by using sense resistors in series with the motor coils. When it’s time to energize a coil, the A3977 delivers the full supply voltage and watches the sense resistor. When the desired amount of current is flowing through the resistor (hence the motor coil), the A3977 shuts off the voltage (briefly), then ramps it up again. The result is the delivery of the desired current on average, but with a much more rapid start due to the higher supply voltage.

Buried within Allegro’s A3977 FAQ is the recommendation that the sense resistors should be non-inductive. Since the values required are the sub-ohm range, commonly-available resistors are in big sand packages — and as noted by Jeff Mann in a comment posted about my control board, are internally wirewound and inductive.

Sand resistors and non-inductive sense resistors

I had already bought Ohmite non-inductive sense resistors from DigiKey, which are also much smaller and more manageable than the big sand resistors. (The cross-section of the sand resistors is about 1/2″ square.) I hadn’t worked on the stepper driver in quite a while, though, and I hadn’t put in the noninductive resistors yet.

Did that Saturday. The difference in performance is amazing.

Performance Gains

The last time I did a speed test of my stepper motor controller, I was able to get about 500-600 steps per second before the motor started losing steps and stopped turning. Additionally, it growled and twitched when it was idle, and grunted and jerked at low speeds, smoothing out only at higher speeds.

A3977 stepper control board

With the non-inductive resistors installed, all the growling and twitching went away. (Someone should look at non-inductive resistors for bulldogs, but I digress.) I’m able to ramp the motor up smoothly from a stop to full speed.

And full speed has increased from about 600 steps per second to over 1450 steps per second, just from installing non-inductive sense resistors. With my 200 step/revolution motors and 20 tpi all-thread, that’s an improvement from about seven seconds per inch of linear travel to about three seconds per inch.

That’s still running on 12V out of my spare PC power supply, and I’m trying to rustle up a 24V supply to test with, which should increase the speed further. That’s also without tweaking the A3977′s component values — I hear there are some tricks to play there, too.

Executive summary:

Inductive sense resistors with the A3977 make the motor growl and jerk when idle and at low speeds, and limit maximum speed. Non-inductive sense resistors with the A3977 make the motor smooth and quiet at all operational speeds, and dramatically increase maximum speed.

Z Axis Completely Assembled

frame

I have the drill sled mounted in the frame, the motor properly mounted, and the joystick controlling it at variable speed. Next step is building the Y axis around the Z frame.

Credit Where Due

Many thanks to Jeff Mann for his original comment, which drew my attention back to replacing the sense resistors, and for our followup conversation, which helped me understand and think through how the PWM driver makes the motors work better at higher voltage without going over the rated current.

Rewiring a Game Controller’s Joysticks

Monday, August 13th, 2007

When the CNC machine is finished, it will of course be controlled by a computer. But during development, it’ll be handy to test it with other controls, like joysticks. I had in mind to use analog joysticks, so I could control motor speed as well as direction.

Unfortunately, I couldn’t find the analog joystick element that I bought from All Electronics. (That this happened something like nineteen years ago may have a little to do with why I can’t find it right now.) Fortunately, a poll of my friends for an analog joystick I could borrow yielded this game controller that Jeremy had already brought me in a batch of electronics junk:

USB game controller

In his own words:

Didn’t like it because it was crappy. The retractable cord (while an OK idea) was too short and stiff. Its real downfall was that the buttons were sticky. They wouldn’t pop back up immediately when pressed so rapid tapping was impossible. More frustrating than useful.

So, perfect for me to butcher for my own purposes.

Inside the Game Controller

My first thought was to extract the analog joystick elements, so I opened the case and dug in.

Game controller with case open

Here you can see all the guts that make it work. The upper half of the picture is the bottom side of the case, with the retractable USB cable recessed under the PCB, and wipers on the PCB to make contact as it spins.

In the handles near the bottom of the picture are small motors with eccentric weights for “force feedback,” and directly above them at the center of the picture are the pushbuttons on the forward edge. The tan PCB has contacts for the pushbuttons, LEDs, and pseudo-joysticks on the top face; and the green PCB is the brains of the outfit.

Game controller, main board

The main board holds the analog joysticks (the solder pads surrounding the silk-screened circles in the lower left and right) and the USB interface (in the black blob).

Game controller, joystick mounting

Flipping the main board makes it easy to see how joysticks work. Each is a clever cage with a gimbal mechanism for the stick, connecting to two potentiometers (visible above and to the right of the right stick). These joysticks also have pushbutton action (like clicking the scrolly-wheel on a mouse), so there’s a stick coming out the lower side to a switch housing.

I had actually completely desoldered one of the joysticks when I stopped to think about how I was going to mount them — loose, to a board, what? How about . . . in a game controller case. Duh.

Rewiring

So I soldered the joystick back in and started to look at the circuit. The USB interface was useless to me since I wanted direct access to the analog controls, but I could still use the board as a carrier for the components.

The controller had the potentiometers wired as variable resistors (the wiper tied to one leg, probably for the blob to measure resistance with an RC timer), but I wanted potentiometers so I could measure voltage with an A/D converter on my microcontroller. So the first order of business was cutting traces.

I used a knife to cut through the traces tying the potentiometer wipers to the legs, and the continuity meter to makes sure I’d cut thoroughly enough. Then I identified which direction I wanted to be 0V and which 5V (moving the joystick to the upper right should deliver 5V on each axis), labelled potentiometer terminals with + and -, and started jumpering together pads that hadn’t previously been connected, to distribute power and ground to all the potentiometers.

And that’s how far I got in May, when I last worked on it. I picked it up again this weekend and finished the job.

Game controller, rewired for direct access to analog joysticks

I severed all the connections around the processor blob, since I didn’t need it and didn’t want it getting confused by the new arrangements. And I soldered on wires from a supple new cable Joel gave me (salvaged from who-knows-what). I provide 5V and ground on the grey and black wires, connected joysticks on brown-red-orange-yellow, and have blue and green left over for pushbuttons when I figure out which ones I want to use.

On the loose end, I soldered a header pin to each wire, to fit nicely into prototyping sockets, and heatshrunk each solder joint. I also heatshrunk logical pairs of wires together, to make it easy to remember which wires go together to a potentiometer. You can see that end in my previous post on the Arduino.

I made one mistake, which I had to go back in and correct: I wasn’t thinking straight about which potentiometer was the X axis and which was the Y. The one across the bottom, of course, is the X axis, and the one on the side the Y — but that’s not how I wired it. I swapped the brown and red and orange and yellow wires from what’s shown in the shot above.

And it works great! I have it reassembled and the right joystick controlling the prototype Z axis of my milling machine . . . which I’ll talk about next.

CNC Drill Sled

Sunday, May 6th, 2007

CNC drill sled, lower left view

I got the sled (or platform) built that will move the drill up and down (Z axis) in my CNC machine. I spent over a week trying to figure out how to make thrust (axial load) bearings for the lead screw, so that all of the motor’s rotary motion is translated into vertical movement of the drill, not vertical movement of the screw itself. I’m still not completely sure that my plan for that will work, but at least I have something to try in the next stage I’m going to build.

I need to find and learn to use an open-source 3D CAD program; but meanwhile, I laid this out in OpenOffice Draw. I had started by tracing the different pieces onto graph paper by hand; but the design didn’t really pick up steam until I got them into the computer, where I could drag and resize components easily. Several times when I thought I was done, I saw the opportunity to shrink things a little closer together — which ultimately translates into the capacity to work a larger piece, as less of the length of the guide rods is consumed by the width of the sled.

CNC drill sled design, front view

Here’s my final design — final for the prototype machine, anyway. And here’s what it looks like in the physical world — a pretty close match.

CNC drill sled, front view

The drill is held by two square blocks with round holes drilled out in their centers. I goofed and cut the blocks to 2 1/4″ instead of 2 1/8″, so the whole platform now fits together a little tightly, and the alignment of the guide rod on the left is a little off; I’ll have to compensate for that later on. And the drill fits a little loosely in the holes because they’re a bit too large, but I’ll add some thin weatherstripping to grip the drill tightly.

The white blocks on the right are built up from two layers of polypropylene kitchen cutting board, superglued together, with a hole tapped through lengthwise for the threaded rod (1/4″ all-thread). When the rod turns, it will push the drill down or pull it back up.

On the left are a bearing glide and stainless steel rod salvaged from a workhorse IBM dot-matrix printer. A computer surplus store in Wichita had a closing sale a few years back, and when no one bought the printers, the owner suggested that I haul them off. I dutifully removed all the electronics, boxed up the mechanical components, and deposited the plastic for recycling. At last the mechanics are finding a new use. :-)

This assembly will be oriented with the drill pointing down, and a frame will surround it in the Y-Z (vertical) plane. The frame is shown in the drawing but not in the photograph; it’s the next piece to be constructed. The frame will anchor both ends of the guide rod and the lead screw, provide a mount for the motor, and mount two glide assemblies to move the entire frame sideways in the Y (short horizontal) axis.

Motor Mounting

The motor isn’t mounted to the screw right now, since it mounts from the outside of the (yet-to-be-constructed) frame. But I’ve been looking for a good coupler to join the motor shaft to the threaded rod. The ideal coupler would help compensate for slight misalignment between the axes of the motor and the rod, but really good couplers seem to cost $60-$80.

I’ve found one at Jameco that’s much more affordable (just under $5) and looks like it’ll do the job nicely. It has a rubber “spider” enclosed between two pronged pieces. The spider has a little bit of “give” to it, to correct for misalignment. It should also help damp transmission of noise and vibration between the motor and the screw.

Stepper motor with homemade shaft coupler, angled view

Meanwhile, I’ve built a cheapo prototype coupler myself. I got a $1.49 threaded coupler from Ace Hardware, drilled out half of it to 1/4″, and drilled and tapped holes for set screws. I pressed the drilled end onto the motor’s shaft, filed a flat into the threaded rod and turned it in to the threaded end, and tightened the two set screws. I need to file off some of the set screws’ length, but it’s working okay for a proof of concept.

Homemade shaft coupler

Stepper Motor Controller Board

Sunday, April 22nd, 2007

Keeping a blog is a great way to realize exactly how long some of my projects sit on the shelf–until recently, I haven’t worked on my CNC milling machine project since last May. Hoo boy.

Last time I discussed it, I’d been experimenting with the stepper motors I want to use to drive it, and the last thing I had done was build a driver out of discrete, complementary MOSFETs. I was hitting about 500 steps (2.5 revolutions) per second, and the output transistors were getting pretty warm. Plus I was using a 12V supply to feed the motor’s coils that only want about 2.1V each, so I was throwing away the rest of the voltage in huge sand resistors.

Allegro A3977 Stepper Driver

I was interested in trying a dedicated stepper controller chip, and I found the A3977 microstepping driver chip from Allegro Microsystems. It’s rated for 2.5A per coil (the same as my motors) and looked perfect for my application, so I ordered a few samples.

The A3977, like many other current-controlled drivers, has each load (motor coil) in series with a sense resistor, to measure the current actually flowing through the coil. The A3977 ramps up the load voltage until the sense voltage reaches a (designer-controlled) threshold, then shuts it off and ramps again. Thus the average current through the coil (when energized) can be controlled by the combination of sense resistor value and reference threshold voltage.

Clear back in September (ahem), I laid out a breakout board for the A3977, to make sure I understood how to control it before building real control boards for the CNC machine. I put on header sockets to make it easy to try different parts values; about the only parts soldered onto the board are the A3977 itself and several required capacitors whose values are specified on the datasheet.

I also planned to solder the sense resistors; their resistance is so low that an oxidized socket could add resistance equal to a significant fraction of the resistors themselves.

A3977 breakout board

The biggest challenge in the layout was designing adequate heatsinking. The A3977 doesn’t have a solder pad on its belly, and I’d have had a hard time soldering it even if it did. Instead, the three pins at the center of each edge are ground pins that double as heatsinks, and they want a big copper area for dissipating heat.

I used EAGLE’s polygon feature (I think that’s what it was called; I should have taken better notes while I was doing this) to make big copper areas. In the above picture, the brighter red and blue outlines show areas that will be filled with copper on their respective sides of the board.

A3977 breakout board with polygons filled

Hitting the ratsnest button then flood-fills copper into not only those areas, but the rest of the board, leaving a specified gap between the copper ground plane and any pins not specifically identified for inclusion. Since I was planning to etch the board in the sink, leaving large copper areas not only provides the requisite heatsinking, but saves on etchant and etching time.

Building the Board

Immediately after making the board, I got the A3977 soldered onto it. Because the board was hand-etched, it was a lot dirtier than professionally-manufactured boards, and soldering the big PLCC chip onto it was correspondingly more difficult. But I got all good joints and no bridges, as confirmed with the continuity tester.

And then the board sat from September through April. Sigh.

A Kick in the Seat

A few weeks ago, I suggested to John Harrison that we needed to get back into having a “geek club” meeting every Monday night this summer–and that at every meeting, every member had to show or demo significant progress on some project. It’s amazing how much you can get done when you have peer expectations of continuous achievement.

I called John on Friday evening and told him that I needed a pep talk: I had a wide open weekend and two electronics projects that I could work on but was reluctant (and/or intimidated) to start. I could finish the work and blog on repurposing a battery-operated motion sensor (coming soon) for class, or work on my stepper controller.

He asked which one I was going to show him on Monday night. Well!

That was the motivation I needed, even though it turned out he’s out of town Monday. By the time I went to bed Friday night, I had the whole board assembled (except for the pieces I forgot). Instead the motor running, though, it kind of twitched and buzzed.

I reread the datasheets and applications notes as I was going to bed, and realized I had somehow left out the RC components for the output waveform generators. My wife woke me up at 6:30 Saturday morning for help with the laser printer before running off to manage the local food coop’s distribution day, and by the time normal people were up, I had the controller running the motor at full speed.

Stepper motor controller board

Here’s what the board looks like with everything installed. The big sand resistors are the sense resistors–and yes, that is .1Ω (although I tried .2Ω first and will probably go back to it). The weird green things are capacitors for an internal voltage boost circuit. The motor coils are fed from the orange, blue, brown, and grey wires that take off from the upper and lower corners. Power from a PC power supply comes in the left, and the red probe and blue wire on the right provide a step signal from my function generator so I can test without hooking up a microcontroller. The extra wires and resistors around the outside are jumpering things like /RESET, /ENABLE, and DIR, again to facilitate μcontless testing.

Stepper motor controller

Thar’s what it looks like with the motor.

How It Works and Lessons Learned

Speed

I was surprised that I wasn’t able to get it to run faster than it does. I haven’t measured exactly, but I guesstimated I was hitting about 600 steps per second (3 revolutions per second) before it started jittering instead of turning. I tried half- and quarter-stepping (at correspondingly higher clock rates), hoping the smoother drive would increase the maximum rotation speed, but it didn’t. I swapped out the sense resistors to increase the motor current, but that didn’t increase the maximum speed either. I could tinker with the ramp generator’s RC values, but I don’t think that’ll help either. The controller is rated for 600,000 steps per second (!!!), so I’m pretty sure the limitation here is the motor, and I’m just pushing it as fast as it can go.

That’s a little disappointing, because (1) that’s only a little faster than the 500 steps/second I was getting with my MOSFET driver; and more to the point, (2) with a 20 thread per inch lead screw, 3 revolutions per second works out to about seven seconds per inch of travel. That is, if the cutter head is at the opposite side of a sheet of typing paper and needs to come back, it’ll take a minute for it to travel across. That’s pretty painful.

The documentation at the LinuxCNC (née EMC) web site suggests that high-speed CNC machines use DC motors with optical encoders, rather than steppers. I guess I’ll look into that for version n + 1.

Advantages?

I’d been hoping that the current-control system would be the silver bullet that pumped this motor up to dramatically higher speeds. Since that’s clearly not the case, is it still worth using this chip over the discrete MOSFET design I made?

I say yes. The A3977 is much smaller than the eight TO-220 FETs (plus heatsinks) required in the discrete transistor design.

The A3977 also runs a lot cooler. Its temperature rose to the mid 90°F range after several minutes of continuous full-speed operation. In contrast, the FETs got hot enough to burn fingers (I didn’t have my infrared thermometer yet) after only a few seconds of operation.

Allegro would claim that the A3977 also improves the pin count for processor interfacing–it requires only two pins (direction and step), whereas the discrete transistor solution requires four pins (two wires each for two coils). This is probably valid, although the plethora of options (half-, quad-, and eighth- stepping, reset, etc.) will tempt me to use up those saved pins controlling other facets of the stepper operation.

Sense Resistors

I had ordered big sand resistors with thoughts of stacking them to kill voltage in my MOSFET design. But defining ITRIPMAX as the maximum instantaneous current of each output ramp cycle (in my case somewhere between 2.5A and 5A), the A3977 recommends:

VREF = 4V
RSENSE = VREF / (8 * ITRIPMAX)
      = 4V / (8 * 2.5) = .2Ω

Which is what I’m using. BUT working back:

V = I * R
VR = 2.5A * .2Ω = .5V

P = V * I
P = .5V * 2.5A = 1.25W

So the resistors need to be large, but not quite so monstrously huge. (These are 10W.) I’ll shop for smaller ones before building the real board.

Source for Mini-Drill and Mill Bits

Wednesday, July 12th, 2006

I just ran across Drill Bit City, a company that resharpens mini drilling and milling bits and sells them for very reasonable prices. Like sets of ten identical bits for as low as $3, mixed sets in the $7 range, etc. I’m looking forward to buying from them once I get my own machine up and running!

Discovered via Will O’Brien’s CNC machine, part 3.

Stepper Motors, Part V: Taming the Wild Voltage

Saturday, May 20th, 2006

With a desired motor voltage of ~2V and the bridge feeding the coils ~11V, the motor draws way more current than it needs, and the FETs get really hot. In fact, the PC power supply I’m using, which is rated for 7.5A of 12V, can’t keep up with the load. It makes sense:

11.4V / .85Ω ≅ 13.4A

And that’s per coil, so almost 27A draw for the two-coil motor. When I measured the voltage drop across one coil, it was actually only a little over 3V. I had known I was going to want to drop the bridge voltage so the motor coils didn’t get the full 11.4V, and I had thought about doing it with diodes or resistors. Before going any further (laying out a PCB), it was obvously time to deal with the overvoltage; so last night, I sat down to do some calculations.

Dropping Voltage with Diodes

I don’t know why, but my first inclination was to try to drop the voltage with a string of diodes. Given

bridge voltage: 11.4V
desired motor voltage: ~2V

then

required drop: ~9.4V

With a .6V drop for small-signal diodes:

drop per diode: .6V
diodes required: 9.4V / (.6V / diode) ≅ 15.7 diodes

And assuming I was willing to string together 15 diodes in each direction, for each coil of each motor (uh, 15 * 2 * 2 * 3 = 180 diodes in the milling machine just for dropping voltage), how close would that get?

drop for 15 diodes: 15 diodes (.6V / diode) = 9V
motor voltage with 15 diodes: 11.4V – 9V = 2.4V
current with 15 diodes: 2.4V / .85Ω ≅ 2.8A

Granted, the rectifiers I’d actually use have a voltage drop more like 1V to 1.25V per diode; but that’s still 9 * 2 * 2 * 3 = 108 diodes in the project. Way too wasteful, and way too many.

Dropping Voltage with Resistors

It seems that Tom McGuire’s suggestion to use power resistors is the right way to go. Big sand resistors can dissipate a lot of power, but how much would be required? From above,

required drop: ~9.4V

And given

coil current: 2.5A

then each resistor would need to be capable of

9.4V * 2.5A ≅ 23.5W

That’s a pretty hefty resistor!

I looked through my parts bin, but most of my power resistors have a much higher resistance. I also browsed power resistors at All Electronics and found a few ceramics rated for 25W–but I didn’t want to have to come up with enough stuff to place a minimum (reasonable) order, wait for it to arrive, and then take a chance of it not meeting my needs. As it turns out, Radio Shack carries an 8Ω 20W resistor, so today I trotted on down and picked up a couple.

I hooked one in series with each motor coil and ran through my barrage of tests. After reconnecting a loose signal wire from the controller (oopsie!), I found that the motor was much easier to stop by gripping it with my fingertips, it had a much lower top speed without losing steps, and the coil voltage was only a little over 1V.

Dropping Voltage with the Right Resistors

At no point in the resistor discussion do I describe figuring out exactly what resistance is appropriate, because I was too impatient to get on with prototyping to be bothered with calculating. Sigh.

Okay, so I want ~9.3V dropped across the resistor and ~2.1V dropped across the motor; and the motor coil is ~.85Ω.

9.3V / 2.1V = R / .85Ω
R = .85Ω (9.3V / 2.1V) ≅ 3.8Ω

So I was embarassingly far off with my 8Ω resistors, which explains the low voltage and poor performance when I tested them.

Hmmm . . . 3.8Ω is really close to half of 8Ω. Now I’m tempted to go back and buy two more of the 8Ω resistors, to test in parallel.

On the other hand, it’d be nice to try a range of values centered around 3.8Ω, to graph the motor performance and find whether the curve has a knee in that vicinity. So now I’m back to looking at All Electronics, thinking of ordering myself an assortment. They don’t have anything in the 4Ω range, but they have 1.2Ω, 1.3Ω, 1.5Ω, and 2Ω in power ratings I could work with.

Stepper Motors, Part IV: Speed Trials

Sunday, May 14th, 2006

First Real Motion

Tuesday night, I duplicated my H-bridge circuit for the second coil of my stepper. I provided drive power from my bench power supply, because I wanted to be able to vary it to test the effects of different supply voltages. And I didn’t (yet) do anything to drop the bridge’s voltage down to the ~2.5V that the motor wants–I just let the motor have whatever came through the bridge. The motor is hefty enough, I didn’t figure it would be damaged during brief tests.

Dual H-Bridge MOSFET Stepper Motor Driver

I hooked up the motor, started my LogoChip program with a clockwise drive pattern, and slowly turned up the supply voltage. Around 2-3V, the motor started chunking along. And I found that I couldn’t supply more than 2-3V–no matter how high I turned my variable supply (like, up to 20V), it wouldn’t provide more than 2-3V. It’s only rated for 1.5A on the channel I was using, and it was giving everything it had.

Using a loop [ step-cw mwait ___ ] command from the LogoChip console, I was able to get down to 4ms wait without losing steps, or 250 steps per second. I assumed that with a stronger power supply, I could do at least a little better than that, and I was not to be disappointed.

Dedicated Power Supply

Wednesday night, I brought in an old PC power supply and wired it into the driver board. I first used its 5V supply to power the driver, wanting to work up to 12V in stages. It was clearly driving the motor more powerfully than my bench supply did Tuesday night–motion was smoother and able to run at slightly higher speeds.

Next, I switched it over to using the 12V supply. Ideally, I’d like to run it on 8-9V, but I wanted to see what 12V did to the FETs and motor. As expected, running on 12V gave the best performance I’ve experienced yet. I was unable to stop the motor’s movement by gripping the 1″-diameter pulley with my fingertips (!), and I was able to get down to a 2ms wait in the loop shown above without losing steps.

How Fast Is That?

It was losing steps continually with a 1ms wait, but that’s a full factor of two difference in speed from the 2ms wait, so I was curious where between the two the fastest possible speed lay. I rewrote the loop to use a no-op (which the LogoChip Language Reference lists as 13μs) for the delay instead, and tweaked it down to about 150 no-ops without losing steps. Since 150 * 13μs = 1950μs ≅ 2ms, it looks like that’s about as fast as I’ll be able to get the motor to run with the current drive system.

What does that translate to in the real world? 2ms / step = 500 steps / second. This stepper has 200 steps per revolution, so 500 steps / second = 2.5 revolutions / second. I was planning to use 20 tpi all-thread for the drive screws, so (2.5 revolutions / second) / (20 revolutions / inch) = 1/8″ / second. That’s kinda slow.

Speed Improvements?

I deliberately designed the H-bridge drivers so that they could be quiesced and deliver no power to the motor. Some drivers use a single bit to select forward or reverse, and are therefore always on; I provide one bit for each half-bridge, like the 754410, allowing both sides to be high or low together for no power delivery to the load.

My current control software, however, always energizes each coil in one direction or the other, so both stepper coils are always active at the same time. Assuming the power supply is up to the task, this provides greater torque, as you have two magnets holding the rotor at all times instead of only one. However, if I recall correctly, this also results in a slower maximum speed. I’d like to experiment with rewriting the code to energize only one coil at a time.

Another approach to explore is half-stepping. When two adjacent coils are both energized (as they are under my present controller), the rotor is pulled to a position halfway between the two coils. If you change the control code to energize coil A, then A and B, then only B, etc., you cause the motor to “half-step,” doubling your steps per revolution. I’d like to test whether this motor performs better when single-stepping or half-stepping.

Finally, I’m not presently ramping the speed at all. When the controller starts up, it’s immediately powering the motor to move at full speed. Because the rotor has mass and therefore inertia (even without an external mechanical load), it’s possible that it’s losing steps because it can’t immediately move at full speed, and never achieves synchronization with the controller. Any CNC control software I might use will have ramp-up capabilities, so it’s worth trying with my test controller as well.

Power Supply Issues

The PC power supply I was using is a switching power supply, and switching supplies don’t like to operate without a load. Projects to adapt PC power supplies to use as bench power supplies generally suggest putting a large load resistor in parallel with the outputs to keep the power supply loaded at all times; but for my quick testing, I didn’t do that. Newer PC power supplies also have “smart switching” or “soft switching,” enabling them to be turned on and off under motherboard control, to shut off the PC when you halt the operating system, facilitate wake-on-LAN circuitry, etc.

For whichever reason, I found that after the power supply warmed up a bit, it would no longer power on unless the stepper driver was already receiving signals that caused it to draw current. That is, I had to start the stepping software on the LogoChip controller before turning on the power supply. Since in a drilling machine, the power supply needs to be on continuously to be ready to receive operating commands, this obviously won’t do. I guess I’ll have to address the dummy load issue sooner than I had hoped.

And I’m delivering a much higher voltage to the motor than it’s rated for. As noted earlier, the motor’s label indicates .85Ω and 2.5A per coil, which is about a 2.1V drop. I don’t remember the source-drain drop of a FET, but my 12V supply is obviously putting more than 2.1V across the motor coils, which means I’m running them at a much higher current, as well. That doesn’t concern me too much for the motors during a brief test, but my FETs are getting awfully hot awfully fast.

I’ve talked a bit with Tom McGuire about how to drop the voltage closer to what the motors would like. He’s seen designs with power resistors in series with low-inductance motors like this, but (1) that seems inelegant, and (2) I’m not sure I have appropriate resistors on hand. I guess I could dig through my bins.

I’m also considering stacking a series of 1N400x diodes (one string in each direction) in series with the motor, to drop the voltage. As Tom points out, I need to be careful to respect the current rating of the diodes in comparison to the draw of the motor.

Stepper Motors, Part III: MOSFET Drivers

Saturday, May 13th, 2006

The Theory

Sunday night, I read the MOSFET chapter in my semiconductor textbook several times, in preparation for beginning to build FET motor drive circuitry Monday. I took away these key points (some of which I already knew):

  • Because MOSFET channels are very thin, their junctions are easily damaged by overvoltage conditions, not just overpower conditions. This is the reason for the standard cautions about static electricity and admonitions to store FETs in conductive bags or with foil wrapped around the leads, etc.–high voltage (even at a very low current) can destroy FET junctions.
  • Because MOSFET gates are very high impedance, it doesn’t take much current to turn them on; thus it’s critical to tie the gates with a pull-up or pull-down resistor to keep them from floating and triggering wild dumps of power through the source/drain.
  • MOSFETs like to have > 7V to saturate, i.e. turn completely on. If they’re not completely on, they’ll act as a resistive load and potentially dissipate a lot of power (equals heat, equals shortened lifespan).
  • Read the datasheet carefully to determine which lead the heatsink tab is common with. On the ones I’m using, it’s the drain; so heatsinking to ground would short them out instantly.

The Circuit

I knew I wanted to design my bridge with complementary FETs (N-channel and P-channel), like I’ve done before with bipolars. There are designs available to do bridges with all N-channel FETs, but it takes extra work to bias up the upper FETs and their gate signals. It all seems very complex and nasty to me, especially when I have complementary FETs available: a large quantity of a couple of different MOSFETs, extracted from old printers’ stepper drivers. The IRF510 is a very common N-channel, capable of 5.6A; the IRF9532 is a P-channel that can do -10.0A.

Because the gate voltage should really exceed 7V to saturate the FETs, I didn’t want to feed the gate directly out of the LogoChip (or other TTL-like source). I have SN75452 peripheral drivers on hand, which buffer a TTL input into a high-voltage output. I’d looked at their datasheets before, scouring them over and over trying to find VCC2 (the high-voltage supply) on the pinout, to no avail. Finally I noticed that they have open-collector outputs (DUH), meaning the chips won’t source a high-voltage output, but they’ll sink an output that has a high voltage on a pull-up resistor.

Monday night, I started prototyping with a single IRF510 switching an LED on and off, to make sure I understood basic FET operation. I added an IRF9532 in a half-bridge configuration (the left half of the circuit below), and from their common drains wired one LED high and another low (with resistors, of course), then tested that the LEDs alternated as I applied a square wave to the gates. After demonstrating that the half-bridge worked correctly, I built the full bridge shown below, again testing with LEDs.

MOSFET Stepper Motor Driver Element

Note that the pin numbering on the 75452 is incorrect–EAGLE doesn’t have a definition for the 75452 and I haven’t made one yet, so I subbed a 7400-series chip with open-collector outputs. Now that I think about it, I probably have a 7400-series chip with high-voltage open-collector outputs that I could have used in the circuit instead. I’ll have to keep that in mind.

The Motion

None, of course. A single H-bridge is enough to drive a DC motor; but a stepper needs two, one for each coil. It was late enough, I quit for the evening knowing the bridge was driving LEDs okay, but without testing the motor.

Stepper Motors, Part II: Testing Motion

Wednesday, May 10th, 2006

The Wiring

Sunday, worked in around the community orchestra concert, I got the stepper motor moving using my old friend, the 754410 dual H-bridge driver. I hooked each coil across an H-bridge, and used my Curiously Strong LogoChip as a controller, with two pins running each bridge (forward and reverse). Four pins per motor may or may not be the best way to build a complete CNC machine, but it worked nicely for testing.

Stepper Motor with LogoChip Controller and 754410 Driver

The red/yellow/black wire set from the LogoChip to the driver board provides regulated 5V and unregulated 9V to any auxiliary circuits I want to connect–I like to think of it as the PTO. The red/grey/blue/orange wires from the LogoChip to the driver board are the step control signals, and the red/black/blue/orange wires are permanently cabled into the motor. The yellow/green wires feed from one of the variable outputs on my bench power supply, and provide drive power separate from logic power, to keep dips and noise due to the motor from interfering with the logic control circuitry.

The Software

After wiring up the driver board, I wrote a little LogoChip program to control the driver. I needed to provide a quadrature-encoded signal (one goes high, two goes high, one goes low, two goes low) on two sets of two pins, and be able to reverse it. It turned out to work really nicely to modularize the CW/CCW quadrature code in one function, and put the icky code to deal with turning pins on and off in a separate function–it makes the quadrature code reusable to run multiple motors, among other things.

Here’s what I ended up with:

  • stepper.txt – Program to drive bipolar stepper motor

Here’s the code:

;   stepper.txt
;
;   06-May-2006  Keith Neufeld
;
;   Test/drive bipolar stepper motor, using external 754410 driver chip.
;   Two coils are driven in quadrature:
;
;       ===|       |=======|       |=======|       |=======|
;          |       |       |       |       |       |       |
;          |=======|       |=======|       |=======|       |===
;
;       =======|       |=======|       |=======|       |=======|
;              |       |       |       |       |       |       |
;              |=======|       |=======|       |=======|       |

;------------------------------------------------------------------------------
;   Debug system
;------------------------------------------------------------------------------

constants [[debug 0]]
;constants [[debug 1]]

;------------------------------------------------------------------------------
;   Section to manipulate stepper motor.
;   Coil 1 driven by C7/C6.  Coil 2 driven by A2/A3.
;------------------------------------------------------------------------------

constants [
    [coil1-port portc] [coil1-ddr portc-ddr]
    [coil1a-bit 7] [coil1b-bit 6]

    [coil2-port porta] [coil2-ddr porta-ddr]
    [coil2a-bit 2] [coil2b-bit 3]
]

to stepper-off
    clearbit coil1a-bit coil1-port      ;   set all coil outputs low
    clearbit coil1b-bit coil1-port

    clearbit coil2a-bit coil2-port
    clearbit coil2b-bit coil2-port
end

global [steps-per-sec msec-per-step]    ;   timing "constants"
global [coil1-pos coil2-pos]            ;   current coil state

to init-stepper
    stepper-off                         ;   shut down all coil outputs

    clearbit coil1a-bit coil1-ddr       ;   set all coil pins as outputs
    clearbit coil1b-bit coil1-ddr

    clearbit coil2a-bit coil2-ddr
    clearbit coil2b-bit coil2-ddr

    setsteps-per-sec 2                  ;   2 steps per second
    setmsec-per-step 1000 / steps-per-sec       ;   precalculate wait per step

    setcoil1-pos 0                      ;   initialize quadrature to (0,0)
    setcoil2-pos 0
end

to step-set                             ;   push out new quadrature values
    ifelse debug [
        send 48 + coil1-pos             ;   0/1 with no CR
        send 32                         ;   space with no CR
        print coil2-pos
    ] [
        ifelse coil1-pos [
            clearbit coil1b-bit coil1-port      ;   clear before set
            setbit coil1a-bit coil1-port
        ] [
            clearbit coil1a-bit coil1-port      ;   clear before set
            setbit coil1b-bit coil1-port
        ]

        ifelse coil2-pos [
            clearbit coil2b-bit coil2-port      ;   clear before set
            setbit coil2a-bit coil2-port
        ] [
            clearbit coil2a-bit coil2-port      ;   clear before set
            setbit coil2b-bit coil2-port
        ]
    ]
end

;   CW pattern:
;       0110.0110
;       0011.0011

global [new1 new2]                      ;   temps for coil values

to step-cw
    setnew1 not coil2-pos
    setnew2 coil1-pos

    setcoil1-pos new1
    setcoil2-pos new2

    step-set                            ;   do it
end

to step-ccw
    setnew1 coil2-pos
    setnew2 not coil1-pos

    setcoil1-pos new1
    setcoil2-pos new2

    step-set                            ;   do it
end

;------------------------------------------------------------------------------
;   Routines to tie it all together
;------------------------------------------------------------------------------

to init-all
    init-stepper
end

to powerup
    init-all
end

to startup
    init-all
    loop [
        step-cw
        mwait 100
    ]
end

The Movement

I started up the motor control with a loop [ step-cw wait 10 ] from the LogoChip console, then turned up the variable power supply until the motor was chunking along at a step per second. That channel of my power supply is only good for 1.5A, and I found that no matter how high I turned the dial, the meter didn’t read any higher than about 2.5V. I guess the coil power calculations were pretty close.

Next, I played with different timing values, to watch the motor turn at different rates and test its torque. I found that on this power supply, I could very easily stop or spin the motor contrary to the control signal. That was a little disappointing, but I realize also not at all a fair test, with the motor so underpowered.

Finally, I knew the 754410 is only rated for 1A per bridge, and I was attempting to use it for much more than that. I was being careful not to sustain high-voltage testing for long periods, but I was still curious how the 754410 was reacting thermally. The result was fascinating–I could quite distinctly feel the chip getting warmer as I ran the motor and cooler when I stopped it. I’m used to components heating up, but I’ve never before experienced it so directly in real time (at least, not without scorching my fingers).

I had known that the 754410 wouldn’t be my ultimate drive circuit, but I hadn’t known I would hit the wall with it so quickly. After realizing how hot it was running, I knew the next step was building a drive circuit with discrete power transistors. And I just happened to have some on hand: MOSFETS, from the stepper drivers in some old printers.

Review time in my Malvino–quite possibly the best $130 I ever spent.

Stepper Motors, Part I: Confirming Values

Saturday, May 6th, 2006

The Project

My friend Joel has a computer numerically controlled (CNC) drilling machine that he built from a mail-order unpopulated circuit board and a set of plans. Its table holds materials up to about 10″ x 14″, and I go over to use it any time I need to drill a circuit board. It’s not terribly inconvenient to use his, and it’s always a nice excuse to visit with him while we’re setting it up and letting it run–but I’ve wanted my own for as long as I can remember. They’re just cool.

There are lots of descriptions of and plans for CNC drilling machines on the Web, so I won’t go into a lot of detail. The basic idea for this model, though, is that a drill is suspended in place above a table that slides around to position the workpiece. The table is positioned by long screws (all-thread) turned by stepper motors, which are motors that move small increments (steps) in response to an input signal, rather than running freely. Each step is a small fraction of a complete rotation, and coupled with the worm-drive effect of the lead screw allows for very precise positioning of the workpiece–easily 1/1000″, and often 1/8000″. (Of course, mechanical issues like backlash do intrude, but 1/1000″ doesn’t seem to be terribly hard to achieve.)

The Motors

So . . . I want to build my own CNC drilling/milling machine, and since I do electronics bottom-up, the project starts with the motors. And boy, do I have motors. I have these giant steppers out of heavy-duty wide-carriage impact printers from a former employer just begging to be used.

Big Stepper Motor

If you look carefully, you can see the ruler underneath the motor–it’s a good 2″ in diameter. Pretty heavy, too.

As we wrapped up our TechArt installation, my thoughts have been returning to these motors, and wondering what it would take to start building drivers for them. This weekend, in between community orchestra rehearsals, I sat down with one of the motors and started making notes. Here are the specs from the sticker on the back side:

PULSE MOTOR
TYPE PJ55E1U97A

A / Phase: 2.5
Ω / Phase: 0.85

Nippon Pulsemotor Co Ltd

Uh, .85Ω per phase? Are they kidding??? That’s an insanely low coil impedance compared to what I’m used to on traditional motors. I can see already this is going to be a challenge.

The Coils

The first thing to do with an unknown stepper motor is figure out the coil wiring. Steppers have multiple coils, each determining either one or two rotor positions, and each with an external wire or pair. From the steppers I’ve played with, four wires generally means two coils each powered in alternating directions, five wires is one common plus four unidirectional coil connections, and six wires is three unidirectional coils. This motor has four, so it was a simple check with an ohmmeter to determine which wires go to which coils.

Red to black: 1.3Ω
Orange to blue: 1.2Ω

Internal resistance of meter (shorting probes together): .3Ω
Variation due to probe placement and pressure against pins: up to .2Ω

So yeah, that’s pretty much .85Ω per coil. Wow.

The label says 2.5A per coil. To get 2.5A current, 2.5A * 1Ω = 2.5V and 2.5A * .85Ω ≡ 2.1V. That’s a really low coil voltage, given some assumptions I’ve already made about the drive circuitry, so I can tell that’s going to be a challenge.

Finally, I hooked wires to my bench power supply and touched them to the coil wires, just to watch the rotor move. In that very unscientific experiment, it looked like the stepping behavior (speed and impact of single steps) was about the same when using a 5V supply as when using a 2.5V supply. That gave me hope that I might be able to fudge on the details and use a higher coil voltage than nominal–although I don’t want to heat up the motor and melt the coils during intense use.

The step pattern I tried moved the motor CCW: black/red, blue/orange, red/black, orange/blue.