Shop OBEX P1 Docs P2 Docs Learn Events
BS2 (on a BOE) gets stuck in a FOR...NEXT loop. — Parallax Forums

BS2 (on a BOE) gets stuck in a FOR...NEXT loop.

Wolverine69Wolverine69 Posts: 31
edited 2008-04-15 19:45 in BASIC Stamp
· 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?

' {$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

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-04-12 05:05
    Works fine for me, as listed.·

    Maybe you have a low battery?
  • Wolverine69Wolverine69 Posts: 31
    edited 2008-04-12 05:37
    No battery, the BOE is plugged into the wall power supply that came with it.
  • Wolverine69Wolverine69 Posts: 31
    edited 2008-04-12 05:44
    PJ Allen,

    Could you try changing all the PAUSE durations to 1000 and let me know if it still works for you?

    Thanks.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-04-12 05:53
    Roger that, W69.

    Works OK, just takes a lot longer.

    Are you using resistors between your output pins and the LEDs?
  • Wolverine69Wolverine69 Posts: 31
    edited 2008-04-12 06:13
    I'm using a 7-segment LED driver (a CD4511BE) between the BOE and a 7-segment LED. So I don't have any resisters at all in the circuit that I've installed. The LED display is being driven by the driver chip directly. I do notice though, that when the digit '8' is first displayed, that it causes the green power LED on the BOE to kind of dim & flicker.

    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.
  • VelocitVelocit Posts: 119
    edited 2008-04-12 06:29
    Actually, that encoder/driver doesn't have any current limiting circuitry built in. You'll need to add current limiting resistors between the chip's output pins and the LED display. 330 or 470 ohm resistors (1/8W should be fine) will do the trick. Neglecting the resistors will burn the LED's out quickly. I'm not sure what kind of power supply you're using, but it's possible that the LED's are pulling much more current than is necessary, creating a voltage drop at the BS2 and causing it to hang.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Paul

    Post Edited (Velocit
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-04-12 06:35
    I'm looking at the 4511 datasheet, Fairchild's pg 6 [noparse][[/noparse]Typical Applications],·you need resistors between it and your LEDs (segments), they're clearly shown.

    Post Edit --·Here's the pic:

    4511.jpg

    Post Edited (PJ Allen) : 4/12/2008 6:44:04 AM GMT
  • Wolverine69Wolverine69 Posts: 31
    edited 2008-04-12 12:21
    I think you're right about that now that I've looked at some other things too. The 4511 that I'm using is from one of those Radio Shack Electronics kits and in the manual for it they have several schematics with the 4511 in it. They don't show any resisters in between the 4511 and the 7-segment LED, but they do show some as part of the LED internally. So that's what I went by when using the 4511 in my BS2 circuit, I assumed the resistors were part of the 7-segment LED already. I'll know better next time to find & read the data sheets even for something as simple as a 7-segment LED.

    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.
  • Wolverine69Wolverine69 Posts: 31
    edited 2008-04-14 03:54
    Ok, I installed some 470 ohm resistors in series with each of the seven segments of the LED display and everything worked just fine.

    Thanks for your help PJ!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-04-15 19:23
    What was happening is your program was starting over and over. You can verify this in the future by making the first line:

    DEBUG “PROGRAM RUNNING…”, CR

    If this appears more than once, your BASIC Stamp is being reset.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Wolverine69Wolverine69 Posts: 31
    edited 2008-04-15 19:45
    Good idea, thanks!
Sign In or Register to comment.