Shop OBEX P1 Docs P2 Docs Learn Events
EasyDriver 4.4 from Sparkfun - How to use? — Parallax Forums

EasyDriver 4.4 from Sparkfun - How to use?

JBWolfJBWolf Posts: 405
edited 2013-07-14 16:41 in Propeller 1
Hello,
I decided to get one of the EasyDriver stepper controllers from sparkfun:
https://www.sparkfun.com/products/10267

This is the newest version and supports 3.3v pulse input, so I would like to control it with the propeller.
I have never worked with a driver like this and was hoping to get some direction on how to use and program for this driver.

Some questions that come to mind immediately...
For sending a step pulse... I'm assuming I can just turn the step pin high then delay 1ms then go low? Or does the delay need to be +/- that value? What is the minimum delay allowed between pulses (from end of one pulse to start of next)?
For changing direction... How does the dir pin work? I cannot find much info on this, How do I use it to set forward or reverse motion?
For microstepping... The product description says this can do up to 8x microstepping. What pin changes the microstep value, and how do I use it?

I couldnt find an object in the exchange for these drivers... so maybe I'll upload what I eventually create to help others learning.
I am comfortable enough with spin to write the code, just need guidelines on the pulses and general usage of this type of driver... especially the dir pin, I have no information on this at all and dont know where to begin.
Hoping to get a motor turning with this driver tonight or tomorrow.
Thanks,
J

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-13 18:23
    I wouldn't worry about micro stepping to start with (plus I don't know how that works with the EasyDriver).

    I really don't think the pulse length matters in this case. As long as you're using Spin for the pulse it should be long enough. I'm pretty sure just the rising edge of the pulse is all that matters to the driver.

    The direction pin should be set either high or low. The stepper will turn one direction with the direction pin high and the opposite direction when the pin is low.

    By just worrying about steps and direction, it's easier to control a stepper motor since the driver board takes care of sending the high/low pattern required by the stepper.

    I know of an object for controlling three motors with this type of controller but it's intended for a CNC machine. You may be better off making your own program to control it. It's probably a good idea to add some ramping to the program to increase (and decrease) the steppers speed over time.

    Here's a link to the CNC object.

    Do you know how to do the ramping? If not, let me know and I'll see if I have an example to show you.
  • JBWolfJBWolf Posts: 405
    edited 2013-07-13 19:45
    I understand the concept behind ramping but not sure how I should program for it exactly, I would love to see an example.
    Definitely interested in the CNC code... I am a CNC operator and have been wanting to make my own small size cnc.

    So for direction, lets say a high state = forward.... I dont have to keep it high all the time right? just before/during a pulse.
    For microstepping, the description on the sparkfun page says it defaults to 8, which is what I will primarily want to use... but it would be nice to know how to change this for faster speeds.

    Should I use resistors to limit the current from/to the prop/easydriver pins? not sure what the max input current of the easydriver or the avg output of the prop is... but I'm guessing 5ma for an input signal to the easy driver would be enough, so... 3.3v / 0.005a = 660ohms
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-13 21:50
    JBWolf wrote: »
    I understand the concept behind ramping but not sure how I should program for it exactly, I would love to see an example.

    I may have spoke too soon. While I have examples of ramping servo and motor speeds, ramping stepper speed is a bit different since one needs to change the pause between steps to change the speed. I couldn't find any examples of how to do this.
    JBWolf wrote: »
    So for direction, lets say a high state = forward.... I dont have to keep it high all the time right? just before/during a pulse.
    I think you're better off leaving the direction pin in the same state unless you want to change direction. If you're want the stepper to rotate forward then just keep the pin high.
    JBWolf wrote: »
    For microstepping, the description on the sparkfun page says it defaults to 8, which is what I will primarily want to use... but it would be nice to know how to change this for faster speeds.

    Should I use resistors to limit the current from/to the prop/easydriver pins? not sure what the max input current of the easydriver or the avg output of the prop is... but I'm guessing 5ma for an input signal to the easy driver would be enough, so... 3.3v / 0.005a = 660ohms

    The input pin on the EasyDriver will have a high impedance. You don't need resistors in this case. Very, very little current will flow (microamps).

    I'm working on some test code for step and direction drivers. I plan to finish it tomorrow. I'll post a copy here as soon as I have it working.
  • whickerwhicker Posts: 749
    edited 2013-07-14 00:23
    Duane Degn wrote: »
    I may have spoke too soon. While I have examples of ramping servo and motor speeds, ramping stepper speed is a bit different since one needs to change the pause between steps to change the speed. I couldn't find any examples of how to do this.

    You convert your scalar speed command value to a frequency. 0 = 0 Hz. One increment of speed value should make intuitive sense (one RPM, degrees/sec, or % of max speed, or some fixed point fraction thereof). Ideally you would have some adjustable parameters like number of steps per revolution and number of microsteps so you can come up with a motor shaft speed that is consistent in magnitude with your speed command value. You could also have parameters to do a gearbox and screw pitch conversion on the command side, so your ramping and final speeds are in linear format (inches per second, mm/s, etc).

    You would ideally build this in modular blocks like most industrial drives do, as in one section is the ramp function generator that generates a speed from setpoint-actual value, another handles the feedback control loop, and another section converts the velocity command to step and direction.

    You run through the control loop calculations at a specific fixed time interval (1 ms, 10ms, whatever), but your frequency generator would be free-running. The frequency generator would need to be written so as to switch to a new frequency at a transition point from low to high, or high to low, to avoid glitches. You want to get a complete pulse, not switch as soon as the speed command to it changes and possibly give a very tiny pulse which will be interpreted as a demand to suddenly go very, very fast for that instant.

    You could do encoder simulation by just feeding back the step and direction internally and incrementing or decrementing a position register each step pulse, then scaling to your unit system. The speed control loop would generally be a Proportional-Integral type loop, with optional feedforward. The derivative portion of the traditional PID loop in motion control has proven again and again to be a terrible idea (terribly picky, prone to oscillation, super sensitive).
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-14 07:57
    whicker wrote: »
    You convert your scalar speed command value to a frequency. 0 = 0 Hz. One increment of speed value should make intuitive sense (one RPM, degrees/sec, or % of max speed, or some fixed point fraction thereof). Ideally you would have some adjustable parameters like number of steps per revolution and number of microsteps so you can come up with a motor shaft speed that is consistent in magnitude with your speed command value. You could also have parameters to do a gearbox and screw pitch conversion on the command side, so your ramping and final speeds are in linear format (inches per second, mm/s, etc).

    You would ideally build this in modular blocks like most industrial drives do, as in one section is the ramp function generator that generates a speed from setpoint-actual value, another handles the feedback control loop, and another section converts the velocity command to step and direction.

    You run through the control loop calculations at a specific fixed time interval (1 ms, 10ms, whatever), but your frequency generator would be free-running. The frequency generator would need to be written so as to switch to a new frequency at a transition point from low to high, or high to low, to avoid glitches. You want to get a complete pulse, not switch as soon as the speed command to it changes and possibly give a very tiny pulse which will be interpreted as a demand to suddenly go very, very fast for that instant.

    You could do encoder simulation by just feeding back the step and direction internally and incrementing or decrementing a position register each step pulse, then scaling to your unit system. The speed control loop would generally be a Proportional-Integral type loop, with optional feedforward. The derivative portion of the traditional PID loop in motion control has proven again and again to be a terrible idea (terribly picky, prone to oscillation, super sensitive).

    Thanks for the information whickers.

    I don't think I was planning on having any feedback with the CNC machine. Don't many (most?) steppers in CNC routers run without encoders?
  • Kirk FraserKirk Fraser Posts: 364
    edited 2013-07-14 10:34
    Duane Degn wrote: »
    I don't think I was planning on having any feedback with the CNC machine. Don't many (most?) steppers in CNC routers run without encoders?

    Most in CNC is relative. Since I have only one, most of my CNC's, a MaxNC 15 CL (closed loop) has position encoders on each servo. With the encoders its accuracy is about 2 or 3 thousandths of an inch. With your 12 bit magnetic encoders, the accuracy would be much greater, up to the limit of the servo motors. If you take one inch and divide it by 4096 you have greater than a quarter of a thousandth of an inch since the distance of one thread turn is less so let's say one turn of the screw is 1/16" travel, that's another order of magnitude in accuracy, better than 10 thousandths of an inch its about 2 hundredthousandths of an inch.

    If precision PWM can drive a servo a little closer to that accuracy then you can both sense it and drive to its maximum accuracy. I don't know the maximum precision of a servo. But if more accuracy is desired, you can use a gear instead of a direct drive from the servo to the screw.

    In theory the reason for having encoder feedback is precision. If you send a signal out to move a certain amount something might interrupt that command, whether a power surge or a little tougher material being chipped away or accumulated backlash slop and it might not actually get there without feedback to tell it to resume travel until the target is achieved.
  • JBWolfJBWolf Posts: 405
    edited 2013-07-14 16:17
    I have been studying servo coupled encoders for positional accuracy, they get very expensive! But I see these are by far one of the best options in accuracy despite the lack of torque when compared to a stepper.
    I understand exactly what you mean by increasing accuracy because of the number of TPI on the lead screw.
    Right now I am just working on a small project, the stepper is a very tiny one with 3.75deg steps... but after this project is done (hopefully by next week), I would like to get into more complicated stuff.
    So this info is great.

    I do not see a way to incorporate ramping with the easydriver with that type of method.
    The only way I see it being possible is by adjusting the microstepping... going from 8 to 4 to 2 to 1 to increase acceleration while retaining maximum torque at beginning of motion.
    Otherwise it would be like you say, just changing the amount of time delay between pulses.
  • JBWolfJBWolf Posts: 405
    edited 2013-07-14 16:22
    I have the EasyDriver working!
    Was alot easier than I had initially imagined.
    I still have not found any information on how to change the microstepping rate... I would like to find this info.

    Here is the code I produced:
    {{
    
    SparkFun EasyDriver v4.4 Bi-Polar Chopper Driver
    10PU-M204ST Stepper Motor - 3.75deg per step - 360deg = 96steps
    
    Direction Pin:
     Low  = CCW
     High = CW
    
    Loses Steps at 30000 delay 
         
    }}
    
    CON
    ' Set Processor Speed @ 80mhz
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    ' Global Pin Assignments  
      StepPin = 23
      DirPin  = 22
    
    
       
    PUB  Main | LocalVariable
    
    dira[StepPin]~~                        ' Set StepPin to OUTPUT
    dira[DirPin]~~                         ' Set DirPin to OUTPUT
    
    outa[StepPin]~                         ' Set Step pin to low to initialize
    outa[DirPin]~                          ' Set Direction pin to low to initialize
                             
    waitcnt(clkfreq * 3 + cnt)             ' 3sec Delay Before Starting   
         
     repeat                                ' Start endless loop
    
      outa[DirPin]~                     ' Set Direction pin to LOW to for Reverse
    
       repeat 4                         ' Nuber of times to revolve 360deg
        repeat 768                         ' 360deg / 3.75deg = 96steps x 8microsteps = 768steps = 1 revolution
          outa[StepPin]~~                  ' Set StepPin HIGH to start pulse       1step @ 8x Microstep = .46875deg
           waitcnt(clkfreq / 15000 + cnt)  ' Pulse HIGH time
          outa[StepPin]~                   ' Set StepPin LOW to end pulse
           waitcnt(clkfreq / 15000 + cnt)  ' Pulse LOW time
           
       waitcnt(clkfreq * 2 + cnt)          ' 5sec delay after Reverse rotate    
    
      outa[DirPin]~~                    ' Set Direction pin to HIGH to for Forward
    
       repeat 4                         ' Nuber of times to revolve 360deg
        repeat 768                         ' 360deg / 3.75deg = 96steps x 8microsteps = 768steps = 1 revolution
          outa[StepPin]~~                  ' Set StepPin HIGH to start pulse       1step @ 8x Microstep = .46875deg
           waitcnt(clkfreq / 15000 + cnt)  ' Pulse HIGH time 
          outa[StepPin]~                   ' Set StepPin LOW to end pulse
           waitcnt(clkfreq / 15000 + cnt)  ' Pulse LOW time 
    
       waitcnt(clkfreq * 2 + cnt)          ' 5sec delay after Forward rotate         
    
  • JBWolfJBWolf Posts: 405
    edited 2013-07-14 16:38
    Does anyone by chance know of a low cost servo with encoder I could get for testing?
    I have some 8" lead screws I would like to test with.

    Also, I have some of the small motors with miniature lead-screw attached that I harvested from a DVD player.
    I would like to get one of these working but cannot find much specifics for these motors... it is a 4-pin stepper.
    Does anyone have experience with one of these?
    IMG_2711 (2).jpg
    1024 x 768 - 131K
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-14 16:41
    whicker wrote: »
    You run through the control loop calculations at a specific fixed time interval (1 ms, 10ms, whatever), but your frequency generator would be free-running. The frequency generator would need to be written so as to switch to a new frequency at a transition point from low to high, or high to low, to avoid glitches. You want to get a complete pulse, not switch as soon as the speed command to it changes and possibly give a very tiny pulse which will be interpreted as a demand to suddenly go very, very fast for that instant.

    Okay, this is my attempt at a frequency generator. "par" would hold the address to the delay amount (in clock cycles). The variable after delay would be the total step counter which the PASM cog would write to each loop it preformed a step.
    DAT ' PASM code                        org
    entry                   or      dira, stepMask
                            mov     stepsAddress, par
                            add     stepsAddress, #4
    loop                    wrlong  totalStepsCog, stepsAddress
    smallLoop               rdlong  cogDelay, par wz
                  if_z      jmp     #smallLoop
                            shr     cogDelay, #1 
                            mov     wait, cnt
                            add     wait, cogDelay
                            or      outa, stepMask  ' step pin high
                            waitcnt wait, cogDelay
                            andn    outa, stepMask  ' step pin low
                            waitcnt wait, cogDelay
                            mov     pins, ina
                            and     pins, directionMask wz
                  if_z      sub     totalStepsCog, #1
                  if_nz     add     totalStepsCog, #1
                            jmp     #loop
                                                
    totalStepsCog           long 0
    stepMask                long 1 << STEP_PIN
    directionMask           long 1 << DIRECTION_PIN
    stepsAddress            res 1
    cogDelay                res 1
    wait                    res 1
    pins                    res 1
                            fit
    

    A zero delay would cause the frequency generator to pause.

    A non-zero delay is shifted right one bit to divide by two. I figure I shouldn't need to worry about a single bit rounding error.

    The delay value would be changed by the higher level code.

    Is this close to the type of frequency generator you were talking about whicker?
Sign In or Register to comment.