BS2 (on a BOE) gets stuck in a FOR...NEXT loop.
Wolverine69
Posts: 31
· I wrote a short piece of code that uses a FOR...NEXT loop to display the digits 0 thru 9 using a 7-segment driver and 7-segment LED display.· I'm simply using four I/O pins with HIGH & LOW commands as inputs to the 7-segment driver.· After each digit is displayed, I have a PAUSE in the code to keep the digit displayed long enough for me to read it.
· The problem is that the code never exits the FOR...NEXT loop.· I even used a DEBUG statement to monitor what the FOR...NEXT loop count is and it stays at '1', it never increments.· But the code keeps looping thru the FOR...NEXT loop and does properly sequence thru the digits 0 thru 9 on the LED display.
· I've experimented with various PAUSE durations and that seems to be the key thing that causes the never ending FOR...NEXT loop.· If I set PAUSE to 1000, I have problems.· If I comment out the PAUSE commands, it works just fine.
· Can anyone explain why it does this?
· The problem is that the code never exits the FOR...NEXT loop.· I even used a DEBUG statement to monitor what the FOR...NEXT loop count is and it stays at '1', it never increments.· But the code keeps looping thru the FOR...NEXT loop and does properly sequence thru the digits 0 thru 9 on the LED display.
· I've experimented with various PAUSE durations and that seems to be the key thing that causes the never ending FOR...NEXT loop.· If I set PAUSE to 1000, I have problems.· If I comment out the PAUSE commands, it works just fine.
· Can anyone explain why it does this?
' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG CLS ' Clear screen T VAR Byte FOR T =1 TO 10 DEBUG ? T ' 0 LOW 1 LOW 2 LOW 3 LOW 4 PAUSE 100 '1 LOW 1 LOW 2 LOW 3 HIGH 4 PAUSE 100 '2 LOW 1 LOW 2 HIGH 3 LOW 4 PAUSE 100 '3 LOW 1 LOW 2 HIGH 3 HIGH 4 PAUSE 100 '4 LOW 1 HIGH 2 LOW 3 LOW 4 PAUSE 100 '5 LOW 1 HIGH 2 LOW 3 HIGH 4 PAUSE 100 '6 LOW 1 HIGH 2 HIGH 3 LOW 4 PAUSE 100 '7 LOW 1 HIGH 2 HIGH 3 HIGH 4 PAUSE 100 '8 HIGH 1 LOW 2 LOW 3 LOW 4 PAUSE 100 '9 HIGH 1 LOW 2 LOW 3 HIGH 4 PAUSE 100 NEXT DEBUG "All Done!" END
Comments
Maybe you have a low battery?
Could you try changing all the PAUSE durations to 1000 and let me know if it still works for you?
Thanks.
Works OK, just takes a lot longer.
Are you using resistors between your output pins and the LEDs?
I'm wondering now if lighting up all seven segments (8 is displayed) of the LED display is causing the total current draw to go over a certain level and cause the problems?
ETA:· I tried running the code with the circuit disconnected from the BOE and it runs just fine.· So the problem must be caused by the circuit some how.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Paul
Post Edited (Velocit
Post Edit --·Here's the pic:
Post Edited (PJ Allen) : 4/12/2008 6:44:04 AM GMT
The resistors in question are probably already wired into the circuit inside of the RS experimentor board.
Thanks for your help. I'll install some resistors and see how it works.
Thanks for your help PJ!
DEBUG “PROGRAM RUNNING…”, CR
If this appears more than once, your BASIC Stamp is being reset.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support