PDA

View Full Version : hb25 precision



Let's Go!
11-25-2009, 01:01 AM
I am using 2 hb25's to operate motors.·i want one motor to turn a turntable to a predefined position every time at the beginning of the overall routine. i am using a stop switch connected to pin 3 of the bs2, and upon closing, the switch should take the bs2 pin 3 active high and go to a routine to reset the beginning position of the turntable by ramping up and then down and stopping.

my active high switch works, the typical routines work, but i can't get this above described routine to work. i have tried many cominations of if...then, etc but i can't get it to go to the "reset" as seen below.

i have listed the appropriate code and i would appreciate any ideas.



·' {$STAMP BS2}
' {$PBASIC 2.5}
'simple test of cart and tt
'11-23-09
'i/o definitions

turntable···· PIN·· 13
cart··· PIN·· 15
'variables

index·· VAR·· Word

'initialization


DO: LOOP· UNTIL turntable = 1···· 'hb25-1
LOW turntable
PAUSE 5
PULSOUT turntable, 750

DO:· LOOP· UNTIL cart = 1······ 'hb25-2
LOW cart
PAUSE 5
PULSOUT cart, 750

PAUSE 5000
'program code

main:
'Turntable reset to beginning position

PAUSE 20
FOR index = 0 TO 50····· 'ramp up,do this routine until pin 3 goes high, 2" per move
PULSOUT turntable, 750 - index······· 'R to Left, reverse index, short moves
PAUSE 20
NEXT

PAUSE 20
FOR index = 50 TO 0········ 'ramp down, then make pin 3 decision below
PULSOUT turntable, 750 - index
PAUSE 20
NEXT

'i feel this next code needs work, or placed elsewhere

IF (IN3 = 1) THEN RESET···· 'after above routine, if pin 3 = active 1 then goto 'reset:mechanical pin is tied to 'turntable

GOTO main·············· 'goto main and move tt another 2" to position tt,if in3 = 0

RESET:·· 'this routine will place tt position in same start position every time
PAUSE 20
FOR index = 0 TO 150
PULSOUT turntable, 750 + index·· 'ramp up, L to R, FWD, move tt fwd to start position
PAUSE 20
NEXT

PAUSE 20
FOR index = 150 TO 0··· 'ramp down
PULSOUT turntable, 750 + index··· 'L TO R, fwd TO start position
PAUSE 20
NEXT·····

'turntable is now reset to it's beginning position


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The smarter I get, the more I understand I don't know!

Let's Go!
11-25-2009, 01:13 AM
sorry,

the problem is that the program is acting like it is not seeing the active high on pin 3 as it keeps looping the code above the "if..then statement.



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The smarter I get, the more I understand I don't know!

skylight
11-25-2009, 01:52 AM
you have do and loop until on the same line, loop until should come after the block of code you wish to execute in a loop

Let's Go!
11-25-2009, 02:03 AM
the do loop is the code offered by the mfr of hb25, and is published by parallax under product info. thanks anyway though

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The smarter I get, the more I understand I don't know!

skylight
11-25-2009, 02:07 AM
what i'm saying is taking one of the loops for example is that

DO: LOOP UNTIL turntable = 1 'hb25-1
LOW turntable
PAUSE 5
PULSOUT turntable, 750

should look like

DO
LOW turntable
PAUSE 5
PULSOUT turntable, 750
LOOP UNTIL turntable = 1 'hb25-1

ie DO and LOOP UNTIL should have code between them and shouldnt follow each other without.

any code after a DO command and before the LOOP comand will execute until the LOOP command has been satisfied in your case turntable = 1

Post Edited (skylight) : 11/24/2009 6:17:26 PM GMT

Let's Go!
11-25-2009, 02:18 AM
i know what you are saying and i'll try it. but the mfr has the code the way i have it written and it works so the hb25's are powering up properly. what doesn't work is the code that is trying to reset the position of the turntable farther down the lines of code. and that begins with swinging the turntable all the way one way, until the mechanical switch is activated and goes active high on pin 3. now we know just where the turntable is located and then i want to move it to a start beginning location to begin the overall routine.

the program is ignoring this and the turntable doesn't stop as it keeps moving from right to left even after triggering the switch. it should stop, and then go to the "reset" code, and therefore i will know exactly where it stop then for the beginning of the entire routine.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The smarter I get, the more I understand I don't know!

allanlane5
11-25-2009, 02:49 AM
It seems to me you should be able to use a "PULSIN" command to read the turntable position zero pulse.

You'll have to do something to insure the PULSIN does a time-out in time to refresh the servo, though.

The way you have it, it's very unlikely you'll read the position zero pin at the right time.

Edit: Well, I just checked, and PULSIN will run as long as 130 mSec if the pulse doesn't happen -- which is no good for what you want.
Probably you need a:

CheckPinFor20mSec:
· CheckCount = 0
· Input 3
· PinVal = in3
· DO WHILE CheckCount < 20
· if PinVal = 1 THEN
··· EXIT· ' Exits do loop immediately
· ELSE
··· pause 1·············· ' Pause 1 mSec
··· CheckCount = CheckCount + 1
· END IF
· LOOP
· RETURN

The above should check the pin, once every millisecond (the pulse IS longer than a millisecond, right?) and exit immediately if it sees the pin 'high'.
The 'caller' should check·"PinVal"-- if PinVal is 0, then the pin was missed so re-pulse the servo and try again.


Post Edited (allanlane5) : 11/24/2009 7:07:27 PM GMT

Let's Go!
11-25-2009, 03:02 AM
thanks for the reply. i do have the mechanical switch staying active high for the correct and extended period of time so it·should work. but i'll take a·look at the pulsin and see what i can do
with that.

i'm going to do a debug to check out the active high and low on that pin 3.

thanks

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The smarter I get, the more I understand I don't know!

Let's Go!
11-25-2009, 04:35 AM
thanks all. i moved a couple of sx wires and made a gosub statement and it works like a charm. i appreciate all the ideas and help.

i'll call this one operator error.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The smarter I get, the more I understand I don't know!