I cannot keep my program from looping
Armored Cars
Posts: 172
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.
'{$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
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
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.
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.
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
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