L6470 Microstepper (128 step) sample Forth code
Peter Jakacki
Posts: 10,193
I've mentioned this L6470 chip a couple of times on this forum but this is the first time I am starting a thread about it. It's got to be the best stepper chip I've come across, and I've worked with quite a few. The last one was an A3985 microstepper driver which still needed external MOSFETs and current sense resistors etc. For steppers up to 3A rms this one is so compact in a 28 pin HTSSOP package, just needs a little copper to help spread the tiny amount of heat on heavy loads.
I will have some small Puppy style modules back soon if anyone wants to play with these chips, so get ready to rev your stepper motors.
I will have some small Puppy style modules back soon if anyone wants to play with these chips, so get ready to rev your stepper motors.
fl [ifdef L6470.fth forget L6470.fth ] : L6470.fth ; \ L6470H Microstepper motion controller chip demo \ (C) 2011 Peter Jakacki \ Hardware: Propeller CPU \ Software: PropForth 4.6 \ \ Handles 3A rms per winding. Uses SPI interface. \ Define port allocations \ Using Prop's EPROM I2C as clock and data to the L6470 \ Pullups on SDO (from L6470), BUSY, and FLAG as well as \ precautionary pullups on CS and pulldown on RST \ decimal 28 constant .SCL 29 constant .SDA 0 constant .SDI \ data from L6470 1 constant .BUSY \ busy flag - pullup with 10K 2 constant .CS1 \ Select master chip 3 constant .CS2 \ slave chip (or daisy chained) 4 constant .STCK1 \ step clock (optional, not used) 5 constant .STCK2 6 constant .FLAG \ pullup with 10K 7 constant .RST \ Chip standby/reset - pulled down with 10K : !STEP .RST dup pinout dup pinlo pinhi .SCL pinout _sclh .SDA pinout .CS1 dup pinhi pinout .RST1 dup pinlo pinout .RST2 dup pinlo pinout hex ; variable response hex : TXRAW _sclh .CS1 pinlo 80 8 0 do _scll response @ 2* .SDI px? 1 and or response ! 2dup and if _sdah else _sdal then _sclh 2/ loop 2drop .CS1 pinhi ; : TX begin .BUSY px? until TXRAW ; \ Made direction a variable to be added to the command so that it could \ be "set and forget", no need to specify each time. \ variable dir : FWD 1 dir C! ; : REV 0 dir C! ; : +DIR dir C@ or ; hex : CMD TX dup 10 rshift TX dup 8 rshift TX ff and TX ; : SYNCH 0 0 CMD ; \ L6470 application commands - named similar as per programming manual : NOP 0 TX ; : REG! CMD ; \ Simply takes the address as a command and writes the data : REG@ 0 swap 20 or CMD response @ ; : RUN \ ( speed -- ) 50 +DIR CMD ; : MOVE \ ( steps -- ) 40 +DIR CMD ; : GoTo \ ( position -- ) Go to an absolute position 60 CMD ; : GoToDIR \ ( position -- ) 68 +DIR CMD ; : GoUntil \ ( speed act -- ) 3 lshift 82 or +DIR CMD ; : ReleaseSW \ ( act -- ) 3 lshift 92 or +DIR CMD ; : GoHome 70 TX ; : GoMark 78 TX ; : ResetPos D8 TX ; : ResetDevice C0 TX ; : SoftStop B0 TX ; \ Stop after deceleration : HardStop B8 TX ; \ Stop immediately : SoftHiZ A0 TX ; \ Decelerate before bridge disconnection : HardHiZ A8 TX ; \ Immediate bridge disconnection : GetStatus 0 D0 CMD response @ 8 rshift ; : MaxSpeed \ ( speed(10bits) 7 TX dup 8 rshift TX TX ; \ Some console friendly aliases : STOP SoftStop ; : HOME GoHome ; : GO GoTo ; hex : ShowStatus dup 8000 and if ." Step Clock Mode" then dup 4000 and 0= if cr ." Step Loss B" then dup 2000 and 0= if cr ." Step Loss A" then dup 1000 and 0= if cr ." Over Current" then dup 0800 and 0= if cr ." Thermal Shutdown" then dup 0400 and 0= if cr ." Thermal Warning" then dup 0200 and 0= if cr ." Under voltage" then dup 0100 and if ." Wrong command" then dup 80 and if ." Command not performed" then dup 60 and 5 rshift cr ." Motor Status =" . dup 10 and cr ." Motor direction " if ." forward" else ." reverse" then dup 8 and if cr ." Switch Event" then dup 4 and if cr ." Switch Closed" then dup 2 and 0= if cr ." Busy" then dup 1 and if cr ." Bridge disconnected" then cr drop ; \ ********************* DEMO & DEBUG ********************** : L \ List the status of the chip for diagnostics GetStatus ShowStatus ina COG@ dup 2 and 0= if ." =busy " then 40 and 0= if ." =flag " then ; : DEMO !STEP \ Init Stepper chip 4000 begin dup FWD MOVE dup REV MOVE 10 - dup 100 < if drop 4000 then key? until ; : oldboot onboot ; : onboot oldboot !STEP hex ;
Comments
It is nice to see another stepper driver in the forum
Bruce
28 Pins...for a stepper driver. Why so many?
When you say 128 microsteps, do you mean that for the typical stepper motor, you would get 128x200 possible positions per revolution? This sounds like way beyond the mechanical ability of a stepper.
The footprint is standard for my range of Puppy modules with one connector devoted to high current and designed so that connections can be kept short. The underside of the PSM6470 is tinned and does not have a solder mask so I could attach a simple heatsink if I needed to (which I haven't). You can see one of the stepper motors that I run with this module, usually at 24 to 30V or so.
As soon as I can I will do a video of these in operation and show how easy they are to drive in software.
Instead of single modules, would it be reasonable to make one board with four steppers?
One could make a single control board with female sockets to accept Peter's boards without sacrificing any space, (well, maybe a couple of centimeters).
This would allow one to install only the number of driver boards need for the application, ( 1-5 boards for a 1-5 axis machine). And would allow for quick change of a defective stepper driver. With a high enough female adapter, a heat sink could also be implemented on the bottom of Peter's board.
Youtube video
How does an L298 compare with the L6470? Not at all, look at the left-hand photo, the L298 is huge, has a huge heatsink, still requires flyback diodes (which in this case are too small) and a stepper controller etc. It only drives the medium sized motor as seen in the video and not more than half-step. The right-hand photo shows a pair of L6203 DMOS drivers with two great big current sense resistors but still only half-step that drive the larger motor which is the same as the one driven by the L6470.
Also, the L298 is only a 2A driver, not 4A which is a total combined figure vs the L6470's rating of 3A rms per channel.
Yeah, I reckon that is pretty nice. Well done.
Bruce
How many of these can one prop chip control?
It's SPI I see but I think some of the control lines are optional.
I would be very interested. I'm using a ChipKit Uno32 to give me much the same benefit running some steppers for a robot project, minus ramping between running speeds. I'd be really interested in this since it would almost be a drop in replacement except for SPI for what I'm doing and allow me to run some bigger NEMA-17s with even more torque. Could repurpose the Uno32 as more generic sensor controller. When I scoped out the chips to order them they were more expensive than I wanted to pay to get a small driver but $29 for a complete board would fall into the "I'll take 2" category.
What's the current draw on the big motor?
Jim
Good point, I looked at the specs and I guess you would have to have a common external clock rather than the internal one plus you would need to load the two chips in parallel which I can do with my setup except for the external clock which I left off in this particular design. There is always the step clock input to manually control it I guess. I will jumper a couple of prototypes to use an external clock and have a go at synchronizing two motors to draw a circle, should be fun.
There are several registers which control the acceleration and deceleration profile so the chip doesn't try to do it's own thing, it will behave as you tell it.
Here's a link to a pdf article.
BTW, I thought I sent this message off yesterday but when I checked this morning it wasn't so, the forum seems to have a timeout these days where you need to reload the page.
You really need to know exactly how the ramping works and calculate/set the according parameters beforehand. And the speed settings need to be calculated as well. Otherwise driver y is done long before driver x.
Hmmm ... external clock ... maybe this really helps. You drive x with clk and you drive y with clk * delta y / delta x. Then both drivers should reach the end of the movement in the same time. But the ramping parameters need to be calculated.
In special cases you also have to calculate the max. speed. If the number of steps for both is different and the number of steps of one driver is not enough to ramp up to full speed you also have to limit the other drivers max. speed ....
For circular or any other free form movement you really need some kind of single step-mode. Maybe you can tweak the min speed being the max speed and then send goto-commands step per step. But then a simple direction/step-driver is much easier.
All in all I think this driver suits much better to a PCB drilling machine than to a CNC mill, because there you don't care how you got to a point - take the shortest way is fine there!
1) up to 128-step microstepping built-in with it's own current sensing (no resistors)
2) very compact and efficient 3A drivers
3) built-in protection with feedback to the controlling micro (over-temperature, stalled, over-current, etc)
@MagIO2 I've worked with a lot of different chips and discrete designs so I don't understand what your beef is with this chip, it's clearly superior to you name it.
I have to admit that I don't have experience with CNC so far ... only some plans to build one by myself somewhen in future. That's why I get attracted by those kind of threads. I could of course take all things I read as granted, but I prefere to think. And thinking often raises questions for example about this automatic ramping (which you mentioned in one of your first posts). I simply see the chance that it could be hard to let 2 (for a 2D mill setup) or more (for 2.5D mill) drivers work together in a way that you can mill -lets start with the simplest- a straight line in any possible direction.
To get a straight line in a 2D setup your ramping has to be synchronized over 2 drivers working with different speed values. A 2.5D mill adds another driver which needs to run synchronously. You have to take into account that the ramping might not reach the max-speed if the number of steps is to little for one driver whilst all other drivers would reach the max speed. This would definitely not end up in a straight line!
I did not have the time to read the full spec of the chip so far, so I did not know in my previous post if something like a "dumb mode" exists.
I think I raised valid questions and it's not about having a beef with this chip, I just want to have an idea if this can be solved with that driver in which way or not at all. The "All in all I think ...." sentence is only true for the knowledge I had at this time and hopefully it changes within this thread ;o)
And ... I would also be willing to buy some of those babys to find out, so please don't feel offended!
My name was not mentioned there, but I have a machine all designed, blanks cut, and ready to be drilled. This will be the PCB drilling machine which I have referred to several times on the forum. This is not the old driller, but a new design, which I intend to market on my web site. If the offer is open to me as well, I would like to review your product and post my opinion and findings, and if I am happy with them, I would seriously consider supplying them with my driller until I get around to making my own drivers.
Bruce
Yes, please! Actually, I would send them off to Sal, he is the master. First I will send him the link to the datasheet, and he will decide if this is part of the schedule. I'm pretty sure this an pololu A4988 would be good baseline for CNC stepper control. BUT this won't be on the release list until summer, I think, since we are taking so long with 5.0 release.
If you would be interesting in send a set of 4 to Sal, I would be willing to buy another set of 4 so I can do testing. But let me run it by him first.
Let's say you want to draw a circle. The points of the circle are obviously calculated from sin/cosine. When you draw a quadrant of a circle, both axes are constantly changing acceleration in relation to each other. When you start the arc, one axis is moving slowest and the other fastest, the become equal when you reach the 45 degree point, then the acceleration reverses and the profile is repeated in reverse.
If your stepper driver is controlling acceleration and you have no control over destination and time, you cannot accurately control a multi-axis system without having realtime control over the motor position.
Let's consider how an older commercial closed loop system might work:
Servo A and Servo B have encoder feedback and velocity inputs. The controller has to modulate the velocity input to control the position of the motor and speed up or slow down the motor based on encoder feedback. This is realtime closed loop control.
Standard open loop stepper control is a bit simpler:
begin loop
is motor X step position in correct place
yes: skip
no: step motor
is motor Y step position in correct place
yes: skip
no: step motor
Run that loop a few k times per second and you have synchronous open loop stepper control. Each axis runs in lockstep with the others, no movements happen outside of that loop.
pedward has now the right explaination for the concerns I had in the beginning. You NEED to control acceleration in a multi-axis setup to be able to have accurate free-form movements. That's why I said the ramping-mode of those drivers is usefull in PCB drilling setups, but not in CNC milling setups.
In milling setups it might be interesting to test whether the ramping mode might be usefull in some sense - that's the fun-part we talked about at the beginning ;o) Of course for positioning the mill it can be used. Maybe for straight lines it also makes sense?
What's your timeline? When do you plan to offer those babies for selling?
Thanks Peter.
Building my new PCB Driller is my next order of business after I finish my exposure box samples. As I mentioned, the blanks for the machine are all cut and the main thing left is drilling and tapping the pieces. I will have to do some research just to find all the specs for these drivers, but I should be able to find them.
"I ain't hiding from nobody, nobodys hiding from me" - Lynyrd Skynyrd(Call Me The Breeze)
Just in case someone wants to hear a nice live version http://www.liveleak.com/view?i=f30_1317204020
Since it is already on my patent information that I posted here and on my web site, my address isn't a secret.
144 North Michigan Avenue
Hobart, Indiana 46342
Thanks again Peter
Bruce