HB-25 motor controllers
kwanzimelonhide
Posts: 20
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
····························································· ·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
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
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...
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.
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
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...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
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
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.
also I was wondering what is the best way to make the motors move slower?
thank you.
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.