Charlie-plexing


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 61

Thread: Charlie-plexing

  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: 9783
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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Here one I made earlier
    Name:  Xylon.gif
Views: 7738
Size:  210.2 KB

    Actually simulated, it's the display of a tidal state indicator that one day I'll get round to building. The Xylon effect is just to test all bits with the two elements separate.

    George

    N2 does work, just a slightly dodgy GIF
    Last edited by towlerg; - 14th December 2014 at 19:16.

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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Charlie, about the red-or-green-or-broken question. I can light the red, green or nothing at all if I wish (which is possible in this application).

    I am powering only one pin at a time. Due to the interconnections on the matrix, applying power to more than one pin will have undesired results.

    Pass 1:
    "1" on pin 1, "0" on pin 2, Input remaining pins lights the top left red LED.

    Pass 2:
    "1" on pin 4, "0" on pin 3, Input remaining pins lights the top green LED between pins 3 and 4.

    But...

    Pass 3:
    "1" on pin 1, "0" on pin 2,
    "1" on pin 4, "0" on pin 3, Input remaining pins lights the top left red LED and the top green LED between pins 3 and 4,
    but it also lights
    a red LED between pins 1 and 3 and
    a green LED between pins 4 and 2
    since those circuits are also completed unintentionally.

    Robert

  9. #9
    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 towlerg View Post
    ...Actually simulated, it's the display of a tidal state indicator that one day I'll get round to building. The Xylon effect is just to test all bits with the two elements separate.

    George
    Either you messed up recording your GIF, or there's a bug in the top row.

    And it's Cylon.

    Robert



    EDIT: It might also be an Internet Explorer thing, I'm still on XP on my laptop.
    Last edited by Demon; - 14th December 2014 at 20:14.

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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    I can power pin 1:
    Name:  CharliePlex pin 1.GIF
Views: 7582
Size:  18.3 KB

    I can power pin 4:
    Name:  CharliePlex pin 4.GIF
Views: 7618
Size:  18.4 KB

    But I can't do the same thing at the same time, two unwanted LEDs come on:
    Name:  CharliePlex pins 1 and 4.GIF
Views: 7595
Size:  18.7 KB
    Edit: I just noticed I missed another unwanted LED between pins 4 and 2.

    I'll probably use a dedicated 18F24K22 running at 64MHz to manage the LEDs. I have to test, but blinking each LED individually might give enough persistence of vision (50 Hz or so).

    I was initially planning on powering all LEDs active on one pin, but that might complicate things beyond my limitted abilities. I like to keep things simple.

    I might also manage a simple keypad, not sure yet. I have enough pins, but tests will show how much the PIC can manage and still give satisfactory visual effects.

    Robert
    Last edited by Demon; - 21st December 2014 at 01:10.

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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    As I sit down to think how to manage this, one MAJOR drawback:

    You had better not forget any LEDs on your project 'cause adding one later is going to be "troublesome".

    You can always add it at the bottom of your truth table, but I'm the obsessive compulsive type that likes symetry; LEDs are handled in the logic as they are placed on the circuit board. Remnants of hating spaghetti code on mainframes (COBOL + GOTO = NIGHTMARES).

    Robert

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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Some neat stuff I forgot that I found several years ago on Charlie-plexing.

    Code:
    clear
    define osc4
    cmcon0=7
    ansel=0
    adcon0 = 0
    @ device mclr_off
    @ device wdt_off
    @ device bod_off
    @ device cpd_off
    @ device protect_off
    
    led var byte
    ledstates var byte
    trisstate var byte
    delay var word
    noghost var byte
    gpnoghost var byte
    
    noghost= %111111
    delay= 1500
    
    starthere:
    gpio.3 = 0
    if gpio.3 = 1 then
      goto main
    endif
    goto starthere
    
    main:
    for led = 1 to 6
      select case led
        case 0 : ledstates =%001 : trisstate =%100
        case 1 : ledstates =%010 : trisstate =%100
        case 2 : ledstates =%001 : trisstate =%010
        case 3 : ledstates =%100 : trisstate =%010
        case 4 : ledstates =%100 : trisstate =%010
        case 5 : ledstates =%010 : trisstate =%001
        case 6 : ledstates =%100 : trisstate =%001
      end select
      trisio = noghost
      gpio = ( gpio & %111000) | ledstates
      trisio = (trisio & %111000) | trisstate
      pause delay
    next led
    
    for led = 1 to 5
      select case led
        case 1 : ledstates =%000001: trisstate =%101110
        case 2 : ledstates =%011000: trisstate =%101110
        case 3 : ledstates =%000010: trisstate =%101101
        case 4 : ledstates =%010000: trisstate =%101101
        case 5 : ledstates =%000010: trisstate =%011101
      end select
      trisio = noghost
      gpio = ( gpio & %111000) | ledstates
      trisio = (trisio & %111000) | trisstate
      pause delay
    next led
    
    trisio=noghost
    gpio=gpnoghost
    
    goto starthere
    end
    Name:  Multiplex pins schematic.GIF
Views: 7688
Size:  11.8 KB
    Editted to add some colour, original was black on light gray background.

    I wish I could give a link and credit, but I can't find anything on google for this now (been looking for over an hour).

    Robert
    Last edited by Demon; - 14th December 2014 at 21:42. Reason: Added code instead of PDF

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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Did this a while ago. Don't know if it will help. http://www.picbasic.co.uk/forum/showthread.php?t=14220

    If you use the above program you'll need to change you define osc line.

    Good luck.

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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    I used the wiring above for pins D.1, D.2 and D.3 on a 16F877 and it didn't work as expected.

    I get 3 LEDs blinking faintly instead of a single one. It seems as if the current loops over to the unused pin and comes back.

    I'll have to check out your thread. I must be missing something.

    Code:
    ' Blink 6 LEDs connected to Port D.1, D.2 and D.3 in charlie-plex manner
    
    '   PIC             16F877      ext osc 20MHz
    '   PBP             v2.60c
    '   MPASM           v5.49
    '   MCS+            v2.1.0.7
    '   U2 programmer   v4.32
    
    asm
     __config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _DEBUG_OFF & _CP_OFF
    endasm
    
    DEFINE OSC 20
    ADCON1 = 7                  ' Set Ports to digital
    TRISA = %00000000           ' Set all Ports to output 
    TRISB = %00000000
    TRISC = %00000000
    TRISD = %00000000
    TRISE = %00000000
    PORTA = %00000000           ' Set ports OFF
    PORTB = %00000000
    PORTC = %00000000
    PORTD = %00000000
    PORTE = %00000000
        pause 100
    mainloop:
        TRISD = %11111001       ' Enable pins D.1 and 2
        PORTD = %00000100       ' Turn ON pin D.2 --> D.1
        pause 500
        PORTD = %00000010       ' Turn ON pin D.1 --> D.2
        pause 500
    
    ;    TRISD = %11110101       ' Enable pins D.1 and 3
    ;    PORTD = %00001000       ' Turn ON pin D.3 --> D.1
    ;    pause 500
    ;    PORTD = %00000010       ' Turn ON pin D.1 --> D.3
    ;    pause 500
    
    ;    TRISD = %11110011       ' Enable pins D.2 and 3
    ;    PORTD = %00000100       ' Turn ON pin D.2 --> D.3
    ;    pause 500
    ;    PORTD = %00001000       ' Turn ON pin D.3 --> D.2
    ;    pause 500
    
        TRISD = %11111111       ' All pins disabled
        pause 500
        goto mainloop
    End
    Robert

  15. #15
    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 AvionicsMaster1 View Post
    Did this a while ago. Don't know if it will help. http://www.picbasic.co.uk/forum/showthread.php?t=14220

    If you use the above program you'll need to change you define osc line.

    Good luck.

    LMAO!

    I posted YOUR program above! I googled and searched this forum to try and find where I got it from but never found it.

    I'll have to look this over again, I must miss something obvious. You have GPIO, I only see PORT and TRIS registers as relevant on a 16F877.

    Robert

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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Partly fixed.

    I was using 3 red, green and yellow LEDs; they have wildly different current draw/voltage drops. I switched to all greens and the ghosting effect is practically gone.

    I saw your comments about ghosting and noticed you output PORT before TRIS, didn't help me; tried both ways.

    Robert

    EDIT:
    Code:
    asm
     __config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _DEBUG_OFF & _CP_OFF
    endasm
    DEFINE OSC 20
    ADCON1 = 7                  ' Set Ports to digital
    TRISA = %00000000           ' Set all Ports to output 
    TRISB = %00000000
    TRISC = %00000000
    TRISD = %00000000
    TRISE = %00000000
    PORTA = %00000000           ' Set ports OFF
    PORTB = %00000000
    PORTC = %00000000
    PORTD = %00000000
    PORTE = %00000000
        pause 100
    mainloop:
        TRISD = %11111001       ' Enable pins D.1 and 2
        PORTD = %00000100       ' Turn ON pin D.2 --> D.1
        pause 500
        TRISD = %11111001       ' Enable pins D.1 and 2
        PORTD = %00000010       ' Turn ON pin D.1 --> D.2
        pause 500
    
        TRISD = %11110101       ' Enable pins D.1 and 3
        PORTD = %00001000       ' Turn ON pin D.3 --> D.1
        pause 500
        TRISD = %11110101       ' Enable pins D.1 and 3
        PORTD = %00000010       ' Turn ON pin D.1 --> D.3
        pause 500
    
        TRISD = %11110011       ' Enable pins D.2 and 3
        PORTD = %00000100       ' Turn ON pin D.2 --> D.3
        pause 500
        TRISD = %11110011       ' Enable pins D.2 and 3
        PORTD = %00001000       ' Turn ON pin D.3 --> D.2
        pause 500
    
        TRISD = %11111111       ' All pins disabled
        pause 500
        goto mainloop
    End

  17. #17
    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

  18. #18
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Hi Robert,
    This article explains what I was trying to tell you about analog vs digital effects: http://www.instructables.com/id/Char...s--The-theory/
    The Microchip article is a quick example, but not true Charlie-plexing, and it doesn't scale up nicely.

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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Ah perception, what a wonderful thing. When I said digital I meant the logic, and when you said analog you meant the properties of the LED. LOL

    I had found that article on google but didn't see anything new at first glance and moved on. It's really a few pages deep that it gets into the meat of the matter. Excellent article though, explained everything so clearly.

    I especially appreciate how he discusses making a pin input disables it. I never understood "high impedance state". It's simple, it impedes, like that 10M resistor he has on his schematic of the input pin.

    It also explains why I couldn't get a decent reading on my Saleae probe; current DOES flow through the unwanted LEDs. It's just that they don't get enough current to light up; hence the importance of forward voltage drop you mentionned (he explains that clearly). It's nice understanding what's going on.

    No ghosting with 200usec delay:


    No pauses:


    Robert
    Last edited by Demon; - 15th December 2014 at 19:23.

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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    To all, I'm learning so these may be stupid questions. Please put the flamethrowers down.

    Are you still using the 16F877? If so:

    Does ADCON1 = 7 do anything for you? It looks like none of ADC ports are on Port D and this wouldn't effect them.

    I don't think of the TRISX as setting ports to digital only setting them input or output. With the 877 are the ports already set so with a high you get 5V out and a low gives you zero when you set them as outputs?

    If you're continuing to have issues with ghosting I found, on the 12F683, that setting all ports to input and turning them off before I moved on to the next light helped quite a bit.

    Hope it helps.

  21. #21
    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 AvionicsMaster1 View Post
    To all, I'm learning so these may be stupid questions. Please put the flamethrowers down.
    ...
    There are no stupid questions, just stupid people. Sorry, couldn't resist.


    ...Are you still using the 16F877?...
    Yup.


    ...Does ADCON1 = 7 do anything for you? It looks like none of ADC ports are on Port D and this wouldn't effect them...
    I use it because I have been using digital only so far. First thing I do when using a new model PIC is run with ALLDIGITAL and add whatever it tells me to. I've used a 16F877 ever since I've been here and I'm just using copies of my first program.

    It just happened that I ran ALLDIGITAL again with this PIC when I started this testing and it also gave me that line to add.


    ...I don't think of the TRISX as setting ports to digital only setting them input or output...
    Yup.


    With the 877 are the ports already set so with a high you get 5V out and a low gives you zero when you set them as outputs?...
    I don't know if they are analog or digital by default. I'd have to check the datasheet for ADCON1.


    ...If you're continuing to have issues with ghosting I found, on the 12F683, that setting all ports to input and turning them off before I moved on to the next light helped quite a bit...
    Nope, no more ghosting. See video with 200uSec delay.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    I've since moved on to 18F44K22 after the videos but the code essentially remains the same:

    Code:
    mainloop:
    
        PortD.2 = 1             ' Heartbeat
    
        TRISA = %11111100
        PORTA = %00000001       ' LED 1
        PAUSE 200
        PORTA = %00000010       ' LED 2
        PAUSE 200
    
        TRISA = %11110011
        PORTA = %00000100       ' LED 3
        PAUSE 200
        PORTA = %00001000       ' LED 4
        PAUSE 200
    
        PortD.2 = 0             ' Heartbeat
    
        TRISA = %11001111
        PORTA = %00010000       ' LED 5
        PAUSE 200
        PORTA = %00100000       ' LED 6
        PAUSE 200
    
        TRISA = %00111111
        PORTA = %01000000       ' LED 7
        PAUSE 200
        PORTA = %10000000       ' LED 8
        PAUSE 200
    
        goto mainloop
    End
    I don't have to set the TRIS register when I remain on the same LED pair.

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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    This:

    Code:
    ' Blink 56 LEDs connected to PORT A in charlie-plex manner
    
    '   PIC             18F44K22    int osc 64MHz
    '   PBP             v2.60c
    '   MPASM           v5.49
    '   MCS+            v2.1.0.7
    '   U2 programmer   v4.32
    
    asm
     __CONFIG    _CONFIG1H, _FOSC_INTIO67_1H & _PLLCFG_ON_1H & _PRICLKEN_OFF_1H & _FCMEN_ON_1H & _IESO_OFF_1H
     __CONFIG    _CONFIG2L, _PWRTEN_ON_2L & _BOREN_SBORDIS_2L & _BORV_285_2L
     __CONFIG    _CONFIG2H, _WDTEN_OFF_2H
     __CONFIG    _CONFIG3H, _CCP2MX_PORTC1_3H & _PBADEN_OFF_3H & _CCP3MX_PORTE0_3H & _HFOFST_OFF_3H & _T3CMX_PORTB5_3H & _P2BMX_PORTC0_3H & _MCLRE_EXTMCLR_3H
     __CONFIG    _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    endasm
    
    DEFINE OSC 64
    
    OSCCON  = %01110000              ' OSCILLATOR CONTROL REGISTER
    ' bit 7 IDLEN: Idle Enable bit
    '     R/W       1 = Device enters Idle mode on SLEEP instruction
    '               0 = Device enters Sleep mode on SLEEP instruction
    ' bit 6-4 IRCF<2:0>: Internal RC Oscillator Frequency Select bits(2)
    '     R/W       111 = HFINTOSC – (16 MHz)
    '               110 = HFINTOSC/2 – (8 MHz)
    '               101 = HFINTOSC/4 – (4 MHz)
    '               100 = HFINTOSC/8 – (2 MHz)
    '               011 = HFINTOSC/16 – (1 MHz)(3)
    '           If INTSRC = 0 and MFIOSEL = 0:
    '               010 = HFINTOSC/32 – (500 kHz)
    '               001 = HFINTOSC/64 – (250 kHz)
    '               000 = LFINTOSC – (31.25 kHz)
    '           If INTSRC = 1 and MFIOSEL = 0:
    '               010 = HFINTOSC/32 – (500 kHz)
    '               001 = HFINTOSC/64 – (250 kHz)
    '               000 = HFINTOSC/512 – (31.25 kHz)
    '           If INTSRC = 0 and MFIOSEL = 1:
    '               010 = MFINTOSC – (500 kHz)
    '               001 = MFINTOSC/2 – (250 kHz)
    '               000 = LFINTOSC – (31.25 kHz)
    '           If INTSRC = 1 and MFIOSEL = 1:
    '               010 = MFINTOSC – (500 kHz)
    '               001 = MFINTOSC/2 – (250 kHz)
    '               000 = MFINTOSC/16 – (31.25 kHz)
    ' bit 3 OSTS: Oscillator Start-up Time-out Status bit
    '       R       1 = Device is running from the clock defined by FOSC<3:0> of the CONFIG1H register
    '               0 = Device is running from the internal oscillator (HFINTOSC, MFINTOSC or LFINTOSC)
    ' bit 2 HFIOFS: HFINTOSC Frequency Stable bit
    '       R       1 = HFINTOSC frequency is stable
    '               0 = HFINTOSC frequency is not stable
    ' bit 1-0 SCS<1:0>: System Clock Select bit
    '       R/W     1x = Internal oscillator block
    '               01 = Secondary (SOSC) oscillator
    '               00 = Primary clock (determined by FOSC<3:0> in CONFIG1H).
    
    OSCCON2 = %00000100              ' OSCILLATOR CONTROL REGISTER 2
    ' bit 7 PLLRDY: PLL Run Status bit
    '     R         1 = System clock comes from 4xPLL
    '               0 = System clock comes from an oscillator, other than 4xPLL
    ' bit 6 SOSCRUN: SOSC Run Status bit
    '     R         1 = System clock comes from secondary SOSC
    '               0 = System clock comes from an oscillator, other than SOSC
    ' bit 5 Unimplemented: Read as ‘0’.
    ' bit 4 MFIOSEL: MFINTOSC Select bit
    '     R/W=0     1 = MFINTOSC is used in place of HFINTOSC frequencies of 500 kHz, 250 kHz and 31.25 kHz
    '               0 = MFINTOSC is not used
    ' bit 3 SOSCGO(1): Secondary Oscillator Start Control bit
    '     R/W=0     1 = Secondary oscillator is enabled.
    '               0 = Secondary oscillator is shut off if no other sources are requesting it.
    ' bit 2 PRISD: Primary Oscillator Drive Circuit Shutdown bit
    '     R/W=1     1 = Oscillator drive circuit on
    '               0 = Oscillator drive circuit off (zero power)
    ' bit 1 MFIOFS: MFINTOSC Frequency Stable bit
    '     R         1 = MFINTOSC is stable
    '               0 = MFINTOSC is not stable
    ' bit 0 LFIOFS: LFINTOSC Frequency Stable bit
    '     R         1 = LFINTOSC is stable
    '               0 = LFINTOSC is not stable
    
    OSCTUNE = %11000000              ' OSCILLATOR TUNING REGISTER
    ' bit 7 INTSRC: Internal Oscillator Low-Frequency Source Select bit
    '     R/W       1 = 31.25 kHz device clock derived from the MFINTOSC or HFINTOSC source
    '               0 = 31.25 kHz device clock derived directly from LFINTOSC internal oscillator
    ' bit 6 PLLEN: Frequency Multiplier 4xPLL for HFINTOSC Enable bit(1)
    '     R/W       1 = PLL enabled
    '               0 = PLL disabled
    ' bit 5-0 TUN<5:0>: Frequency Tuning bits – use to adjust MFINTOSC and HFINTOSC frequencies
    '     R/W       011111 = Maximum frequency
    '               011110 =
    '               • • •
    '               000001 =
    '               000000 = Oscillator module (HFINTOSC and MFINTOSC) are running at the factory calibrated frequency.
    '               111111 =
    '               • • •
    '               100000 = Minimum frequency
    
    ANSELA = %00000000          ' Set ports to digital
    ANSELB = %00000000
    ANSELC = %00000000
    ANSELD = %00000000
    ANSELE = %00000000
    
    ADCON0 = %00000000          ' Disable ADC
    
    TRISA = %00000000           ' Set all Ports to output 
    TRISB = %00000000
    TRISC = %00000000
    TRISD = %00000000
    TRISE = %00000000
    PORTA = %00000000           ' Set ports OFF
    PORTB = %00000000
    PORTC = %00000000
    PORTD = %00000000
    PORTE = %00000000
    
    varLEDstate VAR BYTE[55]
    varLEDport  VAR BYTE[55]
    varArray    var byte
    varEEPROM   var byte
    
    varEEPROM = 0
    
    '-------------------------   T E M P O R A R Y   ------------------------------
    for varArray = 0 to 55                      ' Location in Array
        varEEPROM = varEEPROM + 1               ' Location in EEPROM
        read varEEPROM, VARLEDstate[varArray]
        varEEPROM = varEEPROM + 1
        read varEEPROM, VARLEDport[varArray]
    next varArray
    '------------------------------------------------------------------------------
    
        pause 100
    
    mainloop:
    
        for varArray = 0 to 55               ' LEDs in ascending sequence
            TRISA = VARLEDSTATE[varArray]
            PORTA = VARLEDPORT[varArray]
            PAUSE 15
        next varArray
    
        for varArray = 55 to 0 step -1      ' LEDs in decending sequence
            TRISA = VARLEDSTATE[varArray]
            PORTA = VARLEDPORT[varArray]
            PAUSE 15
        next varArray
     
        goto mainloop
    End
    
    
    DATA @1,%11111100   ' Pin A0
    DATA %00000001
    
    DATA %11111010
    DATA %00000001
    
    DATA %11110110
    DATA %00000001
    
    DATA %11101110
    DATA %00000001
    
    DATA %11011110
    DATA %00000001
    
    DATA %10111110
    DATA %00000001
    
    DATA %01111110
    DATA %00000001
    
    DATA %11111100   ' Pin A1
    DATA %00000010
    
    DATA %11111001
    DATA %00000010
    
    DATA %11110101
    DATA %00000010
    
    DATA %11101101
    DATA %00000010
    
    DATA %11011101
    DATA %00000010
    
    DATA %10111101
    DATA %00000010
    
    DATA %01111101
    DATA %00000010
    
    DATA %11111010   ' Pin A2
    DATA %00000100
    
    DATA %11111001
    DATA %00000100
    
    DATA %11110011
    DATA %00000100
    
    DATA %11101011
    DATA %00000100
    
    DATA %11011011
    DATA %00000100
    
    DATA %10111011
    DATA %00000100
    
    DATA %01111011
    DATA %00000100
    
    DATA %11110110   ' Pin A3
    DATA %00001000
    
    DATA %11110101
    DATA %00001000
    
    DATA %11110011
    DATA %00001000
    
    DATA %11100111
    DATA %00001000
    
    DATA %11010111
    DATA %00001000
    
    DATA %10110111
    DATA %00001000
    
    DATA %01110111
    DATA %00001000
    
    DATA %11101110   ' Pin A4
    DATA %00010000
    
    DATA %11101101
    DATA %00010000
    
    DATA %11101011
    DATA %00010000
    
    DATA %11100111
    DATA %00010000
    
    DATA %11001111
    DATA %00010000
    
    DATA %10101111
    DATA %00010000
    
    DATA %01101111
    DATA %00010000
    
    DATA %11011110   ' Pin A5
    DATA %00100000
    
    DATA %11011101
    DATA %00100000
    
    DATA %11011011
    DATA %00100000
    
    DATA %11010111
    DATA %00100000
    
    DATA %11001111
    DATA %00100000
    
    DATA %10011111
    DATA %00100000
    
    DATA %01011111
    DATA %00100000
    
    DATA %10111110   ' Pin A6
    DATA %01000000
    
    DATA %10111101
    DATA %01000000
    
    DATA %10111011
    DATA %01000000
    
    DATA %10110111
    DATA %01000000
    
    DATA %10101111
    DATA %01000000
    
    DATA %10011111
    DATA %01000000
    
    DATA %00111111
    DATA %01000000
    
    DATA %01111110   ' Pin A7
    DATA %10000000
    
    DATA %01111101
    DATA %10000000
    
    DATA %01111011
    DATA %10000000
    
    DATA %01110111
    DATA %10000000
    
    DATA %01101111
    DATA %10000000
    
    DATA %01011111
    DATA %10000000
    
    DATA %00111111
    DATA %10000000
    Scanning through 56 LEDs:


    Persistence of vision, no noticeable difference (not all LEDs point directly up):


    Current consumption (removed Power Indicator LED from circuit):
    - all off = 11.5mA
    - all on = 22.0 mA

    Robert
    Last edited by Demon; - 18th December 2014 at 06:38. Reason: Added persistence of vision, current

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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Only one LED will be bright enough to be visible even though multiple paths are active at the same time, because the shortest path is the only one with enough current. All the other undesired paths share the same current; not enough to make an LED glow.

    Cycling through the 56 LEDs on the 8 pins in the post above, a LED does not have enough current 7 out of 8 times:


    From Step 4:
    ...
    OK, so a current flows through LED5, current isn't flowing through LED6 because it is reverse biased (and so are LED2 and LED4)....but there is also a path for the current to take from pin A, through LED1 and LED3 isn't there? Why are these LEDs not glowing as well.

    Here is the heart of the charlieplexing scheme. Indeed there is a current flowing both LED1 and LED3, however the voltage across the both of these combined is only going to be equal to the voltage across LED5. Typically they would have half the voltage across them that LED5 has. So if we have 1.9V across LED5, then only 0.95V will be across LED1 and 0.95V across LED3.

    From the If/Vf curve mentioned at the beginning of this article we can see that the current at this half voltage is much much lower than 20mA.....and those LEDs will not glow visibly. This is known as current stealing.

    Thus most of the current will flow though the LED we want, the most direct path through the least number of LEDs (ie one LED), rather than any series combination of LEDs.
    ...
    http://www.instructables.com/id/Char...eory/?ALLSTEPS

    Robert


    (That Habs logo just "happened" to line up with the monitor.)
    Last edited by Demon; - 21st December 2014 at 01:16. Reason: Alignment of quoted text

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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    Corrected LED matrix using one resistor per pin:

    Name:  CharliePlex v2.PNG
Views: 7814
Size:  28.0 KB
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  26. #26
    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

  27. #27
    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)

  28. #28
    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

  29. #29
    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: 7865
Size:  321.9 KBName:  12 Leds 4 Pins.jpg
Views: 7865
Size:  321.9 KB

  30. #30
    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

  31. #31
    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

  32. #32
    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

  33. #33
    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

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


    Did you find this post helpful? Yes | No

    Default Re: Charlie-plexing

    led 11 failed cause i had a typo and did not convert from my setup to yours properly , sorry



    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,4   '   typo here
    '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,4,1],tmp   ;  and here
            PORTA = tmp
            pause 200
        next 
        
    ;leds 2,9
       tmp=255
    while tmp
        TRISA = $f0|12    ;  and here
        porta = 1    ;  and here
        pause 10
        TRISA = $f0|5    ;  and here
        porta = 8    ;  and here
        pause 10
        tmp=tmp-1
     wend
     
    ;leds 10,12 
        tmp=255
    while tmp
        TRISa = $f0|5    ;  and here
        porta = 2    ;  and here
        pause 10
        TRISa= $f0|1    ;  and here
       porta = 1    ;  and here
        pause 10
        tmp=tmp-1
     wend
     
    ;leds 4,8
       tmp=255
    while tmp
        TRISa= $f0|9    ;  and here
        porta = 2    ;  and here
        pause 10
        TRISa = $f0|10    ;  and here
        porta = 1    ;  and here
        pause 10
        tmp=tmp-1
     wend
     
    ;leds 7,11 
        tmp=255
    while tmp
        TRISa= $f0|10    ;  and here
        porta = 4    ;  and here
        pause 10
        TRISa = $f0|6    ;  and here
        porta = 4    ;  and here
        pause 10
        tmp=tmp-1
     wend 
     
         
        
    goto mainloop
    Last edited by richard; - 21st June 2016 at 06:21.
    Warning I'm not a teacher

  35. #35
    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

  36. #36
    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

  37. #37
    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

  38. #38
    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.

  39. #39
    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

  40. #40
    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

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