Shop OBEX P1 Docs P2 Docs Learn Events
Accelerate/Decelerate PULSOUT — Parallax Forums

Accelerate/Decelerate PULSOUT

curious1curious1 Posts: 104
edited 2007-03-01 12:22 in BASIC Stamp
My project has a small stepper motor on board . I am uing 2 out pins on the BS2 for step and direction.
·I am increasing and decreasing speeds with·FOR PULSOUT NEXT. It works·really good but is there any way to accel. and decel. with the pulsout ?
·Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-01 05:23
    How are you increasing and decreasing speeds? If each pulse moves the motor a certain distance, then the frequency of the pulses sets the speed. Maybe you're using the width of the pulse, set by PULSOUT, to effectively set the frequency of the pulses. Since acceleration is the rate of change of velocity, you would accelerate by increasing how quickly you change the pulse width. In other words, instead of changing the frequency of the pulses by a fixed amount (or changing the pulse width by a fixed amount), change the amount you change it.

    If each time through the loop, you normally change the pulse width by 5%, change it by 10% for a few loops, then change it by 20% for a few loops.

    By the way, if you include your current program as an attachment, we would have a better idea of what you're trying to do and possibly make specific suggestions rather than generalities.
  • curious1curious1 Posts: 104
    edited 2007-03-01 06:13
    It's at my shop, I'll send it tomorrow. This is basically what I'm doing:
    counter var word
    DO
    LOOP UNTIL IN1=1 ' to start
    FOR counter = 1 TO 50 ' 1/4 turn ( 200 ppr )
    PULSOUT 4, 5
    PAUSE 25 ' pretty slow to start , I use the pause low to change speed
    NEXT
    FOR counter = 1 TO 250 '1-1/4 turns fast
    PULSOUT 4, 2 ' I have to keep pulse high at least 4 micro sec. for the driver
    PAUSE 0 'I leave the pause out for full speed
    NEXT
    and so on.....
    Then do the same thing to reduce speed by 2 or 3 increments down to creeping speed to a HOME switch that resets for the next cycle.
    At the end, I think it goes like this:

    DO
    PULSOUT 4, 5
    Pause 40 "slow creep to home
    LOOP UNTIL IN5=1 ' 5 is HOME switch input
    LOW 3 ' for direction reversal
    LOOP
    It coutinues to run until it makes IN5, then stops

    It works but I wondered if the stamp could give it an "S Curve" profile or even a "RAMP" like some of the stepper controllers do.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-01 06:36
    It looks like you have 3 variables for each speed step: The FOR loop count, the PULSOUT width, and the PAUSE delay. You could set up a table using DATA statements, then have two nested loops like (with your example):
    table data 50,5,25 ' 1/4 turn slow
            data 250,2,0 ' 1/4 turn fast
    for i = 0 to 1
      read table+i*3,s ' steps
      read table+i*3+1,w ' width
      read table+i*3+2,p ' PAUSE
      for c = 1 to s
        pulsout 4,w
        pause p
      next c
    next i
    
    
  • curious1curious1 Posts: 104
    edited 2007-03-01 12:22
    I'll try that. I see it in the book now too.
    Thanks Mike,
    I could leave·each pulsout high for the same time for all speeds, just change count and pause.
    Then only 2 var to deal with.
    Thanks again.

    Post Edited (curious1) : 3/1/2007 12:29:11 PM GMT
Sign In or Register to comment.