Shop OBEX P1 Docs P2 Docs Learn Events
HB-25 motor controllers — Parallax Forums

HB-25 motor controllers

kwanzimelonhidekwanzimelonhide Posts: 20
edited 2009-01-01 05:55 in General Discussion
This sample code provided for the HB-25 is written for two HB-25s connected together.· I can see the commenting about which code lines are for motor 1 or motor 2 but I am confused about how the code distinguishes between Motor 1 and Motor 2 because they are on the same I/O pin. Also, I don't see why the code has to be written the way it is. Why can't I·use the·code for a normal servo: FOR counter = 1 TO 150
····························································· ·PULSOUT HB25, 1000
······························································ PAUSE 20
·······························································NEXT
I suppose the code for "waiting for the HB-25 to power up" is just always necessary, but I don't understand why "index" must be added to the duration when the motor goes forward...what I'm trying to do is pretty simple: have one motor turn around 180 degrees, stop, then the other motor turns 180 degrees (in a loop).

SAMPLE CODE:
'
[noparse][[/noparse] I/O Definitions ]
HB25 PIN 15 ' I/O Pin For HB-25
'
[noparse][[/noparse] Variables ]
index VAR Word ' Counter For Ramping
'
[noparse][[/noparse] Initialization ]
DO : LOOP UNTIL HB25 = 1 ' Wait For HB-25 Power Up
LOW HB25 ' Make I/O Pin Output/Low
PAUSE 5 ' Wait For HB-25 To Initialize
PULSOUT HB25, 750 ' Stop Motor 1
PAUSE 1 ' 1 mS Delay
PULSOUT HB25, 750 ' Stop Motor 2 (If Connected)
' The Above 2 Lines May Be Removed
' If You Are Using Single Mode
'
[noparse][[/noparse] Program Code ]
Main:
PAUSE 20 ' Wait 20 mS Before Ramping
FOR index = 0 TO 250 ' Ramp Up To Full Speed
PULSOUT HB25, 750 + index ' Motor 1 Forward
PAUSE 1 ' 1 mS Delay For Motor 2 Pulse
PULSOUT HB25, 750 - index ' Motor 2 Reverse
PAUSE 20 ' 20 mS Smoothing Delay
NEXT
PAUSE 3000 ' Wait 3 Seconds
FOR index = 250 TO 0 ' Ramp Back Down
PULSOUT HB25, 750 + index ' Motor 1 Forward Slowing
PAUSE 1 ' 1 mS Delay For Motor 2
PULSOUT HB25, 750 - index ' Motor 2 Reverse Slowing
PAUSE 20 ' 20 mS Smoothing Delay
NEXT

STOP ' Use STOP To Prevent State Change

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2008-12-30 01:16
    Take A look at the v1.2 (pdf) Doc. on the Main parallax Website under product Info.

    The HB-25 will work with simple servo commands the thing to remember is the HB-25 only needs one "PULSOUT" to set speed and direction.
    It doesn't need to be refreshed over and over like a regular servo,If speed and direction don't need to change.

    If You are running a single motor then every "PULSOUT" command will update the single motor.

    If Your using two motors the the first "PULSOUT" will update the 1st motor and the 2nd "PULSOUT" will update the 2nd motor.
    Now if You wanted to keep motor #1 at the same speed and direction but change #2 motors speed. You'll just need to refresh motor #1
    with "PULSOUT,same values", "PULSOUT,new speed values" for #2 motor.

    Don't forget the PAUSE times between PULSOUT commands and that single/dual motor modes are by jumper select on the HB-25

    The doc's in the pdf. will explain this a little better.

    ____________$WMc%_____________Happy New Year

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there
  • kwanzimelonhidekwanzimelonhide Posts: 20
    edited 2008-12-30 01:37
    thanks...I'm still confused though about why you have to ramp the motors with "Pulsout Pin, Duration+index" instead of "Pulsout Pin, Duration"
    this code doesn't work:
    FOR index = 0 TO 250
    PULSOUT HB25,500 'move motor 1
    NEXT
    PAUSE 3000
    FOR index = 0 TO 250
    PULSOUT HB25,500 'move motor 2
    NEXT

    could someone give me a code example of having one motor turn an arbitrary distance,stopping, then having the other motor turn (alternating like this in a loop)
    thank you...
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2008-12-30 05:02
    kwanzimelonhide,
    As it has been pointed out, take a look at the manual linked below at pages 2 and·3.· This should explain how to control one motor over the other.
    http://www.parallax.com/Portals/0/Downloads/docs/prod/motors/HB-25MotorController-V1.2.pdf
    ·
    In your FOR/NEXT loops there needs to be a minimum delay of 5.25ms if using one motor, and a minimum delay of 1.1ms followed by a minimum delay of 5.25ms if using two motors.
    ·



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • kwanzimelonhidekwanzimelonhide Posts: 20
    edited 2008-12-30 06:13
    I'm still having trouble getting the code to work as I want it to. I want motor 1 to turn 180 degrees, stop, then motor 2 to turn 180 degrees, stop, and I want these actions to repeat in a loop. Here is my code. I commented where I want the motors to stop because I don't know how to write this code. and I guess the 180 degree turn code would be by trial and error...

    HB25 PIN 12
    index VAR Word
    DO: LOOP UNTIL HB25 = 1
    LOW HB25
    PAUSE 5
    PULSOUT HB25,750
    PAUSE 1
    PULSOUT HB25,750

    Main:

    PAUSE 20
    FOR index = 0 TO 250
    PULSOUT HB25,800
    NEXT
    'now I want the first motor to stop
    PAUSE 1
    FOR index = 0 TO 250
    PULSOUT HB25,800
    NEXT
    'now I want this second motor to stop
    PAUSE 5
    GOTO Main
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2008-12-30 20:34
    kwanzimelonhide,

    The way your code is, you are not waiting long enough between pulses for the HB25 to distinguish which pulse is which. See if the code below might make some more sense...


    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    Delay CON 125
    
    HB25 PIN 12
    
    M1 VAR Word
    M2 VAR Word
    Duration VAR Word
    
    LOW HB25                      'Initialize PIN low
    
    Main:
    
    FOR Duration = 0 TO Delay
        M1 = 900                  'Start Motor 1 in one direction
        M2 = 750                  'Stop Motor 2
        GOSUB MotorControl
        PAUSE 12
    NEXT
    
    FOR Duration = 0 TO Delay
        M1 = 750                  'Stop Motor 1
        M2 = 780                  'Start Motor 2 in one direction
        GOSUB MotorControl
        PAUSE 12
    NEXT
    
    FOR Duration = 0 TO Delay
        M1 = 600                  'Start Motor 1 in opposite direction
        M2 = 750                  'Stop Motor 2
        GOSUB MotorControl
        PAUSE 12
    NEXT
    
    FOR Duration = 0 TO Delay
        M1 = 750                  'Stop Motor 1
        M2 = 720                  'Start Motor 2 in opposite direction
        GOSUB MotorControl
        PAUSE 12
    NEXT
    
    GOTO Main
    
    
    
    MotorControl:
    PULSOUT HB25,M1
    PAUSE 2
    PULSOUT HB25,M2
    PAUSE 6
    RETURN
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • kwanzimelonhidekwanzimelonhide Posts: 20
    edited 2008-12-31 01:09
    Thank you, this makes a lot more sense. One last problem: the movement of each motor is very pulsed and it turns in short bursts, and the power light on each HB-25 pulses brighter/dimmer too...
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2008-12-31 02:42
    kwanzimelonhide,

    What kind of power supply are you using for the HB25's ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 12/31/2008 7:56:26 AM GMT
  • kwanzimelonhidekwanzimelonhide Posts: 20
    edited 2008-12-31 05:27
    a 12 V Power Supply.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2008-12-31 07:58
    kwanzimelonhide,

    What other ratings are on the supply? i.e. Current
    Also, what is the rating of your motors that you are using? If the power supply is inadequate with relation to your motors, then you could see dimming of the green power LED on the HB25's.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • kwanzimelonhidekwanzimelonhide Posts: 20
    edited 2008-12-31 18:53
    i'm using the parallax motor mount kit, which is 12 V, 1.5 A, no load. I hadn't realized that my power supply only outputs 1 A, so it makes sense why it wasn't working well...
    also I was wondering what is the best way to make the motors move slower?
    thank you.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-01-01 00:02
    kwanzimelonhide,

    The demo code that I provide should make Motor1 turn faster than Motor2.... You can control the motor speed by adjusting the pulse width. The further away from center (a 1.5ms pulse) the faster the motor will spin. Above 1.5ms the motor will spin in one direction, and below 1.5ms the motor will spin in the other direction.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • kwanzimelonhidekwanzimelonhide Posts: 20
    edited 2009-01-01 05:55
    thank you very much for your help!
Sign In or Register to comment.