Project: PIC LED Sequencer

Discussion in 'The Completed Projects Collection' started by MMcLaren, Mar 17, 2012.

  1. MMcLaren

    MMcLaren Thread Starter Active Member

    Joined:
    Feb 14, 2010
    Messages:
    648
    Location:
    Michigan, USA
    For my very first project submission I'd like to present a relatively simple PIC based LED sequencer project. By "relatively simple" I mean each LED is directly driven from an I/O pin, and while this method generally uses more pins when compared to multiplexing to drive the same number of LEDs, it does make the PIC program much simpler.

    [​IMG]

    Prerequisites
    While you don't need to be a micro controller expert to build this project and create nifty LED FX (effects), you will need the (free) Microchip MPLAB IDE (integrated development environment) installed on a PC and a programmer such as the PICKIT2 to "burn" the program which contains your LED 'FX' sequences into the PIC device. You also need the basic skills and tools necessary to build the project on a solderless breadboard or a prototype board.

    Hardware
    While the project requires very few parts, you need to decide how you want to build it. I used an inexpensive phenolic prototype board available from Radio Shack (sku 276-149) with a plastic coated paper silkscreen glued onto the top, but you might decide to build the circuit on a solderless breadboard or perhaps etch your own printed circuit board.

    [​IMG]

    Code:
    Parts List
    
    1 ea. - C1, 0.1uf monolithic ceramic capacitor
    8 ea. - D1-D8, generic discrete LED
    8 ea. - R1-R8, 470 ohm, 1/8th watt carbon film resistor
    1 ea. - R9, 10 kohm, 1/8th watt carbon film resistor
    1 ea. - SW1, generic PCB momentary contact switch
    1 ea. - U1, PIC16F628A micro controller
    1 ea. - prototype board or solderless breadboard
    1 ea. - regulated 5 volt D.C. power source
    
    Software
    The program is designed to continuously display LED sequences contained in one of eight FX (effects) tables. Each table can contain up to 255 sequences or steps and each step contains two parts, (1) the LED <pattern>, and (2) the <duration> for that pattern. The <pattern> part of each step is simply eight bits which match the position of the eight LEDs on the project board. A '1' bit will turn an LED on while a '0' bit will turn an LED off. The <duration> part of each step must contain a value from 1 to 255 which corresponds to the time the pattern will be displayed in 10-ms increments (1..255 duration = 10..2550 msecs) before going on to the next step. When the program has finished displaying the last step in an FX table, it wraps around to start again at the first step in that table. When you press the push button switch, the program will move on to displaying the next FX table. Here's what one of the program FX tables looks like (for a Knight Rider type effect);

    Code:
    fx2
            dt      (fx3-fx2)/2     ; <steps>                         |B0
            dt      b'00000001',8   ; <pattern>, <duration>           |B0
            dt      b'00000010',8   ;                                 |B0
            dt      b'00000100',8   ;                                 |B0
            dt      b'00001000',8   ;                                 |B0
            dt      b'00010000',8   ;                                 |B0
            dt      b'00100000',8   ;                                 |B0
            dt      b'01000000',8   ;                                 |B0
            dt      b'10000000',8   ;                                 |B0
            dt      b'01000000',8   ;                                 |B0
            dt      b'00100000',8   ;                                 |B0
            dt      b'00010000',8   ;                                 |B0
            dt      b'00001000',8   ;                                 |B0
            dt      b'00000100',8   ;                                 |B0
            dt      b'00000010',8   ;                                 |B0
    fx3
    
    Using MPLAB, the user can edit or modify any line in an FX table or insert and delete lines in an FX table and the program will automatically keep track of the number of steps in each table.

    Summary
    Short of teaching someone how to use MPLAB, which is beyond the scope of this article, feel free to ask questions if, as I suspect, I've left out some important piece of information.

    Cheerful regards, Mike

    Attached Files:

    Last edited: Jun 2, 2014
    RRITESH KAKKAR likes this.
  2. Sparky49

    Sparky49 Active Member

    Joined:
    Jul 16, 2011
    Messages:
    768
    Location:
    Cambridgeshire
    Hi,

    I am interested in your project, but it looks like your image links are broken.
  3. Bill_Marsden

    Bill_Marsden Moderator Staff Member

    Joined:
    Mar 24, 2008
    Messages:
    19,147
    Location:
    Dallas, TX (GMT-5 w/ DST)
    Nice job! It is approved. I'll post a link in the index ASAP.

    Much better submission than most. It sets the standard.

    I put it in the Lighting, LED Flashlights, Etc catagory.

    If you want me to move it to the Microprocessors / Micro Controllers class let me know.
  4. Georacer

    Georacer Moderator Staff Member

    Joined:
    Nov 25, 2009
    Messages:
    4,909
    Location:
    Athens, Greece (GMT +2)
    Neat project, very compact.

    I wonder: Am I the only one who uses stripped wires on the underside of the perfboard? I feel they 're more manipulable this way.
  5. Bill_Marsden

    Bill_Marsden Moderator Staff Member

    Joined:
    Mar 24, 2008
    Messages:
    19,147
    Location:
    Dallas, TX (GMT-5 w/ DST)
    I like the insulation. I did buy some specialty teflon ultra fine wire though, both 28 and 30 gauge. Teflon won't melt when soldered, but it is expensive and soft (cold flows).
  6. DerStrom8

    DerStrom8 Well-Known Member

    Joined:
    Feb 20, 2011
    Messages:
    1,934
    Location:
    Vermont, U.S.A. (GMT-5)
    Well done, MMcLaren.

    @Geo, I use insulated wire for a few reasons--One, it prevents shorts, two, it prevents shorts, and three, it prevents shorts. :D:p
    Sparky49 likes this.
  7. gerty

    gerty Well-Known Member

    Joined:
    Aug 30, 2007
    Messages:
    930
    Location:
    Tennessee GMT -5
    I use 30 gauge wire wrap wire (insulated) for jobs like this. I use standard sockets and solder the connections.

    Edit: here's a couple of lousy pics of the sequencer we made in class here for future students to learn programming.
    It shows the type of wire I'm referring to.

    Attached Files:

    Last edited: Mar 19, 2012
  8. RRITESH KAKKAR

    RRITESH KAKKAR Well-Known Member

    Joined:
    Jun 29, 2010
    Messages:
    1,353
    Location:
    India
  9. BillO

    BillO Well-Known Member

    Joined:
    Nov 24, 2008
    Messages:
    974
    Location:
    Canada
    Cool.

    I also use wire wrap wire to hook up circuits.
  10. Bill_Marsden

    Bill_Marsden Moderator Staff Member

    Joined:
    Mar 24, 2008
    Messages:
    19,147
    Location:
    Dallas, TX (GMT-5 w/ DST)
    If someone could go through the programing steps that would be useful.

    That, and I'm eradicating a spammer trace. :D
    DerStrom8 likes this.
  11. MMcLaren

    MMcLaren Thread Starter Active Member

    Joined:
    Feb 14, 2010
    Messages:
    648
    Location:
    Michigan, USA
    While a printed circuit board (PCB) would be best, using 30 gauge kynar wire-wrap wire for these little point-to-point wiring projects does work quite well. The same wiring method will be used on an upcoming project board (preview below).

    Cheerful regards, Mike

    Attached Files:

  12. Sparky49

    Sparky49 Active Member

    Joined:
    Jul 16, 2011
    Messages:
    768
    Location:
    Cambridgeshire
    Videos please!!!
  13. tracecom

    tracecom Well-Known Member

    Joined:
    Apr 16, 2010
    Messages:
    3,262
    Location:
    West Tennessee
    I am a complete novice to PIC programming, so the answer to this question may be obvious to everyone but me. When I try to build the project, it fails with the following report.

    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 182 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 182 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 183 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 183 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 184 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 184 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 185 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 185 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 186 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 186 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 187 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 187 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 188 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 188 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 189 : Operand contains unresolvable labels or is too complex
    Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 189 : Operand contains unresolvable labels or is too complex
    Halting build on first failure as requested.
    ----------------------------------------------------------------------
    Debug build of project `C:\Documents and Settings\Charles R. Hampton\Desktop\PIC MCU's\CRH Project Files\MPASM Playtime Projects\PIC16F628A LED Sequencer.mcp' failed.
    Language tool versions: MPASMWIN.exe v5.43, mplink.exe v4.41, mplib.exe v4.41
    Preprocessor symbol `__DEBUG' is defined.
    Tue May 08 15:06:34 2012
    ----------------------------------------------------------------------
    BUILD FAILED

    The errors seem to point to this section of the code.

    Code:
    ;******************************************************************
    ;  directory of fx tables (index 0..7 -> fx1..fx8)                *
    ;******************************************************************
    fxdir
            dt      fx1%256,fx1/256 ; fx1 array address               |B0
            dt      fx2%256,fx2/256 ; fx2 array address               |B0
            dt      fx3%256,fx3/256 ; fx3 array address               |B0
            dt      fx4%256,fx4/256 ; fx4 array address               |B0
            dt      fx5%256,fx5/256 ; fx5 array address               |B0
            dt      fx6%256,fx6/256 ; fx6 array address               |B0
            dt      fx7%256,fx7/256 ; fx7 array address               |B0
            dt      fx8%256,fx8/256 ; fx8 array address               |B0
    Can someone tell my why and how to fix the problem? Thanks.
  14. DerStrom8

    DerStrom8 Well-Known Member

    Joined:
    Feb 20, 2011
    Messages:
    1,934
    Location:
    Vermont, U.S.A. (GMT-5)
    Could you post your present code, please?

    I think your problem is that you're building the program as relocatable code. If you change it in MPLAB to absolute code, it shouldn't give you the error. I may be wrong, but it's worth a shot.
    Last edited: May 8, 2012
  15. tracecom

    tracecom Well-Known Member

    Joined:
    Apr 16, 2010
    Messages:
    3,262
    Location:
    West Tennessee
    I think I chose relocatable code, but I could be wrong.

    I tried to post the code, but it exceeds the 10000 character limit. It's the code that was attached to the original post in this thread.
  16. DerStrom8

    DerStrom8 Well-Known Member

    Joined:
    Feb 20, 2011
    Messages:
    1,934
    Location:
    Vermont, U.S.A. (GMT-5)
    Sorry, please read my edited post. I had relocatable and absolute backwards. :rolleyes:
  17. tracecom

    tracecom Well-Known Member

    Joined:
    Apr 16, 2010
    Messages:
    3,262
    Location:
    West Tennessee
    OK, I just changed it to absolute and it compiled. :confused: What I don't know about programming PICs is limitless.

    So, I programmed the chip. Now, I have to disconnect the wires that were connected to pins 12 and 13, and use those pins (plus others) to connect to LEDs per the schematic. Correct?
  18. DerStrom8

    DerStrom8 Well-Known Member

    Joined:
    Feb 20, 2011
    Messages:
    1,934
    Location:
    Vermont, U.S.A. (GMT-5)
    if 12 and 13 are PGC and PGD, and you want to use them as ports, then yes-- You'll need to disconnect your programmer from the circuit in order for it to work.
  19. tracecom

    tracecom Well-Known Member

    Joined:
    Apr 16, 2010
    Messages:
    3,262
    Location:
    West Tennessee
    It works! :D I have LEDs flashing.
  20. MMcLaren

    MMcLaren Thread Starter Active Member

    Joined:
    Feb 14, 2010
    Messages:
    648
    Location:
    Michigan, USA
    hi tracecom,

    Thank you for trying the project and my apologies for forgetting to say it was an "absolute" mode project.

    Have fun... Cheerful regards, Mike
    Last edited: May 8, 2012
Similar Threads
Forum Title Date
The Completed Projects Collection Project : Electronic Load Sep 16, 2014
The Completed Projects Collection Project: TA1000PS - PSU for audio amplifiers with protection, sofstart and fan contro Jul 20, 2014
The Completed Projects Collection Project : Mono Preamp Nov 24, 2013
The Completed Projects Collection Project : Halloween boo badge Oct 5, 2013
The Completed Projects Collection A simple 3.2" TFT LCD Module with Touch Panel test project Sep 25, 2013

Share This Page