Shop OBEX P1 Docs P2 Docs Learn Events
I cannot keep my program from looping — Parallax Forums

I cannot keep my program from looping

Armored CarsArmored Cars Posts: 172
edited 2004-11-15 21:24 in BASIC Stamp
This program will NOT go to grate when I want it and will continuously loop no matter what I try;

'{$STAMP BS2}
'{$PBASIC 2.5}
littlecount VAR Byte
bigcount VAR Byte
drive VAR Word
drove VAR Word
MAIN:
drive=750
FOR bigcount=1 TO·5········ 'works when set to 2 or 3
· FOR littlecount=1 TO 50
··· PULSOUT 1, drive
··· PULSOUT 0, 750
··· PAUSE 20
· NEXT
· FOR littlecount=1 TO 25
··· PULSOUT 1, drive
··· PULSOUT 0, 500
··· PAUSE 20
· NEXT
· FOR littlecount=1 TO 25
··· PULSOUT 1, drive
··· PULSOUT 0, 1000
··· PAUSE 20
· NEXT
· drove=drive
· drive=drove-25
NEXT
GOTO GRATE
GRATE:
PULSOUT 1, 750
PULSOUT 0, 750
PAUSE 20
GOTO GRATE
END


I have tried everything I can think of, but the thing that throws me off the most is that when bigcount is set to go to 2 or 3, it works.· It always infinitely loops when it is set to 4 or 5.

Comments

  • Armored CarsArmored Cars Posts: 172
    edited 2004-11-11 20:00
    What I mean by infinately loops is it never goes to GRATE, I know GRATE is supposed to loop, but when set to 4 or 5 it never gets there and just goes to the top of the program and starts over again.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2004-11-11 21:26
    dog8spam -

    My best guess is that the Stamp is inadvertantly being reset, possibly due to the servo hitting against the mechanical stop, presuming these are not continuous rotation servos.

    Just before MAIN: place the following line of code:
    DEBUG "Starting" : DEBUG bigcount?, " ", littlecount?

    If "Starting" only appears once, then you may need to place additional instances of the display DEBUG bigcount?, " ", littlecount? at various points in your program, to find when the problem is actually beginning to occur. If "Starting" appears more than once, you know the Stamp is being reset, and proceed from there with your debugging.

    Regards,

    Bruce Bates
  • JurgenJurgen Posts: 8
    edited 2004-11-11 21:35
    I can't seem to find anything wrong either, I also think the stamp is resetting.

    In the guide 'Robotics with the BOE-BOT' which can be downloaded from the Parallax site there is a simple system to detect when your stamp resets using a small buzzer.

    Maybe this can help.
  • DonivanDonivan Posts: 23
    edited 2004-11-11 21:53
    Are you using a large capacitor to give the servo a boost of power that it needs when moving? My code was erratic until I added that. A 3300uF capacitor parallel to the power input provides microcontroller brownout protection when the servos draw large amounts of power to move.
  • Armored CarsArmored Cars Posts: 172
    edited 2004-11-12 14:08
    So to keep from browning out I need to put a capacitor going from Vin to Vss?

    And does DEBUG display on the computer screen?
    If it doesnt I can just use a buzzer to find when its resetting, I just got one in the mail yesterday.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-12 15:04
    You could add

    DEBUG "Reset", CR

    at the beginning of your code (before Main). If the BASIC Stamp is resetting, you'll see it in the Debug Terminal window.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Armored CarsArmored Cars Posts: 172
    edited 2004-11-12 19:28
    Okay, I figured out with a speaker that when the ESC is set too high the stamp is reseting. When adding a capacitor does it go from Vin to Vss?
  • DonivanDonivan Posts: 23
    edited 2004-11-13 00:02
    No, the Capacitor goes between Vdd and Vss, of course be sure to observe polarity on the cap. See page 44 of "What's a Microcontroller" PDF file for more information:

    http://www.parallax.com/dl/docs/books/edu/wamv2_2.pdf

    This got me as well until I put the cap in my circuit.

    Good Luck!

    -Donivan

    Post Edited (Donivan) : 11/13/2004 1:10:37 AM GMT
  • Armored CarsArmored Cars Posts: 172
    edited 2004-11-15 20:12
    I have lots of 1000 uf capacitors, should I wire them in parralell or in a series to get the equivilent of a 3000 uf cap?
  • mikeCmikeC Posts: 4
    edited 2004-11-15 21:24
    to increase the capacitance, wire three of them in parallel.
Sign In or Register to comment.