Shop OBEX P1 Docs P2 Docs Learn Events
OEM-BS2 resets during second loop structure — Parallax Forums

OEM-BS2 resets during second loop structure

Senator PenguinSenator Penguin Posts: 3
edited 2008-02-28 01:18 in BASIC Stamp
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:
' {$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

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-02-27 04:35
    Senator Penguin -

    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
  • Senator PenguinSenator Penguin Posts: 3
    edited 2008-02-27 05:05
    The servos are not the usual kind of servos, but depending on the pulse width, they will rotate forwards or backwards continuously. The idea is that it will maintain its direction, while the other reverses (each is connected to a wheel, the desired behavior is that the robot to go forward for a period, then turn left.) They are defined as WORDS because the FOR loop, at one point, looped for longer than 255, but I reduced it for debugging purposes. The servos are powered off of the OEM-BS2's onboard 5V regulator, which is powered by 4x AA batteries.
    Thanks for the quick reply, I'm at wit's end unsuccessfully trying to narrow down the problem.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-02-27 05:19
    Senator Penguin -

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-27 05:22
    Usually this kind of behavior is a power problem. Servos can take quite a bit of current, particularly when they have some distance to move or when there's a large change in speed. The on-board regulator can't supply the current for long, overheats, and shuts down resetting the Stamp.

    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.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-02-27 14:44
    Well, actually, the current surge needed by the servo usually 'browns-out' (pulls down) the input voltage to the BS2. The BS2 incorporates a "brown-out" detector, and THAT is what resets the stamp. Otherwise Mike's analysis is correct.
  • Senator PenguinSenator Penguin Posts: 3
    edited 2008-02-28 01:18
    Yep, that was the problem, the MCLR pin on the PIC was being pulled to ground every time by the reset supervisor. Thanks for the help!
Sign In or Register to comment.