Lighting LEDs with PIC16f877a (Non-Sequential)

Discussion in 'Embedded Systems and Microcontrollers' started by lloydi12345, Dec 21, 2010.

  1. lloydi12345

    Thread Starter Member

    Aug 15, 2010
    103
    0
    Hi, I would like to ask on how to do non sequential patterns of lighting LEDs. What I mean is that for example I have 30 LEDs. They will all do running lights except that:

    1. LED1 to LED10 flashes at 100ms delay. (Set 1)
    2. LED11 to LED 20 flashes at 50ms delay. (Set 2)
    3. LED21 to LED 30 flashes at 500us delay. (Set 3)
    3. They all start together from the same time.

    After successfully doing them, I would then add different PWM on each set.

    What I only know is to light them sequentially but not non sequential. I wanted to do different speed and patterns from different parts of LEDs I'm designing. I hope you understand what I'm saying. Thank you in advance for your kind help. :)
     
    Last edited: Dec 21, 2010
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Since you have conveniently chosen times which are multiples of each other, you can add a couple of counters so you do the 500us routine 100 times, then do your 50ms changes, another 100 of the 500us routines, then both the 100ms and 50ms changes, then repeat.
     
  3. lloydi12345

    Thread Starter Member

    Aug 15, 2010
    103
    0
    I find your statement not so clear. :( Can you help me please? Just few lines for basis and then I'll generate then my own.
     
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    This is one way of doing it, there are probably plenty of others.
    Code ( (Unknown Language)):
    1. count1=100
    2. count2=200
    3. loop
    4.    do something
    5.    delay 500us
    6.    count1 = count1 -1
    7.    if count1 = 0 call every50ms
    8.    count2 = count2 -1
    9.    if count2 = 0 call every100ms
    10.    goto loop
    11.  
    12. every50ms
    13.    do something
    14.    count1=100
    15.    return
    16.  
    17. every100ms
    18.    do something
    19.    count2=200
    20.    return
    21.  
    22.  
     
  5. lloydi12345

    Thread Starter Member

    Aug 15, 2010
    103
    0
    any helping hand please? :(
     
  6. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    Exactly what help do you need?


    Does each set of LEDs all turn on at the same time or do individual LEDs wthin a set need to be controlled independently?
     
  7. lloydi12345

    Thread Starter Member

    Aug 15, 2010
    103
    0
    Yeah that's the idea! To control individual LEDs independently. Is it possible? All I know is synchronizing them.
     
  8. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    Look Google "Charlieplexing". It is fairly complicated but a way to control a number of LEDs w/o and extra chips.

    You could also use shift registers. With several hooked together you could control a bunch of LEDs w/o using too many pins of the PIC.
     
  9. lloydi12345

    Thread Starter Member

    Aug 15, 2010
    103
    0
    Wow never heard of charlieplexing in my entire life. That help me thanks.
     
Loading...