Shop OBEX P1 Docs P2 Docs Learn Events
trouble with hb25 commands — Parallax Forums

trouble with hb25 commands

joy1joy1 Posts: 32
edited 2013-10-14 09:19 in BASIC Stamp
Hello,

I have hooked up one hb25 to a vacuum pump and another to a linear actuator. I'm having trouble with the code to get them to work properly

I will paste below...the issues I'm having are commented on in the code.

Any assistance would be greatly appreciated.

thanks


' =========================================================================
' File...... HB-25 Motor Test.bs2
' Purpose... Tests One Or Two HB-25's Connected To P15
' Author.... Parallax, Inc.
' E-mail.... support@parallax.com
' Updated... 01-18-2006
'
' {$STAMP BS2}
' {$PBASIC 2.5}

'
[ Program Description ]

' This program tests the HB-25 by waiting for it to power up, then pulsing
' the output to ramp the motors up in opposite directions, wait 3 seconds
' then ramp them back down to a stopped position. While the code is
' written for two HB-25/motors you can use it with just one by commenting
' out or removing the lines for the second motor, commented below. If you
' have two HB-25/motors connected, remember to remove the jumper block from
' the second HB-25.


'
[ I/O Definitions ]

pump PIN 15 ' I/O Pin For pump
linear PIN 1 'I/O Pin for linear actuator


'
[ Variables ]

index VAR Word ' Counter For Ramping
'two VAR Word

'
[ Initialization ]

DO : LOOP UNTIL pump = 1 ' Wait For HB-25 Power Up
LOW pump ' Make I/O Pin Output/Low
PAUSE 5 ' Wait For HB-25 To Initialize
PULSOUT pump, 750 ' Stop Motor 1
PAUSE 1 ' 1 mS Delay
PULSOUT linear, 750 ' Stop Motor 2 (If Connected)
' The Above 2 Lines May Be Removed
' If You Are Using Single Mode
'
[ Program Code ]

Main:

FOR index = 0 TO 100 'moves linear actuator forward
PULSOUT linear, 500 'linear actuator is extended.
PAUSE 20
NEXT
PAUSE 1000

FOR index = 0 TO 1 'Start pump **no matter what number I put for
PULSOUT pump, 1000 'duration, in this case 0 to 1, the
PAUSE 20 'outcome is the same where the pump stays on
NEXT 'until after the actuator is brought in.
PAUSE 1000 'I want to be able to control the vacuum pump so that
'what it picks up will be released when i want it to

FOR index = 0 TO 100 'bring actuator back to beginning position
PULSOUT linear, 1000
PAUSE 20
NEXT
PAUSE 1000


END

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2013-10-08 08:04
    Your code seems to work as expected, at least when looking at the signals on a scope. One thing though is that the "FOR index = 0 TO 1" may not be long enough and the pulse could be missed from the HB25.

    Also, since the "pump" I/O is used for an input waiting for the HB25 to initialize as a logic HIGH, and then immediately your making it a logic LOW, you might want to place a current limiting resistor on the I/O pin (15 in your case) in case the HB25 and the BS2 I/O do not agree.
  • joy1joy1 Posts: 32
    edited 2013-10-08 12:42
    Your code seems to work as expected, at least when looking at the signals on a scope. One thing though is that the "FOR index = 0 TO 1" may not be long enough and the pulse could be missed from the HB25.

    Also, since the "pump" I/O is used for an input waiting for the HB25 to initialize as a logic HIGH, and then immediately your making it a logic LOW, you might want to place a current limiting resistor on the I/O pin (15 in your case) in case the HB25 and the BS2 I/O do not agree.

    I've tried with anything from 1 to 100 or more in the "For index = 0 to 1"....the time the motor runs is always around 4 seconds

    I will need some more time to go through the rest of your suggestions

    thanks
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-10-09 18:19
    My bad. I just reread your post and see you do have 2 motors.

    EDIT: Have you tried them individually with any luck? Since the actuator portion works maybe comment it out to see what happens on with the pump.
  • joy1joy1 Posts: 32
    edited 2013-10-10 10:18
    I have tried them individually and I'm not satisfied with the result...the linear actuator works just fine...I can control the movement easy enough

    The vacuum pump though, this just doesn't want to work properly...it shouldn't stay on long with a duration of 0 to1 but it does...any ideas?
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-10-10 11:46
    Have you tried the resistor as Beau mentioned?
  • joy1joy1 Posts: 32
    edited 2013-10-10 12:37
    NWCCTV wrote: »
    Have you tried the resistor as Beau mentioned?

    yes i have...still did not change anything
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2013-10-10 13:35
    Just for kicks, does the operation change at all if you replace END with STOP instead? .... The thinking here is that PULSOUT pump, 1000 does turn the pump on and using END, the STAMP goes into a sleep mode that pulses every 2.3 seconds. That brief period of wakup could be whats turning the pumps OFF after the actuator is brought in. By replacing the END with STOP, instead, the STAMP actually stops and does not sleep. Keep in mind this is purely a debugging exercise.

    From what I can see of your code this is what is happening:
    1) wait for the HB-25 to turn on
    2) make sure BOTH motors are OFF
    3) move the actuator OUT
    4) start pump
    5) move actuator back in
    6) End of program

    Note: from what I gather, the idea is to keep the pump ON after the program stops? ... but with the current program, the pump shuts off at the end?


    Note: taken from the BASIC Stamp Help for the "END" function
    Just as with the SLEEP command, pins will retain their input or output settings after the BASIC Stamp is deactivated by END. For example, if the BASIC Stamp is powering an LED when END executes, the LED will stay lit after END, but every 2.3 seconds, there will be a visible wink of the LED as the output pin switches to the input direction for 18 ms.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-10-10 15:47
    NWCCTV wrote: »
    Have you tried the resistor as Beau mentioned?

    If the I/O pin is for the HB-25 the resistor is not needed. The HB-25 has an internal pull-up and the code is waiting for that line to go high so it knows when the HB-25 has been powered on and needs to be initialized. Making the line low won't hurt anything since the HB-25 has an input only. In fact, putting a resistor in series may cause the HB-25 not to work since it may never see a low on the input.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-10-10 15:52
    Unless I misread the code, I think I see your problem. In the future please use code tags around your code or just attach the code so it's easier to follow.
    [COLOR=#333333]Main:[/COLOR]
    
    [COLOR=#333333]FOR index = 0 TO 100 'moves linear actuator forward[/COLOR]
    [COLOR=#333333]PULSOUT linear, 500 'linear actuator is extended.[/COLOR]
    [COLOR=#333333]PAUSE 20[/COLOR]
    [COLOR=#333333]NEXT[/COLOR]
    [COLOR=#333333]PAUSE 1000[/COLOR]
    
    [COLOR=#333333]FOR index = 0 TO 1 'Start pump **no matter what number I put for[/COLOR]
    [COLOR=#333333]PULSOUT pump, 1000 'duration, in this case 0 to 1, the[/COLOR]
    [COLOR=#333333]PAUSE 20 'outcome is the same where the pump stays on[/COLOR]
    [COLOR=#333333]NEXT 'until after the actuator is brought in.[/COLOR]
    [COLOR=#333333]PAUSE 1000 'I want to be able to control the vacuum pump so that[/COLOR]
    [COLOR=#333333]'what it picks up will be released when i want it to[/COLOR]
    
    [COLOR=#333333]FOR index = 0 TO 100 'bring actuator back to beginning position[/COLOR]
    [COLOR=#333333]PULSOUT linear, 1000[/COLOR]
    [COLOR=#333333]PAUSE 20[/COLOR]
    [COLOR=#333333]NEXT[/COLOR]
    [COLOR=#333333]PAUSE 1000[/COLOR]
    
    
    [COLOR=#333333]END[/COLOR]
    

    It looks to me like you're sending a pulse value of 1000 to start the motor and then expecting the motor to stop because you sent one pulse. But it doesn't work that way. You must send a 750 pulse to it so that the motor stops. Please let me know if this helps.

    Also, ending the program can cause pulses on the I/O pins which may retrigger your HB-25. Try ending the code with a STOP or keep it in a loop.
  • joy1joy1 Posts: 32
    edited 2013-10-11 08:48
    Thanks guys...I'll give your suggestions a try and let you know the results
  • joy1joy1 Posts: 32
    edited 2013-10-11 11:03
    Thanks again for your help.

    I kinda started from the beginning and tried to make sense of everything from your suggestions; i don't know if my end code is exactly what you were telling me but, it works nicely now. I will post my code and if there is something you see that can make it better then let me know.

    thanks again.

    ' ================================================== =======================
    'Mr. C testing hb25 with pump and actuator
    '
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    '
    [ Program Description ]

    ' This program works with two hb25 controllers...one for a pump...one for a linear
    'actuator. The actuator moves out, pump starts, then actuator moves back with object
    'in suction cup.


    '
    [ I/O Definitions ]

    pump PIN 15 ' I/O Pin For pump
    linear PIN 1 'I/O Pin for linear actuator


    '
    [ Variables ]

    index VAR Word ' Counter For Ramping
    'two VAR Word

    '
    [ Initialization ]

    DO : LOOP UNTIL pump = 1 ' Wait For HB-25 Power Up
    LOW pump ' Make I/O Pin Output/Low
    PAUSE 5 ' Wait For HB-25 To Initialize
    PULSOUT pump, 750 ' Stop Motor 1
    PAUSE 1 ' 1 mS Delay
    PULSOUT linear, 750 ' Stop Motor 2 (If Connected)

    '
    [ Program Code ]

    Main:
    DO
    IF (IN4 = 1) THEN
    GOSUB move
    ELSE
    PULSOUT linear, 750
    PULSOUT pump, 750
    PAUSE 20
    ENDIF
    LOOP

    move:
    FOR index = 0 TO 100 'moves linear actuator forward
    PULSOUT linear, 500 'linear actuator is extended.
    PAUSE 20
    NEXT
    PAUSE 1000


    PULSOUT pump, 1000 'Start pump
    PAUSE 20

    PAUSE 1000

    FOR index = 0 TO 100 'bring actuator back to beginning position
    PULSOUT linear, 1000
    PAUSE 20
    NEXT
    PAUSE 1000

    PULSOUT pump, 750 'Stop pump
    PAUSE 20

    PAUSE 1000
    RETURN
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-10-14 09:19
    You should use code tags to post code since the formatting is all lost when you just paste it into the message body.

    As for what I suggested, yes, you now have the start and stop pulse values so the motor can stop and your code doesn't end so there are no glitches to cause the motor to become erratic.
Sign In or Register to comment.