Shop OBEX P1 Docs P2 Docs Learn Events
L6470 Microstepper (128 step) sample Forth code — Parallax Forums

L6470 Microstepper (128 step) sample Forth code

Peter JakackiPeter Jakacki Posts: 10,193
edited 2015-07-11 23:20 in Propeller 1
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.

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 ;
«13

Comments

  • lardomlardom Posts: 1,659
    edited 2011-12-24 06:39
    Peter, can we order L6470 modules from you?
  • idbruceidbruce Posts: 6,197
    edited 2011-12-24 16:28
    Peter

    It is nice to see another stepper driver in the forum :)

    Bruce
  • hinvhinv Posts: 1,255
    edited 2011-12-25 04:00
    Got pictures?

    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.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2011-12-25 04:30
    Hi guys, I hope to have a website up early in the new year with a range of products for sale. I like to make these available at a reasonable price. I'm not trying to compete with anyone on specs or price but would you be happy to pay $29USD per module? I will have to check on shipping options. You can stack or parallel two modules as each has a master/slave solder jumper. Remember that the 6470 chip is a motor controller and driver so you can just issue commands to go here or there etc and it will handle the ramping and so on.

    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.

    PSM6470-1.jpg
    PSM STEPPER-1.jpg
    PSM6470 Schematic.jpg
    1024 x 1067 - 145K
    1024 x 1139 - 156K
    1024 x 493 - 110K
  • StephenMooreStephenMoore Posts: 188
    edited 2011-12-25 10:20
    I would buy at 29 clams. ST has an eval board they sell for 63.
  • prof_brainoprof_braino Posts: 4,313
    edited 2011-12-25 11:05
    The Reprap CNC uses four stepper drivers (X, Y, Z, and print head). We were thinking of using the work on Reprap as a starting point for other CNC, (milling, laser, etc)

    Instead of single modules, would it be reasonable to make one board with four steppers?
  • PublisonPublison Posts: 12,366
    edited 2011-12-25 16:29
    The Reprap CNC uses four stepper drivers (X, Y, Z, and print head). We were thinking of using the work on Reprap as a starting point for other CNC, (milling, laser, etc)

    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.
  • idbruceidbruce Posts: 6,197
    edited 2011-12-25 16:58
    Very nice.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-01-09 20:29
    I mentioned in one of my posts that I would get around to doing a video of this chip in action. I still haven't had a chance to hook it up to the big stuff but here's a sneak peek until then.

    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.


    L6470vsL293.jpg
    L6470vsL6203s.jpg
    800 x 762 - 342K
    800 x 642 - 291K
  • idbruceidbruce Posts: 6,197
    edited 2012-01-10 03:59
    What do you reckon, pretty good?

    Yeah, I reckon that is pretty nice. Well done.

    Bruce
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-01-10 08:53
    So, how many pins from the prop does it take to run one of these? I think I'm counting 12 prop I/O pins consumed.

    How many of these can one prop chip control?
  • photomankcphotomankc Posts: 943
    edited 2012-01-10 09:04
    So, how many pins from the prop does it take to run one of these? I think I'm counting 12 prop I/O pins consumed.

    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.
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-01-10 11:30
    Hmmm .... if this is a complete controller doing the microstepping and ramping, how can you use 2 of them to run together in a perfect circle?
  • PublisonPublison Posts: 12,366
    edited 2012-01-10 12:02
    Stunning layout and a great video Peter.

    What's the current draw on the big motor?

    Jim
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-01-10 22:42
    No replies to my question?! So, am I wrong saying that this driver does not work good for CNC setups - at least in the auto rampup/down mode? Or is there still the possibility to run it in single step mode? Guess I have to read the specs by myself ;o)
  • photomankcphotomankc Posts: 943
    edited 2012-01-11 13:25
    Well you're telling it how many steps to execute and what rate you want them executed at but it's going to determine the acceleration used and ultimately how fast the motor is actually going to go if there isn't enough room to ramp. Running an arc is going to take motion planning so you can keep the overall motion rate at X IPM by constantly ramping up and down in the two axis motors. It sure seems like a poor fit to that application on it's face. I don't see a way to just feed it step pulses.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-01-11 15:18
    MagIO2 wrote: »
    No replies to my question?! So, am I wrong saying that this driver does not work good for CNC setups - at least in the auto rampup/down mode? Or is there still the possibility to run it in single step mode? Guess I have to read the specs by myself ;o)

    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.
    Your submission could not be processed because you have logged in since the previous page was loaded.

    Please reload the window.
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-01-11 23:27
    Yep ... going to be fun ... and it already starts with straight lines. Suppose you want to mill a diagonal line where delta x = 1000 steps and delta y = 200 steps. If you simply tell 2 drivers to go to these positions you definitely won't get a straight line!
    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!
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-01-11 23:42
    To think that having these operations being directed by an external micro does not change matters at all, the variables still need to be taken into account. There is nothing magical or mysterious about the internal operation, it's documented and is configured through the SPI registers. Even if this chip were operated in it's totally dumb mode and using an external step clock with direction etc being set via SPI I still think it is a very good chip for these reasons if not more:

    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.
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-01-12 02:30
    I do not doubt that you have superior experience with steppers. But what you show in the video is simply driving one stepper and that it perfectly works there. But prof_braino mentioned to use 3 of this drivers to run a CNC ( the reprap to be precise ).

    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!
  • pedwardpedward Posts: 1,642
    edited 2012-01-12 11:44
    From a CNC perspective (I've done a lot of this, including retrofits, programming, and repair), the motion controller is built in to the control, not the motor controller. The ramping is done by the motion controller and the motor driver is "dumb". This is so the motion controller can do accel and decel based on part features. I agree that accell/decel in the driver chip is only of use in 1 axis systems unless you have encoder feedback. Obviously encoder feedback is the part that most are trying to avoid with the use of a stepper in the first place.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-01-13 06:09
    Just a very brief reply while have the opportunity. Bear in mind that I showed a very simple demo of the chip, it is very basic and will have to do until I hook-up a larger system. Having motion control built-in is never a disadvantage as long as you also have manual control which you so have with this chip. Also I not sure why you think acc/dec features are a problem with multi-axis systems because it's not as if the acc/dec is not precisely known, set, and controlled. The chip even senses if steps have been missed based upon the BEMF which BTW is also compensated for. Anyway I can only tell you what I know and a multi-axis system implementation will tell all. If someone wants to play with these modules on a multi-axis system and share the experience then I would be happy to supply the modules no charge to that one. Prof? MagIO2?
  • idbruceidbruce Posts: 6,197
    edited 2012-01-13 07:14
    @Peter

    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
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-01-13 07:21
    If someone wants to play with these modules on a multi-axis system and share the experience then I would be happy to supply the modules no charge to that one. Prof? MagIO2?

    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.
  • pedwardpedward Posts: 1,642
    edited 2012-01-13 11:14
    I won't belabor the point, but I feel an explanation (if for the other viewers) is in order.

    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.
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-01-13 13:35
    @Peter: Thanks for that offer, but as I said I have plans to build my own CNC - which might happen sooner, but most propable it's going to happen later. So it's better for you to pick someone else.

    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?
  • photomankcphotomankc Posts: 943
    edited 2012-01-18 08:57
    I'm also quite interested in your timeline. As I said, the main stumbling block I have now for StepperBot is that I can't ramp between speeds, I can ramp up and down from start to stop but I can't go from one speed to another without 'slam-and-hope' or stopping. This would be perfect since it takes the load of calculating accel out of the picture for my application which will work fine and the current capacity means I can possibly use some of the 80 to 100oz/in NEMA17's I have seen out there.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-01-18 17:02
    @Prof & Bruce - Please msg or email me with a delivery address if you would like to sample a set of four stepper modules. I will supply them with the matching low-profile sockets. I haven't had much time to spend on these steppers but I have found since the video was taken that I had forgotten to lift the lid on the maximum speed, there's quite a difference but I will record some acc/dec profiles later and post these.
  • idbruceidbruce Posts: 6,197
    edited 2012-01-18 17:25
    @Peter

    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.
    Bruce Drummond
    144 North Michigan Avenue
    Hobart, Indiana 46342
    Anyhow, I will give them a good testing. They should be a nice fit for the new machine :)

    Thanks again Peter

    Bruce
  • photomankcphotomankc Posts: 943
    edited 2012-02-22 08:44
    Is this still going anywhere? I cant produce the pads needed to use the 0.65mm leads on these guys reliably so I'd either have to send the PCBs out to be made or buy them pre-made. Since I also rarely get it right the first time that's probably going to cost too much to be practical. My bot could definately benefit from these if you still plan to make them.
Sign In or Register to comment.