xtreme serial control code for servo?
' {$STAMP BS2}
' {$PBASIC 2.5}
' Using the BSII with X-Treme Serial Control
' Visual Basic Software to Control 4 Relays.
relay· VAR B3··· 'relay number storage variable
stat·· VAR B4··· 'relay status ON/OFF variable
baud·· CON 16468 '9600,N,8,1
serpin CON 0···· 'serial I/O pin = 0
DO
· SERIN serpin,baud,[noparse][[/noparse]WAIT(254),relay,stat] 'serial data in on pin0
· IF relay = 1 THEN outr1 ' if request is for relay#1 then goto relay#1 routine
LOOP
outr1:
· IF stat = 1 THEN
·DO
·PULSOUT 15, 500
·LOOP
ENDIF
· IF stat = 0 THEN
· DEBUG " pin low"
ENDIF
RETURN
Can anyone explain to me how to keep my servo on in this code while outr1 status is 1 and turn it off when the status is 0?? ( I am hacking a serial control relay project to control servos for a robot)
Thanks for any help.
' {$PBASIC 2.5}
' Using the BSII with X-Treme Serial Control
' Visual Basic Software to Control 4 Relays.
relay· VAR B3··· 'relay number storage variable
stat·· VAR B4··· 'relay status ON/OFF variable
baud·· CON 16468 '9600,N,8,1
serpin CON 0···· 'serial I/O pin = 0
DO
· SERIN serpin,baud,[noparse][[/noparse]WAIT(254),relay,stat] 'serial data in on pin0
· IF relay = 1 THEN outr1 ' if request is for relay#1 then goto relay#1 routine
LOOP
outr1:
· IF stat = 1 THEN
·DO
·PULSOUT 15, 500
·LOOP
ENDIF
· IF stat = 0 THEN
· DEBUG " pin low"
ENDIF
RETURN
Can anyone explain to me how to keep my servo on in this code while outr1 status is 1 and turn it off when the status is 0?? ( I am hacking a serial control relay project to control servos for a robot)
Thanks for any help.
Comments
You may need to use a servo control board which can provide the updating while the Stamp does other things. There are a couple on the Parallax pages.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
The answer to your question is simple, but there are MANY problems that you haven't even seen yet in this program. Just to answer your question first, here's what you need to do. Where you have:
DO
PULSOUT 15, 500
LOOP
You need to add the PAUSE in there so it looks like this:
DO
PULSOUT 15, 500
PAUSE 20
LOOP
HOWEVER, if you use DO...LOOP you need to have a conditional within the DO..LOOP, or a conditional argument in the DO part, or LOOP part, in order to exit, otherwise it will continue forever.
Moreover the RETURN at the end of that program is eventuall ygoing to cause you all sorts of grief, since there is no GOSUB anywhere in the program. GOSUB...RETURN always act in pairs.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
http://www.parallax.com/detail.asp?product_id=28023
Why waste code an clock cycles on spinning motors. Save your code space for the important stuff.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
'{$STAMP BS2}
'{$PBASIC 2.5}
' Using the BSII with X-Treme Serial Control
' Visual Basic Software to Control 4 Relays.
relay· VAR B3··· 'relay number storage variable
stat·· VAR B4··· 'relay status ON/OFF variable
baud·· CON 16468 '9600,N,8,1
serpin CON 0···· 'serial I/O pin = 0
key:
· SERIN serpin,baud,[noparse][[/noparse]WAIT(254),relay,stat] 'serial data in on pin0
· IF relay = 1 THEN outr1
· IF relay = 2 THEN outr2
· IF relay = 3 THEN outr3
· IF relay = 4 THEN outr4
outr1:
·DEBUG ?IN5
· IF stat = 1 THEN GOTO work ' If status request is I/O pin#1 logic 1 [noparse][[/noparse]high]
· LOW 1: GOTO key······ ' then make I/O pin#1 high, else make it [noparse][[/noparse]low]
high1:
HIGH 1: GOTO key
outr2:
DEBUG ? IN5
· IF stat = 1 THEN high2
· LOW 2: GOTO key
high2:
DEBUG ? IN5
· HIGH 2: GOTO key
outr3:
· IF stat = 1 THEN high3
· LOW 3: GOTO key
high3:
· HIGH 3: GOTO key
outr4:
· IF stat = 1 THEN high4
· LOW 4: GOTO key
high4:
· HIGH 4: GOTO key
work:
IF (IN5 = 0) THEN
DO
PULSOUT 15,500
PAUSE 20
IF (IN5)=1 THEN
GOTO key
·ENDIF
LOOP UNTIL IN5=1
ENDIF
It is sort of working but I cant get it to interupt when the servo is pulsing to check the condition of IN5 so that when in5 is changed to 1 the servo stops.
'{$STAMP BS2}
'{$PBASIC 2.5}
' Using the BSII with X-Treme Serial Control
' Visual Basic Software to Control 4 Relays.
relay· VAR B3··· 'relay number storage variable
stat·· VAR B4··· 'relay status ON/OFF variable
baud·· CON 16468 '9600,N,8,1
serpin CON 0···· 'serial I/O pin = 0
key:
· SERIN serpin,baud,[noparse][[/noparse]WAIT(254),relay,stat] 'serial data in on pin0
· IF relay = 1 THEN outr1
· IF relay = 2 THEN outr2
· IF relay = 3 THEN outr3
· IF relay = 4 THEN outr4
'ON relay GOSUB... may work better here - easier to follow.·
outr1:
·DEBUG ?IN5
· IF stat = 1 THEN GOTO work ' If status request is I/O pin#1 logic 1 [noparse][[/noparse]high]
· LOW 1: GOTO key······ ' then make I/O pin#1 high, else make it [noparse][[/noparse]low]
'Code doesn't do what comment says - when does it make pin 1 high? goto prohibits it.
high1: 'This label is completely unreachable in the code
HIGH 1: GOTO key
outr2:
'This works - maybe substituting an IF THEN ELSE statement can help you with program flow.
DEBUG ? IN5
· IF stat = 1 THEN high2
· LOW 2: GOTO key
high2:
DEBUG ? IN5
· HIGH 2: GOTO key
outr3:
'This works - maybe substituting an IF THEN ELSE statement can help you with program flow.
· IF stat = 1 THEN high3
· LOW 3: GOTO key
high3:
· HIGH 3: GOTO key
outr4:
'This works - maybe substituting an IF THEN ELSE statement can help you with program flow.
· IF stat = 1 THEN high4
· LOW 4: GOTO key
high4:
· HIGH 4: GOTO key
work:
' a DO WHILE (IN5 = 0)...· may work better for flow control, clarity and memory usage
IF (IN5 = 0) THEN
DO
PULSOUT 15,500
PAUSE 20
IF (IN5)=1 THEN
GOTO key
·ENDIF
LOOP UNTIL IN5=1
ENDIF
'program terminates here was that your intention? try adding an·END to save battery.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR