Charlie-plexing


Closed Thread
Results 1 to 40 of 61

Thread: Charlie-plexing

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,956

    Default Charlie-plexing

    The need to control a lot of LEDs arose in my residential alarm project, the most efficient I could google was charlie-plexing. I thought I'd share a chart showing combinations:

    EDIT: MUST USE 1 RESISTOR PER PIN

    Name:  CharliePlex.GIF
Views: 9788
Size:  18.3 KB

    Robert


    Reference: http://ww1.microchip.com/downloads/e...Doc/40040b.pdf

    EDIT: Even better reference courtesy of Charlie, clearly explains the technique:
    http://www.instructables.com/id/Char...s--The-theory/

    Skip down to working code and videos:
    http://www.picbasic.co.uk/forum/show...132#post130132
    Last edited by Demon; - 18th December 2014 at 06:25. Reason: Added information

  2. #2
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    As I study what is clearly an amazing example, many thoughts come to mind...

    "There is only one step from the sublime to the ridiculous." - Napoleon Bonaparte.

    Stay tuned for Robert's forthcoming book: "Burglary with a Light Show"

    A subtitle: Redundancy in redundant lighting systems .

    While I jest, I do so in fun. I am... I search for an adjective... somehow "flabbergasted" seems appropriate. You are controlling nearly what could be, an entire string of holiday lights, with 10 pins!

    Thanks for sharing!

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    And the real beauty is that unlike multiplexing you don't have to constantly service the array just set the inputs and outputs and write once to the outputs. Good example Demon.

    George

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,956


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Congratulate me once I get mine working. LOL

    Robert

  5. #5
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Hi Robert - a couple questions / thoughts....
    I think you have too many resistors. With the original Charlie-plexing, there should be one current limiter per pin, not per diode, since some combinations rely on the forward volt drop of a diode to keep two others from coming on. I think what you did will work, but once you get beyond 3 pins, you may start having different intensities of LEDs. It would certainly save you some components to go per pin rather than per LED pair.
    Do the red and green diodes have the same volt drop? Green is usually about double red, so there will be still more challenges. Is it your intent that something is green or red, but never off unless broken? I think that might be difficult to do too. The array will need to be constantly scanned if more than one led should be on at any given time. But you'll want to do that to save power, anyway.
    Have you done a big truth table to see what happens for each combination? You'll need that to write the code anyway, but it might save you a lot of work. I don't think this is something that can be tested in a simulator easily since it depends on analogue effects.
    Anyway, very cool approach if you can work around those limitations!

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,956


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Charlie! We were just talking about you.

    Quote Originally Posted by Charlie View Post
    Hi Robert - a couple questions / thoughts....
    I think you have too many resistors. With the original Charlie-plexing, there should be one current limiter per pin, not per diode, since some combinations rely on the forward volt drop of a diode to keep two others from coming on. I think what you did will work, but once you get beyond 3 pins, you may start having different intensities of LEDs. It would certainly save you some components to go per pin rather than per LED pair.
    Many LEDs on the same pin may be on, but only a single LED per pair can be lit.

    The tri-state properties of a pin control which LED is lit, not forward voltage drop. See Tip #2 in the Microchip PDF.

    LED intensity is not supposed to vary depending on active LEDs.

    Do the red and green diodes have the same volt drop? Green is usually about double red, so there will be still more challenges.
    Probably not, the LEDs I have in stock do not have identical properties. But they are close enough for personal use. I am compensating by using different light intensities; ie: I have varying intensities of LEDs for the same colour. Bulk purchases so I don't have specs.

    Is it your intent that something is green or red, but never off unless broken? I think that might be difficult to do too.
    I don't understand.

    The array will need to be constantly scanned if more than one led should be on at any given time. But you'll want to do that to save power, anyway.
    Yes, definitely scanning to save current.

    Have you done a big truth table to see what happens for each combination? You'll need that to write the code anyway, but it might save you a lot of work.
    Next on my TO-DO list.

    I don't think this is something that can be tested in a simulator easily since it depends on analogue effects.
    Anyway, very cool approach if you can work around those limitations!
    Yes it can be tested, this is digital only. But I don't have Proteus.

    Robert

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,956


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Quote Originally Posted by Charlie View Post
    Hi Robert - a couple questions / thoughts....
    I think you have too many resistors. With the original Charlie-plexing, there should be one current limiter per pin, not per diode, since some combinations rely on the forward volt drop of a diode to keep two others from coming on. I think what you did will work, but once you get beyond 3 pins, you may start having different intensities of LEDs. It would certainly save you some components to go per pin rather than per LED pair.
    ...
    Aaaaaaaand I think this just came back to bite me. LOL

    Robert

  8. #8
    Join Date
    Jun 2016
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Hi Richard
    Thanks again for some great information.
    Got the 20 Leds working fine. Tried the pauseus 1200 in the code and they are very dim with 100 ohm resistors.
    Found out that in the tris values where you have a pair you leave both alone if the port.4 (16) is involved.
    I have been looking through the PBP compiler manual but can not find any reference to the $e0 or the $f0.
    Does the $e0 remove the mask from all the upper 4 bits? and are there any more masking commands?
    I am thinking of doing a 30 led charlieplex, I have the layout for it.
    They are just on a breadboard at the moment and until I can design a good pattern that is where they will stay.
    I would like to know more about your last code set but I think I will need to wait until I upgrade and get a 16f1825 pic.
    Regards
    Jim

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,505


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    $e0 = binary 11100000
    $f0 = bin 11110000

    logical function AND (&) goes like this

    a b a&b
    0 0 0
    0 1 0
    1 0 0
    1 1 1

    logical bitwise function OR (|) goes like this
    a b a&b
    0 0 0
    0 1 1
    1 0 1
    1 1 1

    masking clearing and setting bit/s in a var can be accomplished this way

    eg if a = %11111111 (255 or $ff)

    then a&$e0= %11100000

    then a | 12 = %11101100

    see bitwise in book
    Warning I'm not a teacher

  10. #10
    Join Date
    Jun 2016
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Hi
    I'm new to this Forum.
    I tried to CharliePlex 12 Leds using a 16F84A and tried to use both the A and B ports but it didn't work.
    Is it possible to do that?
    Regards
    Jim

  11. #11
    Join Date
    Jun 2016
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Hi
    I'm trying to light pairs of Leds in a 12 Led CharliePlex.
    I manage to light 4 pairs with different Leds but can't get past 4 as I end up lighting Leds used in the first 4 sets.
    Code
    #CONFIG
    __CONFIG _XT_OSC & _CP_OFF
    #ENDCONFIG
    'DEFINES:
    define osc 10
    'Initialize:
    TRISA = %00000000 'Set PORTA to Output
    PORTA = %00000000 'Set Ports Off
    pause 1000
    MAINLOOP
    pause 1000
    TRISA = %11110100 'Enable Pins A.0, A.1, A.3
    PORTA = %00001001 'Turn on Pins A.0, A.3 (Led 2 and 9)
    pause 1000
    TRISA = %11110100 'Enable Pins A.0, A.1, A.3
    PORTA = %00000011 'Turn on Pin A.0, A.1 (Leds 10 and 12)
    pause 1000
    TRISA = %11111000 'Enable Pins A.0, A.1 A.2
    PORTA = %00000011 'Turn on Pins A.0, A.1 (Leds 4 and 8)
    pause 1000
    TRISA = %11110010 'Enable A.0, A.2, A.3
    PORTA = %00001100 'Turn on A.2, A.3 (Leds 7 and 11)
    pause 1000
    TRISA = %11111111 'All Pins Disabled
    goto MAINLOOP
    end
    I am using 16F84A PIC
    PICkit3 programmer
    Microcode Studio Plus 5
    MPLAB IPE
    Windows 7
    Is this the norm for CharliePlex ?
    Regards
    Jim(Boater)

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,505


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    without a schematic its a bit difficult to intrepret whats going on in your code

    wired like this , i made a table on whats needed to light each led
    here is an example for a pic16f1825 to light each led in sequence


    Ps code in code tags is ten times easier to interpret
    Code:
    '****************************************************************
    '*  Name    : charlieplex.pbp                                        *
    '*  Author  : richard                                   *
    '*  Notice  :                                *
    '*          :                                *
    '*  Date    :                                          *
    '*  Version :    16f1825     @3.3 volts                               *
    '*  Notes   :       *
    '*          :              *
    '*            
    '****************************************************************
      
    #CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_ON  &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF
    #ENDCONFIG
    
    DEFINE OSC 32
     
         
    led var byte
    tmp var byte
     
    OSCCON=$70
    ANSELA=0
    ANSELC=0
    
    'TRISA = 0110
    'porta.0=1
    'pause 4000 
    'serout2 PORTA.0,84,[ "charlieplex",13,10]
       
    mainloop:
        
        for led=0 to 11
            lookup led,[12,12,9,9,3,3,5,5,6,6,10,10],tmp
            TRISC = $f0|tmp
            lookup led,[ 2, 1,4,2,8,4,8,2,8,1 ,4, 1],tmp
            latC = tmp
            pause 200
        next 
    goto mainloop
    Attached Images Attached Images  
    Last edited by richard; - 19th June 2016 at 10:27.
    Warning I'm not a teacher

  13. #13
    Join Date
    Jun 2016
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Hi Richard
    Sorry not very good at the workings of the Forum, still new but still trying.
    I don't have a 16f1825 pic in fact my version of MicroCode Studio does not have that PIC listed?
    I copied and pasted your code into MicroCode Studio but it would not compile with Sintax errors for , OSCON $70, ANSELA = 0, ANSELC = 0, TRISC = $f0.
    Tried putting a 16f877a into the pic selection with almost same result.
    I thought I had attached a diagram last time so have tried again also the code in tags, I hope.
    Your pin set up is in fact the same as mine just drawn slightly different.
    I am trying to flash pairs of Leds and managed to flash 4 pairs but no more.
    Regards
    Jim

    '* Name : CharliePlexing *
    '* Author : Jim Hagan *
    '* Notice : Copyright (c) 2016 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 15/06/2016 *
    '* Version : *
    '* Notes : Twelve Leds 2 and 2 pattern *
    '* : For 16F84A *
    '************************************************* ***************
    #CONFIG
    __CONFIG _XT_OSC & _CP_OFF
    #ENDCONFIG
    'DEFINES:
    define osc 10
    'Initialize:
    TRISA = %00000000 'Set PORTA to Output
    PORTA = %00000000 'Set Ports Off
    pause 1000
    MAINLOOP
    pause 1000
    TRISA = %11110100 'Enable Pins A.0, A.1, A.3
    PORTA = %00001001 'Turn on Pins A.0, A.3 (Led 2 and 9)
    pause 1000
    TRISA = %11110100 'Enable Pins A.0, A.1, A.3
    PORTA = %00000011 'Turn on Pin A.0, A.1 (Leds 10 and 12)
    pause 1000
    TRISA = %11111000 'Enable Pins A.0, A.1 A.2
    PORTA = %00000011 'Turn on Pins A.0, A.1 (Leds 4 and 8)
    pause 1000
    TRISA = %11110010 'Enable A.0, A.2, A.3
    PORTA = %00001100 'Turn on A.2, A.3 (Leds 7 and 11)
    pause 1000
    TRISA = %11111111 'All Pins Disabled
    goto MAINLOOP
    end
    Name:  12 Leds 4 Pins.jpg
Views: 7866
Size:  321.9 KBName:  12 Leds 4 Pins.jpg
Views: 7866
Size:  321.9 KB

  14. #14
    Join Date
    May 2013
    Location
    australia
    Posts
    2,505


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    I copied and pasted your code into MicroCode Studio but it would not compile with Sintax errors for , OSCON $70, ANSELA = 0, ANSELC = 0, TRISC = $f0.
    NOT ALL PICS ARE EQUAL , some study of the data sheet is always reccomended

    your code is posted in Quote tags not code tags [#]


    try this for a 16f84a

    Code:
    '****************************************************************
    '*  Name    : charlieplex.pbp                                        *
    '*  Author  : richard                                   *
    '*  Notice  :                                *
    '*          :                                *
    '*  Date    :                                          *
    '*  Version :    16f84A                                   *
    '*  Notes   :       *
    '*          :              *
    '*            
    '****************************************************************
    #CONFIG
    cfg = _XT_OSC
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _CP_OFF
      __CONFIG cfg
    #ENDCONFIG
     define osc 10
    led var byte
    tmp var byte
    
      
    ' tris     port     t,p
    '1 1100 0010    12,2
    '2 1100 0001    12,1
    '3 1001 0100    9,4 
    '4 1001 0010    9,2
    '5 0011 1000    3,8
    '6 0011 0100    3,4
    '7 1010 0100    10,4
    '8 1010 0001    10,1
    '9 0101 1000    5,8
    '10 0101 0010    5,2
    '11 0110 1000    6,6
    '12 0110 0001    6,1
     
       
    mainloop:
        
        for led=0 to 11
            lookup led,[12,12,9,9,3,3,10,10,5,5,6,6],tmp
            TRISA = $f0|tmp
            lookup led,[ 2, 1,4,2,8,4, 4, 1,8,2,6,1],tmp
            PORTA = tmp
            pause 200
        next 
    goto mainloop
    Warning I'm not a teacher

  15. #15
    Join Date
    May 2013
    Location
    australia
    Posts
    2,505


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    i see the problem
    TRISA = %11110100 'Enable Pins A.0, A.1, A.3
    PORTA = %00001001 'Turn on Pins A.0, A.3 (Led 2 and 9)
    TRISA = %11110100 == bad
    you can only light 1 led at a time , only two pins can be outputs at any one time (one high one low) the others need to be in a high impedence state [not high - high impedence ie input]

    to simulate multiple lit leds the the charlieplex needs to be driven multiplex style
    Code:
    '****************************************************************
    '*  Name    : charlieplex.pbp                                        *
    '*  Author  : richard                                   *
    '*  Notice  :                                *
    '*          :                                *
    '*  Date    :                                          *
    '*  Version :    16f84A                                   *
    '*  Notes   :       *
    '*          :              *
    '*            
    '****************************************************************
    #CONFIG
    cfg = _XT_OSC
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _CP_OFF
      __CONFIG cfg
    #ENDCONFIG
     define osc 10
    led var byte
    tmp var byte
    
      
    ' tris port
    '1 1100 0010    12,2
    '2 1100 0001    12,1
    '3 1001 0100    9,4 
    '4 1001 0010    9,2
    '5 0011 1000    3,8
    '6 0011 0100    3,4
    '7 1010 0100    10,4
    '8 1010 0001    10,1
    '9 0101 1000    5,8
    '10 0101 0010    5,2
    '11 0110 1000    6,6
    '12 0110 0001    6,1
     
       
    mainloop:
        
        for led=0 to 11
            lookup led,[12,12,9,9,3,3,10,10,5,5,6,6],tmp
            TRISA = $f0|tmp
            lookup led,[ 2, 1,4,2,8,4, 4, 1,8,2,6,1],tmp
            PORTA = tmp
            pause 200
        next 
        
    ;leds 2,9
       tmp=255
    while tmp
        TRISC = $f0|12
        latC = 1
        pause 10
        TRISC = $f0|5
        latC = 8
        pause 10
        tmp=tmp-1
     wend
     
    ;leds 10,12 
        tmp=255
    while tmp
        TRISC = $f0|5
        latC = 2
        pause 10
        TRISC = $f0|1
       latC = 1
        pause 10
        tmp=tmp-1
     wend
     
    ;leds 4,8
       tmp=255
    while tmp
        TRISC = $f0|9
        latC = 2
        pause 10
        TRISC = $f0|10
        latC = 1
        pause 10
        tmp=tmp-1
     wend
     
    ;leds 7,11 
        tmp=255
    while tmp
        TRISC = $f0|10
        latC = 4
        pause 10
        TRISC = $f0|6
        latC = 6
        pause 10
        tmp=tmp-1
     wend 
     
         
        
    goto mainloop
    Warning I'm not a teacher

  16. #16
    Join Date
    Jun 2016
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Hi Richard
    Thanks for the information. Your first program works just fine except that Led 11 does not light. I ran my 12 Led running program and all leds lit up. In your second one you only appear to light 4 pairs out of the 6 available,the same 4 pairs that I can light up so is it not possible to light 6 pairs?
    My program does work but I could not find a way to light all six pairs in that 12 led set up.
    I think the reason I can't compile your original program is because my PBP3 Silver only does Mid range PICS, so I need to upgrade to Gold.
    Sorry I sent two drawings, slip of the mouse finger.
    I will try and run this last program you sent and see what happens.
    Not able to understand your first program fully, the small one, but I'm trying.
    Regards
    Jim

  17. #17
    Join Date
    May 2013
    Location
    australia
    Posts
    2,505


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    In your second one you only appear to light 4 pairs out of the 6 available,the same 4 pairs that I can light up so is it not possible to light 6 pairs?
    by using multiplexing you can " light' any or even all the leds its all about persistence of vision

    to light them all

    mainloop:

    for led=0 to 11
    lookup led,[12,12,9,9,3,3,10,10,5,5,6,6],tmp
    TRISA = $f0|tmp
    lookup led,[ 2, 1,4,2,8,4, 4, 1,8,2,6,1],tmp
    PORTA = tmp
    pauseus 1200
    next
    goto mainloop
    Warning I'm not a teacher

  18. #18
    Join Date
    Jun 2016
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Hi Richard
    No problem I managed to correct it and also the two in your pairs section.
    I thought they were deliberate to make me work HaHa.

    Code:
    '****************************************************************
    '*  Name    : charlieplex.pbp                                        *
    '*  Author  : richard                                   *
    '*  Notice  :                                *
    '*          :                                *
    '*  Date    :                                          *
    '*  Version :    16f84A                                   *
    '*  Notes   :       *
    '*          :              *
    '*            
    '****************************************************************
    #CONFIG
    cfg = _XT_OSC
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _CP_OFF
      __CONFIG cfg
    #ENDCONFIG
     define osc 10
    led var byte
    tmp var byte
    
      
    ' tris port
    '1 1100 0010    12,2
    '2 1100 0001    12,1
    '3 1001 0100    9,4 
    '4 1001 0010    9,2
    '5 0011 1000    3,8
    '6 0011 0100    3,4
    '7 1010 0100    10,4
    '8 1010 0001    10,1
    '9 0101 1000    5,8
    '10 0101 0010    5,2
    '11 0110 1000    6,8
    '12 0110 0001    6,1
     
       
    mainloop:
        
        for led=0 to 11
            lookup led,[12,12,9,9,3,3,10,10,5,5,6,6],tmp
            TRISA = $f0|tmp
            lookup led,[ 2, 1,4,2,8,4, 4, 1,8,2,8,1],tmp
            PORTA = tmp
            pause 400
        next
        for led = 0 to 11
            lookup led,[12,9,3,10,5,6,6,5,10,3,9,12],tmp
            TRISA = $f0|tmp
            lookup led,[ 2,4,8, 4, 8,8,1,2,1,4,2,1],tmp
            PORTA = tmp
            pause 400
        next 
        
    ;leds 2,9
       tmp=255
    while tmp
        TRISA = $f0|12
        PORTA = 1
        pause 5
        TRISA = $f0|5
        PORTA = 8
        pause 5
        tmp=tmp-1
     wend
     
    ;leds 10,12 
        tmp=255
    while tmp
        TRISA = $f0|5
        PORTA = 2
        pause 5
        TRISA = $f0|6
        PORTA = 1
        pause 5
        tmp=tmp-1
     wend
     
    ;leds 4,8
       tmp=255
    while tmp
        TRISA = $f0|9
        PORTA = 2
        pause 5
        TRISA = $f0|10
        PORTA = 1
        pause 5
        tmp=tmp-1
     wend
     
    ;leds 7,11 
        tmp=255
    while tmp
        TRISA = $f0|10
        PORTA = 4
        pause 5
        TRISA = $f0|6
        PORTA = 8
        pause 5
        tmp=tmp-1
     wend 
    goto mainloop
    Hope you can run the above.
    I do have a problem with one of the three columns.
    I'm okay with the TRISA and PORTA columns but I am having difficulty sorting the 3rd one t, p.
    Some of the numbers fall okay with regard to tris and port but others do not. I must be looking at it wrong.
    I am presuming the t stands for tris and p for port, am I right?
    Regards
    Jim

  19. #19
    Join Date
    May 2013
    Location
    australia
    Posts
    2,505


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    led__tris____port___ t______p
    1___1100___0010__12__,__ 2
    yes t and p are tris and port in decimal form for us humans

    i can't run your code exactly my setup is wired differently to yours and different to my drawing too it appears
    hence my muddled led 11 , any of the others may may be mislabled also . i was just happy to get the leds lit up , its to jumbled up to rework it.


    i have never tried charlieplexing before, looks like the leds need to lit 15 to 20 at least times per second to minimise flicker. i was going to try a 4x4x4 charlieplex led cube but i'm having doubts now about driving 64 leds @ 20hz and having enough cpu time left to do anything else without using a pic18
    Warning I'm not a teacher

  20. #20
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Couple of things. In your schematic I don't see any current limiting resistors at each pin. They are necessary. When defining the oscillator speed osc needs to be OSC. I think the spaces in your lookup table are some of the problem. Try removing them and see what happens.

  21. #21
    Join Date
    Jun 2016
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    by using multiplexing you can " light' any or even all the leds its all about persistence of vision

    to light them all
    Hi Richard
    Just ran that short piece of code. All the Leds are lit.
    It appears to be down to one line

    Code:
    pauseus 1200
    So pausing the code for 1.2 milliseconds makes them look like they are all on?
    Regards
    Jim

  22. #22
    Join Date
    Jun 2016
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Hi AvionicsMaster1
    The schematic is not really a schematic just a drawing to sort out the CharliePlex. There are 100 Ohm resistors on each pin.
    The spaces in the lookup didn't seem to make any difference to the running of the program but I will try it without them.
    Almost all of the code is from Richard and even with very slight errors i am finding it very instructive.
    thankyou for your observations
    regards
    Jim

    So Richard when I see 12 in the t,p column I am really looking at TRIS or PORT 1100 and 7 will be 0111 ?
    Regards
    Jim

  23. #23
    Join Date
    May 2013
    Location
    australia
    Posts
    2,505


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    So Richard when I see 12 in the t,p column I am really looking at TRIS or PORT 1100 and 7 will be 0111 ?
    yes the tris and port columns are binary 0b1100=0xC = 12 or pbp parlance %1100=$c=12

    this is where i was heading for the led cube , current irq rate is 1000 Hz to drive 64 leds that needs to 5 times faster
    this codes flashes all the odd leds for 1 sec and then all the evens then repeats

    Code:
    '****************************************************************
    '*  Name    : charlieplex.pbp                                        *
    '*  Author  : richard                                   *
    '*  Notice  :                                *
    '*          :                                *
    '*  Date    :                                          *
    '*  Version :    16f1825     @3.3 volts                               *
    '*  Notes   :       *
    '*          :              *
    '*            
    '****************************************************************
      
    #CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_ON  &  _PWRTE_ON  &  _MCLRE_ON  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF
    #ENDCONFIG
    
    DEFINE OSC 32
     
     include "dt_ints-14.bas"
     Include "REENTERPBP.bas"
     
    
    asm      
    INT_LIST macro     
          INT_HANDLER TMR1_INT, _TOCK, PBP ,YES
          
          endm
           INT_CREATE
    ENDASM       
          
           
       
         
    @timer1 =TMR1L
    leds var word
    tmp var byte
    x var byte
    timer1         VAR WORD EXT
    timer1=15543
    T1CON=$31
    @ INT_ENABLE  TMR1_INT
    OSCCON=$70
    ANSELA=0
    ANSELC=0
    
       
    mainloop:
    leds=1365    
    pause 1000 
    leds=2730
    pause 1000  
    goto mainloop  
     
       
        
         
      
    TOCK:
    T1CON.0=0
    timer1=timer1+64536
    T1CON.0=1
    if leds.0[x] then
        lookup x,[12,12,9,9,3,3,5,5,6,6,10,10],tmp
        TRISC =(TRISC&$f0)|tmp
        lookup x,[ 2, 1,4,2,8,4,8,2,8,1 ,4, 1],tmp
        latC =(latC&$f0)|tmp
    endif
    x=x+1
    if x=12 then x=0
    @ INT_RETURN
    Last edited by richard; - 21st June 2016 at 14:46.
    Warning I'm not a teacher

  24. #24
    Join Date
    Jun 2016
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Hi Richard
    I'll need to do a lot more reading to know what most of your code is doing.
    I sort of understand some of it but there is a lot I don't.
    You say it is for a 64 Led cube though there only appears to be 12 leds in the lookup?
    I really need to upgrade to PBP3 compiler Gold as I can't run your code with my set up.
    On learning about the Decimal and Binary I tried to run some code for 20 Leds but some didn't light, namely the Leds whose decimal was 16.
    Is there something else that needs to be changed in the code.

    Code:
    '****************************************************************
    '*  Name    : CharliePlex                                     *
    '*  Author  : Jim                   *
    '*  Notice  : Copyright (c) 2016 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 21/06/2016                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : For PIC 16F84A                                                 *
    '****************************************************************
    #CONFIG
        __CONFIG _XT_OSC & _CP_OFF
    #ENDCONFIG
    'DEFINES:
         define OSC 10
         led var byte
         tmp var byte
         mainloop:
            
            for led=0 to 19
            lookup led,[12,12,9,9,3,3,7,7,10,10,5,5,11,11,6,6,13,13,14,14],tmp
            TRISB = $f0|tmp
            lookup led,[2,1,4,2,8,4,16,8,4,1,8,2,16,4,8,1,16,2,16,1],tmp
            PORTB = tmp
            pause 400
            next
             
    goto mainloop
    16 would be PORTB.4(00010000) by my Bin/Dec table.

    Regards
    Jim

  25. #25
    Join Date
    May 2013
    Location
    australia
    Posts
    2,505


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    I probably could have phrased that better , the code does only support 12 leds . the idea was to get a feel about led brightness and flicker
    to see if a 64 led version was worth the effort.
    when expanded to 64 leds the brightness is disappointing even with the resistors down to 39ohm.
    Warning I'm not a teacher

  26. #26
    Join Date
    May 2013
    Location
    australia
    Posts
    2,505


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    On learning about the Decimal and Binary I tried to run some code for 20 Leds but some didn't light, namely the Leds whose decimal was 16.
    Is there something else that needs to be changed in the code.
    TRISB = $f0|tmp the $f0 masks off the upper 4 bits [ this was to ensure other pins are not set to o/p by mistake

    if you need to make portb.4 an output the
    mask becomes $e0
    TRISB = $e0|tmp
    however
    all your tris values that don't need portb.4 as an output now need to bit4 set in your lookup table
    12 becomes 28 9 becomes 25 etc
    Last edited by richard; - 22nd June 2016 at 09:52. Reason: however
    Warning I'm not a teacher

Members who have read this thread : 9

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts