hb25 precision
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!
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!
Comments
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!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The smarter I get, the more I understand I don't know!
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
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!
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
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!
i'll call this one operator error.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The smarter I get, the more I understand I don't know!