Shop OBEX P1 Docs P2 Docs Learn Events
stepper motor programming help — Parallax Forums

stepper motor programming help

RPrattRPratt Posts: 19
edited 2009-02-16 22:59 in BASIC Stamp
Hey Guys -

I have been working with the Stamp Works kit, and I am trying a modification on experiment 27 in the guide (stepper motor control). I am already starting to gear towards halloween gags ( I enjoy messing with the neighborhood kids lol) and I am looking to use the PIR's from Parallax along with some stepper motors to cause some skulls to turn towards who ever walks up to the table. should only be a 45 degree turn each time the PIR is tripped, then move back to the home position when the PIR goes to rest. but I am just not getting anywhere fast! I·am starting with just using a NO button·to step the motor using the sample code in the book (its written to use a POT to control direction and speed. I have one button set for each direction), but I can only get it to do one step each time the·button is pressed. I have tried with modifing the step scale in the EEPROM data, and changing the modifer for the step control variable in the sub routine, but it still only gives me the same result. I am sure I am missing something in the math, but what? the source code from the guide is attached. thanks.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-02-16 19:54
    Could you attach the code you are actually using.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • RPrattRPratt Posts: 19
    edited 2009-02-16 20:00
    so far I have just mod'd this code, with renaming the POT controls over to the buttons to keep track of everything. the button will allow it to move one step (or half step if I change the lookup table), but they wont go past this. I would assume that if the button trigger will cause one step, I should be able to modify the variable to allow for the extra steps I want rather than relying on multiple presses of the button. just cant seem to put a finger on where I am missing that at?
  • RPrattRPratt Posts: 19
    edited 2009-02-16 22:54
    ok so after breaking out the pad an pencil, and doing a lot of math over and over, I came to realize that no matter what I was not going to get past one step per button press using the code I attached above. so when all else failed, I went back to basics, and tore it apart one step at a time. and low and behold, I realized that by simply going with:

    Main:
    DO
    IF Button1 = 0 THEN
    GOSUB HeadLeft
    ELSEIF button2 = 0 THEN
    GOSUB HeadRight
    ENDIF
    LOOP

    HeadLeft:
    FOR idx = 1 TO RevSteps ' 1 rev forward
    GOSUB Step_Fwd
    NEXT
    PAUSE 2000

    FOR idx = 1 TO RevSteps ' 1 rev back
    GOSUB Step_Rev
    NEXT
    PAUSE 2000
    RETURN


    HeadRight:
    FOR idx = 1 TO RevSteps
    GOSUB Step_Rev
    NEXT
    PAUSE 2000

    FOR idx = 1 TO RevSteps
    GOSUB Step_Fwd
    NEXT
    PAUSE 2000
    RETURN

    I could maintain the same sub-routines as the example program and get the response I was looking for. and by modifying the variable for the motor, and the delay time, I can get the exact amount of steps I want along with the creepy "exorcist" style head crank.

    Franklin - thanks again for the help!
  • FranklinFranklin Posts: 4,747
    edited 2009-02-16 22:59
    I'm glad you figured it out. Next time it will be easier as you learn to think these problems through. Good luck with your stamp. check out efx-tek.com and www.scary-terry.com

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
Sign In or Register to comment.