Some help with simple codes.
haninator
Posts: 6
Hi all,
i have been trying to make a servo sweep 180 degrees twice. However, it tends to sweep out of control, many many times instead of 2. i have the follwing code. It loks very simple, but still it doesn't work?!
I would really appreciate some help.
' {$STAMP BS2sx}
DEBUG "Test Sweeping"
counter VAR Byte
counter2 VAR Byte
outercounter VAR Byte
FOR outercounter = 1 TO 2
FOR counter = 1 TO 30
PULSOUT 14, 500
PAUSE 20
NEXT
FOR counter2 = 1 TO 30
PULSOUT 14, 2850
PAUSE 20
NEXT
NEXT
that's all to my code. it sweeps many many times instead of the 2 times as specified by the outercounter. sometimes it stops abruptly, sometimes it goes on forever. Also, i noticed that "Test Sweeping" gets printed many times too shouoldn't it only print once?.
pls help. thank you guys so much!
haninator
i have been trying to make a servo sweep 180 degrees twice. However, it tends to sweep out of control, many many times instead of 2. i have the follwing code. It loks very simple, but still it doesn't work?!
I would really appreciate some help.
' {$STAMP BS2sx}
DEBUG "Test Sweeping"
counter VAR Byte
counter2 VAR Byte
outercounter VAR Byte
FOR outercounter = 1 TO 2
FOR counter = 1 TO 30
PULSOUT 14, 500
PAUSE 20
NEXT
FOR counter2 = 1 TO 30
PULSOUT 14, 2850
PAUSE 20
NEXT
NEXT
that's all to my code. it sweeps many many times instead of the 2 times as specified by the outercounter. sometimes it stops abruptly, sometimes it goes on forever. Also, i noticed that "Test Sweeping" gets printed many times too shouoldn't it only print once?.
pls help. thank you guys so much!
haninator
Comments
Also, the code as shown puts the servo in one position 30 times then puts it in the other position 30 times in a total of about 600 msec for each position. Is that really what you want?
Cheers
If you're using the word "sweep" meaning to move through a range of values quickly and smoothly, your code, as it is, isn't going to do that at all. However you have all of the elements to do so, right at your disposal.
You may have to tweak this program below a bit, to work with your specific servos, but try something like this:
' {$STAMP BS2sx}
DEBUG "Test Sweeping"
'Note If "Test Sweeping" appears more than once, the Stamp is resetting!
counter VAR Byte
counter2 VAR Byte
outercounter VAR Byte
FOR outercounter = 1 TO 2
FOR counter = 1 TO 30
PULSOUT 14, 500+(5 * counter)
PAUSE 20
NEXT
FOR counter2 = 1 TO 30
PULSOUT 14, 2850- (5 * counter)
PAUSE 20
NEXT
NEXT
END
Regards,
Bruce Bates
i recently changed the power supply to the basic stamp from a battery pack of 9V to a constant power supply of 9V through an adapter. The moment i changed it back, the code works fine!!!! Thank you guy so very much for the advice. I will·NEVER buy china made adaptors EVER again...
As for the code, yes that is very much what i want, up to 600ms per cycle.
Bruce, your tweak is·very interesting, will definately study that and see if it helps in my application.
Once again, thank you guys for your help, really appreciate it!!
Haninator