Shop OBEX P1 Docs P2 Docs Learn Events
turn on and off 21 LEDs using BStamp2 P40 — Parallax Forums

turn on and off 21 LEDs using BStamp2 P40

MarkusMarkus Posts: 22
edited 2006-02-11 16:02 in BASIC Stamp
Hi,

I can't turn on 21 LEDs using this rutine.
Do you know why ? Any easy rutine instead this one?

' {$STAMP BS2p}
' {$PBASIC 2.5}

ini:

FOR W2 = 0 TO 21
HIGH W2
PAUSE 100
LOW W2
PAUSE 100
NEXT

GOTO ini


Thanks, Mark
confused.gifconfused.gifconfused.gif

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-02-07 21:49
    You may only address 16 pins at a time (0-15 or 16-31), using the statement MAINIO to use the first bank and AUXIO to address the second. Refer to the stamp manual for the use of the two commands.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-08 01:27
    Here's a subroutine to "virtualize" your pins so that you can set any one of them (0 - 31) to 0 (low) or 1 (high).

    Setup_Pin:
    · IOTERM thePin / 16················· · ' point to correct pin bank
    · thePin = thePin // 16·············· · ' truncate 'bank' from pin
    · DIRS.LOWBIT(thePin) = 1············ · ' make the pin an output
    · OUTS.LOWBIT(thePin) =·pinLevel······· '·set the pin level
    · RETURN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-02-08 14:55
    If I'm not mistaken, if you're using 10 mA per LED, 21 LED's would be 210 mA. That's WAY more than the PIC chip inside the BS2p40 will drive.

    You should probably add 2 ULN2008 darlington chips to the circuit to handle the current for you.

    Now, if you're using "High efficiency" LED's, of 1 to 3 mA each, that's below the 50 mA limit for the PIC chip, and you'd be okay.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-08 14:58
    In the original post the LEDs were being turned on, then off before the next one was turned on.· Following this concept he should be fine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-02-08 15:09
    Fair enough. I assumed the original post code was test code, and that there was some reason for having 21 LED's that he MIGHT want them all on at the same time at some point.

    If not, then you're right, it's not a problem.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-02-08 16:04
    Only the BS1 and BS2 use PIC chips.

    That one is an SX-Ubicom, soon to be an SX-Parallax chip. It actually may handle a bit more power. [noparse][[/noparse]read the specifications]

    Alternatively, he can use three shift registers and get 24 leds lit from one data pin, one clock pin, and one latch pin. There are even 'high power output shift registers' that can eliminate the UNL2308.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-08 17:10
    Allan,

    · He may not know that, so your post is justified in simply making him aware of this potential problem.· I was just going by the original code posted.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • MarkusMarkus Posts: 22
    edited 2006-02-08 21:07
    Thanks,


    I was testing the BSP40 with LEDs
    Then it seems that Basic Stamp P40 couldn't turn on and off
    more than 16 LEDs at the same time.
    ( Regarding Paul Baker reply )

    Thanks for all the support. Mark
    smilewinkgrin.gif
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-09 16:21
    Small scale microcontrollers an only sink/source so much current -- this is not a function of the BASIC Stamp, but the PIC or SX micro at its core. Similar 8-bit microcontrollers have similar limitations, and if you need to run a bunch of LEDs you have to control the current. You can either use very low current LEDs (usually not very bright) or put a buffer in between the microcontroller and the standard LED circuits you want to illuminate.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-02-09 21:30
    Or, as seems true here, if you're just creating a 'test jig' and cycling each LED one at a time, you should be OK without a buffer.
  • MarkusMarkus Posts: 22
    edited 2006-02-11 14:05
    Thanks Jon,

    The current is not my problem.

    The problem I have is to use the all the Basic Stamp P40 pins at a time,
    something like:

    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}

    High 1
    High 2
    High 3
    High 4
    High 5
    High 6
    High 7
    High 8
    High 9
    High 10
    High 11
    High 12
    High 13
    High 14
    High 15
    High 16
    High 17
    High 18
    High 19
    High 20
    High 21

    END

    Please suppose the I/O consuption is not the problem because I
    could use a very little led and the total comsumption of all pins at the
    same time is 15 mA only. I that possible?


    Thanks, Mark confused.gif
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-11 16:02
    You cannot do anything past HIGH 15 -- this is just one of the rules of PBASIC.· The subroutine I wrote earlier in this thread will let you accomplish what you want, though the syntax would look something like:

    Main:
    · FOR thePin =·1 TO 21
    ··· pinLevel = 1············ ' make pin high
    ··· GOSUB Setup_Pin··········' do it
    · NEXT

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.