Sunday, January 30, 2011

Custom Heat Sinks

I bought the HobbyCNC kit that included a driver board, stepper motors, power supply and assembly instructions because I knew I didn't have the knowledge to select the components and assemble it all myself. I had considered a cheaper driver board based on a TB6560 that was readily available on eBay but I just didn't know enough about the power requirements nor did I have any idea how I'd put it all together in an appropriate case. But the big problem with the TB6560 was that there seemed to be little documentation and zero support. The HobbyCNC company has a Yahoo group to support their product and that was enough for me to choose it. The fact that they had nearly all the components I would need in one package was icing on the cake.

I knew up front I would be deviating from the plans. I would not be using a computer with a parallel port to communicate with the driver. Instead, I'd be using an Arduino microcontroller. In my last post, I talked about the opto-isolator circuit I am building. Normally, the signals to the driver board get their power from the computer, not the driver. It's the computer, or in my case, the Arduino, where the signal originates that provides the power for the signal. The electricity flows across to the driver, runs around the circuit, then comes back through the ground wire. This ground is common to both the computer and the driver, hence it is the electrical connection through which Bad Things can happen to my computer if the driver and it's 32 volts of power should go south. So the opto-isolator provides the protection I need.

This means the power (electricity) from the computer does not go to the driver and back, just to the opto-isolator and back. The side of the isolator circuit where the driver is needs to have a power source to "reconstitute" the signal that comes across the void in the form of light. It's not like a solar cell that generates electricity when the light hits it. So I needed a 5V power source. Since the driver board logic runs at 5V, it seems a no-brainer to tap off this to power the isolator. So I posed the question to the support group, where is the best place to get 5V from? To my surprise, the response was generally, "You don't want to do that". It was suggested that I use some other source, like a "wall wart" which I really didn't want to do. It's bad enough my transformer doesn't fit in the case. The "help" I got was pretty terse - no real explanation for why so I had to do some work to understand things.

Ultimately I learned that the limiting factor was the 5V regulator on the EZ Driver. This is in the form of a TO220 package that has a small, thin metal "tab" that provides for minimal heat dissipation. According to some calculations I don't understand, this regulator is near the edge of its ability to dissipate heat. I couldn't get anyone to tell me how I could remedy this, I asked if putting heat sinks on it would take care of it, but apparently no one wanted to be responsible for what happens. I finally got some help from someone who contacted me outside the group and said the worst that can happen is the thermal protection circuit would shut it down.

So I figger, if heat's the problem I'll just put heat sinks on the 24V and 5V regulators. I looked them up online. Radio Shack sells 2 varieties for $1.50 or $2.00 each. No sweat, I'll buy a couple and slap 'em on. I went to "The Shack" by my house and found what I needed. I was surprised to find them to be much bigger than I thought they would be. I was advised that since the 2 regulators were at different potentials, the heat sinks should not touch each other, nor anything else. These Radio Shack monsters were pretty close to touching each other, but the real problem was installing them without obstructing access to other components, particularly one of the variable resistors for adjusting the stepper motor current. So clearly not going to work.

Well a working manual milling machine and a box of 1/2 inch aluminum stock was just asking to be made into heat sinks, so who am I to say no. 2 hours later I had 2 custom heat sinks. Here they are next to a TO220 package and the Radio Shack heat sink:


And here they are installed:


So I'll return the Radio Shack heat sinks I paid $3 for. I'm not a great machinist. At a modest $20 an hour, I figure this is a $40 pair of heat sinks. But they fit just right.

Wednesday, January 26, 2011

Don't Cross The Streams!

Dr. Egon Spengler: There's something very important I forgot to tell you. 
Dr. Peter Venkman: What? 
Dr. Egon Spengler: Don't cross the streams. 
Dr. Peter Venkman: Why? 
Dr. Egon Spengler: It would be bad. 
Dr. Peter Venkman: I'm fuzzy on the whole good/bad thing. What do you mean, "bad"? 
Dr. Egon Spengler: Try to imagine all life as you know it stopping instantaneously and every molecule in your body exploding at the speed of light. 
Dr Ray Stantz: Total protonic reversal. 
Dr. Peter Venkman: Right. That's bad. Okay. All right. Important safety tip. Thanks, Egon. 


My system is composed of a laptop computer (a MacBook Pro that belongs to my employer and I use to make a living), an Arduino microcontroller and a HobbyCNC EZ Driver stepper driver. The stepper driver has a 32V power supply and can push 10A before blowing a fuse. The Arduino is powered by the laptop. Since the Arduino sends signals to the driver, there has to be a connection between them, meaning there is is a connection between my laptop and that 32V, 10A power supply. I've already tested the driver with an old desktop PC so I know I put it together right, but there is probably still some opportunity for me to make a mistake. I can't afford that.

I said there needs to be a "path" from the laptop to the stepper driver. That's usually a wire carrying electricity. There is another way. Imagine 2 ships in the night communicating by flashing lights at each other, Morse code or whatever. This is the basis for an opto-isolator, usually an LED and a light sensor in a light-tight box. Properly designed, such a circuit keeps the two sides electrically separated. It would take a lightening bolt to jump across such a barrier. A good surge protector could add even more protection.

I tried to find an existing product I could just plug in. What I found was either too expensive or possibly too slow. Or I couldn't find a way to buy it. I really wanted to buy a couple of these. The RepRap folks seemed to have figured everything out. Except it didn't seem to be for sale. I found an affordable one but it didn't used the same chips as the RepRap design and from what I could find, the affordable one seemed like it would not be fast enough. The RepRap design calls for a chip with 10Mb throughput which according to my calculations... well I don't know how to figure out if it's fast enough, but I trust the RepRap guys.

So I downloaded the schematic and bought the components. The top picture is a test setup, just blinking some LEDs. I spent quite a bit of time studying and researching everything. I tore down the prototype and rebuilt it so many times I can do it from memory now.

Here's my test setup connected to the stepper driver:



I've got a potentiometer at the bottom that I turn to adjust the speed. I cobbled together a program that uses the Timer1 component of the Arduino to trigger interrupts that step the motor. I made several mistakes both in wiring and coding but finally got it working. I found the shortest time between steps to be 300 microseconds. I'm half-stepping the motors so with my 1/4-20 lead screw that works out to 22 inches per minute of feed. I think that's pretty fast. Much faster than I'll be cutting at. My rapid movements might not be more than 15ipm.

The opto-isolator subproject isn't really something I accounted for in the beginning. It's going to amount to quite a bit more work than I'd like to do, but I'm really learning a lot and I think it's going to be quite satisfying in the end.

Thursday, January 13, 2011

Stepper Driver Testing

Earlier this week I mounted the EZ Driver in the case:


The parallel cable can be seen there running out the back of the case. This is for testing purposes and will be replaced by the Arduino. I'll probably put the Arduino in the left rear where the transformer was supposed to go. Then I wired up the stepper motors:


I'm not the best at soldering, but I actually found the PCB soldering to be easier than the wires for the steppers. The problem is holding the wires together while you solder. And remembering to put the heat shrink tubing on first. There are 6 wires (with 2 doubled). Even when I put all the heat shrink tubes on first, one or more would fall off and I wouldn't notice. Then I'd have to reheat the wires and pull them apart. Or I'd heat them up too much and the tube would fuse where it was - not covering the joint. The first of the 6 wires was easy, but after that, the tension and rigidity of the wires made it hard to keep them in place so my hands were free to work the iron and the solder. You can see my "helping hands" unit on the right. I didn't bother with that, I got faster as I went and developed a workable technique. I found it difficult to get the outer heat shrink tube to stay up against the motor while shrinking it. It's pretty good, though. Here's everything lined up, ready for testing:



I will be building the "computer" from an Arduino microcontroller. It's going to take me some time to develop it and I just gotta know if the thing works. I don't want to work on the Arduino part and have it not work and me not know which part is failing. So I dragged my backup PC down to my shop:



Yup, that's Darth Vader in the background. Seeing this behemoth in my shop is, well, not pleasing. I could fit my mill and controller on the same table the computer is on. But it's a PC with a parallel port and it runs software I can use to test it. I downloaded a copy of EMC2 on Ubuntu Linux. It has a "live CD" mode meaning I can run it from the CD without installing it. I was not able to get EMC2 to run, it kept crashing after loading the config file. 

I was able to get the configuration utility to run and it had a test mode you could jog the axes with and that was good enough. I looked things over one last time and turned on the driver. There was a loud thunk as the motors energized, a bit disconcerting. But I jogged all 3 axes and it worked great! 

There's a lot that I had to do right to get this far. I do some woodworking from time to time. Generally if I can measure from the wrong end, put the piece on the saw backwards or upside down, cut on the wrong side of the line, I'll do it. I have to check my work very carefully. I kept my focus pretty well on this assembly project so I'm quite pleased. I even deviated from the plans and didn't blow anything up!

The next step is to heat shrink the wires inside the case, tape down the cap and neaten things up a bit. Then I need to design the opto-isolation layer. More on that in my next post.

Saturday, January 8, 2011

Acceleration

Nothing can move from any given speed to another speed instantly. I could tell the motors to jump from speed A to speed B instantly but the machine is going to resist. The result will be jerky motion, rough cutting and wear on the machine.
I've studied a number of G Code interpreters for the Arduino. The RepRap project has 2 or three, I can't figure it out. There's "Arduino G Code Interpretor", the "new RepRap firmware", and "FiveD on Arduino". The contraptor project recommends one of these or GRBL. They seem to be related in one way or another. The latest versions all seem to be well developed. None of them do any sophisticated "look ahead" which is understandable given the limited horsepower of the Arduino.


One or more of these interpreters support "linear interpolation" of speed. IOW, they will calculate the change in speed per unit of time to get from one speed to another along a straight line movement. I will be doing as much "heavy lifting" as I can in the host software, so I have the opportunity to precalculate speed changes and send this information "prebaked" in the G Code to the Arduino.


Once the path is built (a series of straight line movements), what I'd like to do is make a pass through the path setting the speed at each point to the "maximum" speed. This speed will likely be related to the change in angle between adjacent lines. A zero degree change will be full speed. Maybe by 70 degrees, the max speed will be zero. I could get more sophisticated down the road, but I think this is a good place to start.


My mill is small. In fact there probably isn’t a smaller one. Without any major chucks of metal on it, like my rotary table, it doesn’t have a whole lot of momentum. The steppers are 205oz so will probably get it up to speed quickly. But not instantly.


There is some “full speed” that I will run my machine at. I think this will be determined experimentally and will be based on how fast the steppers will be able to go (possibly under some average load) without losing a step. If we’re going from stop to full speed, there is some minimum distance that we’ll want this to happen over. I’m calling this the “full acceleration distance” or FAD. This will also be determined experimentally and will probably be based on my perception of “jerk”, deflection and vibration. I’ll be conservative since I’m more concerned about wear and tear than production speed.



The speed at the start of a line segment is SS, the speed at the end ES. Full speed is 1.0, SS and ES are from 0.0 to 1.0. For any given acceleration (where ES > SS) there is some minimum distance required to reach the end speed. This is “delta acceleration distance”, DAD:


DAD = (ES - SS)(FAD)


I’ve thought of 3 scenarios relating the change in speed to the length of the segment, L.
If DAD > L then we don’t have enough room to go from SS to ES, so we need to reduce ES.





The target end speed is the top of the dotted lines. The right dotted line is the distance it will really take to get to 0.75. The new, reduced end speed is the intersection of the left dotted line and the diagonal line. Since our start speed is not zero, we need to shift the whole thing up and down by 0.25:


Reduced ES = (L / DAD)(ES - SS) + SS


If we say FAD is 3 "units", then DAD is 1.5 since we've changed speed by 0.5 (0.75 - 0.25). Judging from the illustration L looks to be around 1.0. So to verify, we substitute these numbers:


0.58 = (1 / 1.5)(0.75 - 0.5) + 0.25


0.58 looks to be about right from the illustration.


In the second scenario, we have at least enough distance to go from SS to full speed and back down to ES. We need to address this scenario if


L >= (1 - SS)(FAD) + (1 - ES)(FAD)



What we want to do is split the segment into 3 parts and set the new points to full speed.


L1 = (1 - SS)(FAD)
L2 = (1 - ES)(FAD)


Now’s the tough one. We have more than enough room to get from SS to ES (but not enough to get to full speed) which means we can hit a speed higher than ES and come back down to ES. We know we have this scenario if


DAD < L and L < (1 - SS)(FAD) + (1- ES)(FAD)



What we need to do here is split the line in 2 and set the “mid speed” MS at the new point. If we were to accelerate from SS continuously until we move a distance of L, we would have reached an end speed we’ll call VES for virtual end speed (0.92):


VES = SS + (L / FAD)


Assuming our acceleration distance is equal to our deceleration distance, MS is half way between ES and VES:


MS = (VES + ES) / 2


The distance from MS to ES is:


L2 = (MS - ES)(FAD)


Now we can split the segment a distance of L2 from the end and set the speed to MS.


To verify, if we say L = 2, then VES = 0.25 + (2 / 3) = 0.92


MS = (0.92 + 0.75) / 2 = 0.835


L2 = (0.835 - 0.75)(3) = 0.25


I took measurements from the illustration and I come up with something closer to 0.45 for L2. The slope of the diagonal line is pretty close to 3 but not right on. This seems like a big discrepancy, but I can't seem to find the problem if there is one. I'm tired of working on this so I'm putting it out there. I'll come back to it later.


And the fourth of my three scenarios is DAD = L in which case we don’t have to do anything.


All of these scenarios are for ES > SS or an increase in speed. I figure I'll walk through the path forward and ignore decreases in speed. Then I'll walk backward with the same algorithm as going forward and it should correct the cases where we need to decelerate faster than our constant.

Tuesday, January 4, 2011

Case Assembly

I weep the loss of the post that was supposed to go up instead of this one. I spent several days (of here and there sessions) writing up my approach to acceleration complete with equations and graphs. I was preparing to make some final tweaks when I hit some random key combination and deleted some stuff. I believe I hit command-Z to undo it, but instead the entire contents disappeared. 'Round about the same time the Auto-Save Auto-Destroy feature kicked in and saved my post as completely empty. Much to my surprise there is no "versioning" of posts. All was lost. So it will probably be a while before I can resurrect it.

In the meantime, I've been working on the case and power supply. I purchased the HobbyCNC EZ Driver package which included everything needed except a 24V 10A transformer and case. A PacTec DM-4 case was recommended along with a couple of transformers. The transformers were out of stock. A friend gave me an industrial 24V 12A transformer mounted in a NEMA 1 case. It's much too big to fit inside the PacTec case so I'll be mounting it externally and deviating from the plans.

The plans call for a wiring path something like this:

  • AC 110 from the wall
  • Power switch
  • Hot wire through 4A fuse
  • Transformer
  • Bridge rectifier
  • Capacitor
  • Negative wire through 10A fuse
  • Driver board

I'll be going:

  • AC 110 from wall
  • Hot wire through 6A fuse (to be reduced to 4A)
  • Transformer
  • AC switch
  • Bridge Rectifier
  • Capacitor
  • Negative wire through 10A fuse
  • Driver board


So I've left out the 4A fuse in the case and the switch is on the 24V AC lines. Not being an expert in electricity, I had to run this by my dad to make sure the rating on the switch was good for this. It's marked AC 125V 10A so I should be fine. Apparently it's a big No-No to switch the DC lines as some fantastic thing happens in the motors and the driver blows up. I hope I don't blow the fuse...


I tested things as I went. The transformer secondaries produced 24V AC as expected. I temporarily connected them to the bridge rectifier but couldn't get a stable reading of DC output. This is because the AC/DC conversion produces a "wave" of current or voltage or whatever. After connecting the capacitor, things smoothed out and I got 32V DC output. I was expecting the output to be greater than 24V but I haven't had time to look up the theory that explains this.

Here's the transformer with wiring exposed with a 9V battery for scale (I didn't have a quarter handy). I studied it a bit to find out it was properly wired.

Here's the case prior to work.

Here's the case with all the parts in place. I haven't committed to anything yet. The capacitor and the driver board are just sitting in place. I haven't even put the heat to the heat-shrink tubing yet. I'd like to see some motors move first. I tested the DC output and I'm getting 32V. I applied this to the driver board and got 5V logic on the test pad. So far so good. Next is to solder on the driver chips and install the heat sink. I'll be using my mill for the heat sink, so I'll need good dimensions first for the screw holes.

Here's a shot of the front of the case. The plans called for 10 5/8" holes for ventilation. But I've got a mill and a DRO - I'm not afraid to use it! So I made 40 slots. That looks better.

And the transformer nicely wired and ready to go.