Shop OBEX P1 Docs P2 Docs Learn Events
HB25 help — Parallax Forums

HB25 help

jdnphotojdnphoto Posts: 5
edited 2010-09-26 12:21 in BASIC Stamp
Hello,
This is my first time here and I have read some of the posts about controlling a dc motor with the hb25. I am trying to (like others) to control the distance a dc motor with a hb25 goes. I have a pot connected to the direction I want the dc motor to go. I can get the motor to move in both directions and the problem is that it stops too soon or goes past the distance I want. Can anyone please look at my code and tell me where I am going wrong.

' {$STAMP BS2}
' {$PBASIC 2.5}

'HB-25 Test.bs2
'Tests two HB-25 Distance 1/4inch (down and back) Height 1/2 inch up and 'down

HB25D PIN 14 'I/O Pin for HB25
Distance PIN 2 'I/O pin for distance pot

HB25H PIN 13 'I/O Pin for HB25
Height PIN 1 'I/O Pin Height pot
index VAR Word
time VAR Word 'Variable declarations
time2 VAR Word
delay CON 10
'
Initialization
DO: LOOP UNTIL HB25D = 1 'Wait for HB25 Power up
LOW HB25D 'Make I/Opin Output/Low
PAUSE 5 'Wait for HB25 to Initialize
PULSOUT HB25D, 750 'Stop Motor 1

'
Initialization HB25H
DO: LOOP UNTIL HB25H = 1 'Wait for HB25 Power up
LOW HB25H 'Make I/Opin Output/Low
PAUSE 5 'Wait for HB25 to Initialize
PULSOUT HB25H, 750 'Stop Motor 1

PAUSE 1000

'
Program Code

Main:
DEBUG "program running"
HIGH Distance 'RC decay distance measurement
PAUSE delay
RCTIME Distance, 1, time2

time2 = time2 */25
time2 = time2 + 100 'Scale pot, match HB25 range

PULSOUT HB25D, 750 + (time2 - 20) 'Backward
PAUSE 1000 '20mS Smoothing delay

HIGH Height 'RC decay height measurement
PAUSE delay
RCTIME Height, 1, time

time = time */89
time = time + 100 'Scale pot, match HB25 range

PULSOUT HB25H, 750 + (time - 5) 'UP
PAUSE 20
END

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2010-09-26 12:21
    You've got a lot of time spent in PAUSE in your loop.

    For starters, I would remove the PAUSE 1000 (that's 1 full second of nothing happening) and change the PAUSE 20 to PAUSE 10.

    Rich H
Sign In or Register to comment.