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
    3,154


    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!

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    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.

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    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

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    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

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    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: 12048
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!

Members who have read this thread : 7

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