OEM-BS2 resets during second loop structure
We are using the OEM-BS2 rev. A2, MacBS2 v2.1b1 for programming, and a Prolific 2303-based USB-serial cable.
We have two servo motors modified for continuous rotation attached to the stamp, and it succeeds in giving basic PULSOUT commands to them. Looping those commands several times as in Good.bs2 also works fine. The problems arise when a second loop is placed after it, to change the motor direction, as in Bad.bs2. Whenever that is run, the first FOR loop executes fully, and the second one executes exactly once, and the program resets to the beginning. AlsoBad.bs2 exhibits the same strange resetting behavior, after the first execution of the second loop. Even more strangely, if the DEC5 modifiers in the DEBUG statements are changed to DEC2, the stamp resets to the beginning of the code 5 times, then runs perfectly. If it is changed to DEC1, it resets once, then runs perfectly. All of my attempts to circumvent this (DO loops, GOTO statements) have resulted in the same resetting during the second command. Has anyone else experienced this? Any ideas?
Attachment manager isn't working for me, so here are the programs, they are quite short:
Good.bs2:
Bad.bs2:
AlsoBad.bs2:
We have two servo motors modified for continuous rotation attached to the stamp, and it succeeds in giving basic PULSOUT commands to them. Looping those commands several times as in Good.bs2 also works fine. The problems arise when a second loop is placed after it, to change the motor direction, as in Bad.bs2. Whenever that is run, the first FOR loop executes fully, and the second one executes exactly once, and the program resets to the beginning. AlsoBad.bs2 exhibits the same strange resetting behavior, after the first execution of the second loop. Even more strangely, if the DEC5 modifiers in the DEBUG statements are changed to DEC2, the stamp resets to the beginning of the code 5 times, then runs perfectly. If it is changed to DEC1, it resets once, then runs perfectly. All of my attempts to circumvent this (DO loops, GOTO statements) have resulted in the same resetting during the second command. Has anyone else experienced this? Any ideas?
Attachment manager isn't working for me, so here are the programs, they are quite short:
Good.bs2:
' {$STAMP BS2} ' {$PBASIC 2.5} a VAR WORD FOR a = 1 TO 4 DEBUG "a=", DEC5 a, CR PULSOUT 2, 650 PULSOUT 9, 850 PAUSE 20 NEXT END
Bad.bs2:
' {$STAMP BS2} ' {$PBASIC 2.5} a VAR WORD b VAR WORD FOR a = 1 TO 4 DEBUG "a=", DEC5 a, CR PULSOUT 2, 650 PULSOUT 9, 850 PAUSE 20 NEXT FOR b = 1 TO 4 DEBUG "b=", DEC5 b, CR PULSOUT 2, 650 PULSOUT 9, 650 PAUSE 20 NEXT END
AlsoBad.bs2:
' {$STAMP BS2} ' {$PBASIC 2.5} a VAR WORD b VAR WORD FOR a = 1 TO 4 DEBUG "a=", DEC5 a, CR NEXT FOR b = 1 TO 4 DEBUG "b=", DEC5 b, CR PULSOUT 2, 650 PULSOUT 9, 650 PAUSE 20 NEXT END
Comments
What gives you the impression that the following code will change the motor direction?
' {$STAMP BS2}
' {$PBASIC 2.5}
a VAR WORD
b VAR WORD
FOR b = 1 TO 4
DEBUG "b=", DEC5 b, CR
PULSOUT 2, 650
PULSOUT 9, 650
PAUSE 20
NEXT
It appears to me that the servo on pin port 2 won't move at all from the prior position, and the servo on pin port 9 will move just a bit. BTW there is no reason for the variables "a" and "b" to be defined as a WORD. Defining them as a BYTE would be fine.
Additionally, how are you powering the servos?
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Genius is one percent inspiration and ninety-nine percent perspiration."
Thomas Alva Edison
Thanks for the quick reply, I'm at wit's end unsuccessfully trying to narrow down the problem.
I would suggest you use a separate power source for the servos. Just remember to tie the grounds together between the two power supplies.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Genius is one percent inspiration and ninety-nine percent perspiration."
Thomas Alva Edison
The solution is to run the servos off the 6V battery pack rather than the 5V regulator output. Sometimes you need additional filtering at the servos. Something like 470uF or even 100uF can help. The voltage rating must be at least 6V, preferably more than 6V, perhaps 10V.