PDA

View Full Version : Charlie-plexing



Demon
- 14th December 2014, 08:02
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

7511

Robert


Reference: http://ww1.microchip.com/downloads/en/DeviceDoc/40040b.pdf

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

Skip down to working code and videos:
http://www.picbasic.co.uk/forum/showthread.php?t=19618&p=130132#post130132

Amoque
- 14th December 2014, 12:58
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!

towlerg
- 14th December 2014, 14:56
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

Demon
- 14th December 2014, 15:18
Congratulate me once I get mine working. LOL

Robert

Charlie
- 14th December 2014, 16:17
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!

Demon
- 14th December 2014, 18:51
Charlie! We were just talking about you. :)


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

towlerg
- 14th December 2014, 19:11
Here one I made earlier
7512

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

Demon
- 14th December 2014, 19:14
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

Demon
- 14th December 2014, 19:17
...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. :D

Robert
:)


EDIT: It might also be an Internet Explorer thing, I'm still on XP on my laptop.

Demon
- 14th December 2014, 19:41
I can power pin 1:
7513

I can power pin 4:
7514

But I can't do the same thing at the same time, two unwanted LEDs come on:
7515
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

Demon
- 14th December 2014, 19:55
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

Demon
- 14th December 2014, 21:32
Some neat stuff I forgot that I found several years ago on Charlie-plexing.


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

7517
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

AvionicsMaster1
- 14th December 2014, 22:50
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.

Demon
- 15th December 2014, 01:05
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.


' 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

Demon
- 15th December 2014, 01:12
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

Demon
- 15th December 2014, 01:35
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:

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

Demon
- 15th December 2014, 01:56
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

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

Demon
- 15th December 2014, 19:17
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:

https://www.youtube.com/watch?v=ayIdN6Iy5Js

No pauses:

https://www.youtube.com/watch?v=knGTtV4vjI0

Robert

AvionicsMaster1
- 16th December 2014, 14:10
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.

Demon
- 16th December 2014, 17:18
To all, I'm learning so these may be stupid questions. Please put the flamethrowers down.
...

There are no stupid questions, just stupid people. :D 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
:)

Demon
- 16th December 2014, 17:30
I've since moved on to 18F44K22 after the videos but the code essentially remains the same:



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.

Demon
- 18th December 2014, 06:04
This:


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

https://www.youtube.com/watch?v=TqhbUcmDLYA

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

https://www.youtube.com/watch?v=7lANx5QZuCE

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

Robert

Demon
- 21st December 2014, 01:00
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:
http://i991.photobucket.com/albums/af37/DemonDNF/IMG_20141220_193652_zps48163a77.jpg (http://s991.photobucket.com/user/DemonDNF/media/IMG_20141220_193652_zps48163a77.jpg.html)

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/Charlieplexing-LEDs--The-theory/?ALLSTEPS

Robert


(That Habs logo just "happened" to line up with the monitor.)

Demon
- 21st December 2014, 16:45
Corrected LED matrix using one resistor per pin:

7537

Boater
- 16th June 2016, 07:33
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

Boater
- 16th June 2016, 13:53
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)

richard
- 19th June 2016, 10:22
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



'************************************************* ***************
'* 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

Boater
- 20th June 2016, 04:03
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

82618261

richard
- 20th June 2016, 04:46
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



'************************************************* ***************
'* 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

richard
- 20th June 2016, 12:47
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


'************************************************* ***************
'* 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

Boater
- 20th June 2016, 14:11
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

richard
- 20th June 2016, 14:30
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

richard
- 21st June 2016, 06:10
led 11 failed cause i had a typo and did not convert from my setup to yours properly , sorry




'************************************************* ***************
'* 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

Boater
- 21st June 2016, 13:17
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.


'************************************************* ***************
'* 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

richard
- 21st June 2016, 13:41
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

Boater
- 21st June 2016, 13:49
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


pauseus 1200

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

AvionicsMaster1
- 21st June 2016, 13:52
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.

Boater
- 21st June 2016, 14:25
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

richard
- 21st June 2016, 14:44
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


'************************************************* ***************
'* 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

Boater
- 22nd June 2016, 08:54
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.


'************************************************* ***************
'* 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

richard
- 22nd June 2016, 09:34
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.

richard
- 22nd June 2016, 09:43
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

Boater
- 22nd June 2016, 14:27
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

richard
- 22nd June 2016, 14:44
$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

Boater
- 27th June 2016, 14:22
Hi Richard
Thank you for the information, seems I have a lot to learn.
I have been reading up on Bitwise in the PBP Compiler Ref manual.
Can't find out how to type in the OR operator, doesn't appear to be on my keyboard.
Anyway I'll keep on reading and see if I can make sense of it.
Regards
Jim

Demon
- 27th June 2016, 21:45
Jim,

If you can't type | using SHIFT, go through again with ALT.

Edit: or come here and COPY the character and then PASTE it in your code.

Robert

AvionicsMaster1
- 28th June 2016, 13:58
Depending on the keyboard the | character doesn't look like it on your keyboard. Never could figure out why they do this but it's above the ENTER key and is accessed by using SHIFT and the \ key. It looks like a vertical line separated by a space in the middle. I thought in old programming terminology it's called the pipe symbol.

Though it looks cool to use those symbols I think it's easier just to type OR and know what it means.

Boater
- 29th June 2016, 03:41
Hi Demon and AvionicsMaster1
Thank you for the information.
I will try your suggestions though I think typing OR seems the easiest.
Regards
Jim

richard
- 29th June 2016, 04:07
I will try your suggestions though I think typing OR seems the easiest.


Though it looks cool to use those symbols I think it's easier just to type OR and know what it means.


NOT sure about that , this is what the book says



3.4.2 Logical vs. Bitwise

Logical operators are very different than bitwise operators! There are

circumstances under which PBP will allow the use of logical operators in
expressions. This means that no error message will be generated when you
mistakenly use a logical operator in a bitwise calculation. Consider the following:
result = PORTB AND %00001111
' Returns logical result (1 or 0)
The above example will compile and give a result. The value of the result can only
be one or zero (true or false). If the intent is to use a bitwise operation to obtain a
binary result, you MUST USE BITWISE OPERATORS:



i_term=0
d_err=4
i_err= 3
i_term= i_err | d_err
serout2 PORTA.0,84,[ "3 | 4 ",9,#i_term, 13,10]
i_term= i_err OR d_err
serout2 PORTA.0,84,[ "3 OR 4 ",9,#i_term, 13,10]

PRINTOUT:
3 | 4 7
3 OR 4 65535

Boater
- 2nd July 2016, 09:00
Hi Richard
Looking at the PBP3 Compiler Manual it only shows OR as the description for
| in the Bitwise operators. It does show OR as an operator in the Logical operators.

Regards
Jim

richard
- 2nd July 2016, 09:28
Logical operators are not bitwise operators
| does a bitwise OR
OR does a Logical OR

2 | 3 = 7
2 OR 3 = ! 0 [ not nothing ]

AvionicsMaster1
- 5th July 2016, 23:08
Yes I made a mistake. There is a difference between bitwise operations and logical operations. I vehemently apologize for the second part of my post.

Boater
- 10th July 2016, 13:27
Hi AvionicsMaster1
No big deal, someone on here reckons that mistakes are not mistakes but learning opportunities and I think he's right having had plenty of learning opportunities myself.
Still getting them.
Using your idea to copy and paste |OR Demon, thanks.
Thanyou to Richard for keeping us right and for introducing me to the lookup command which has led me onto writing my code in decimal and hex.
Having great fun with them, well this is a hobby and hobbies are supposed to be fun.
The following code is for a set of traffic lights on the roads as part of a 1/76 scale model railway.


'************************************************* ***************
'* Name : Four Way Traffic Lights *
'* Author : Jim Hagan *
'* Date : 10/07/2016 *
'* Version : 1.0 *
'* Notes : For 16F84A *
'************************************************* ***************
#CONFIG
__CONFIG _XT_OSC & _CP_OFF
#ENDCONFIG
'Defines
DEFINE OSC 4 'Tell PBP3 expected system clock frequency
'Aliases
LEDS1 var PORTB 'Assign name LEDS1 to PORTB
LEDS2 VAR PORTA 'Assign name LEDS2 to PORTA
'Variables
i var byte
'Initialize
TRISB = $0 'Set PORTB to Output
TRISA = $0
'Program Code
START
gosub REDGREEN
gosub REDAMBER
gosub GREENRED
gosub AMBERRED
goto START
REDGREEN
LEDS1 = $61 'LEDS 0, 5 and 6 on PORTB On
LEDS2 = $08 'LED 3 on PORTA On
pause 3000 'Puts lights on for 3 seconds
for i = 1 to 10
LEDS1 = $0
LEDS2 = $0
next i
return
REDAMBER
LEDS1 = $D3 'LEDS 0, 1, 4, 6 and 7 on PORTB On
LEDS2 = $04 'LED 2 on PORTA On
pause 2000 'Puts lights on for 2 seconds
for i = 1 to 10
LEDS1 = $0
LEDS2 = $0
next i
return
GREENRED
LEDS1 = $C 'LEDS 2 and 3 on PORTB On
LEDS2 = $03 'LEDS 0 and 1 on PORTA On
pause 3000
for i = 1 to 10
LEDS1 = $0
LEDS2 = $0
next i
return
AMBERRED
LEDS1 = $9A 'LEDS 1, 3, 4 and 7 on PORTB On
LEDS2 = $06 'LEDS 1 and 2 on PORTA On
pause 2000
for i = 1 to 10
LEDS1 = $0
LEDS2 = $0
next i
return
end

Regards
Jim

Boater
- 29th March 2018, 05:22
Hi
Looks like I made a wrong post??
Don't know what?

mpgmike
- 29th March 2018, 15:33
On topic, the March 2018 Nuts and Volts Magazine has an article on "Charlieplexing an analog style LED clock", by Robert Gill. It drives 182 LEDs with 14 I/Os.

Ioannis
- 29th March 2018, 17:26
Isn't that impressive?

Ioannis

Boater
- 2nd April 2018, 10:24
Hello [insert user name ],
You can disagree with someone's opinions, but calling that person an idiot or a profane name is a violation of our forum etiquette. Some forums are more liberal about this than others, but keeping it civil is never the wrong thing to do.

Posting the same thing over and over again is called scrolling, and is also a banning offense. It is annoying in the extreme and it is entirely unnecessary, please refrain from further activity of that nature or risk a ban from this forum.DATA sheets are your friend.
Please read the chips DATA sheet and make it happy :)You are in breach of the forums rules.

Your recent post [insert post ref] breached the rules because [insert reason]

This warning has been noted. We operate a three strike policy, however enforcement is at the admin / moderator discretion, in all respects our decision is final.

Further warnings will result in suspension of the service to you.Please start a thread in the appropriate forum for detailed technical help. This is just a chat box, your post will disappear quickly.We accept that the vast majority of our forum members follow general forum etiquette.

Forum etiquette means maintaining a standard of posting behavior that is acceptable and appropriate. Forum etiquette can be flexible, according to the subject of the forum, but there are certain standards most people expect others to maintain. Some lines must be drawn for the safety of all posting on the forum.

You may disagree with someone's opinions, but calling that person an idiot is a violation of forum etiquette.

Posting the same thing over and over again is called scrolling, and is also a violation of forum etiquette.

Trolls enjoy disturbing the peace. Trolls tend to call names, gossip about other posters, post things that are deliberately provocative and usually violate the forum's rules about posting. Don't become a Troll.

Another violation of forum etiquette is posting in ALL CAPS. This is considered shouting and is very rude.

Flaming, or deliberate insults or personal rants, are also against forum etiquette. Flaming is often employed by people who are losing arguments on a forum. Their response is to personally insult the poster disagreeing with them, usually in a long, nasty post. The veil of anonymity seems to bring out the worst in these people, and any bullying tendencies they have tend to become magnified in the semi-protection given by the anonymity provided on a forum.

Forum etiquette involves using the Golden Rule: treat others as you would like to be treated.

Behaving as a reasonable adult, even in the face of being flamed, is always the best course of action. If a poster becomes harassing, obscene or personal, do not retaliate. Instead, report it to the moderators or forum administrators.

Here we set out the basic rules that we use when managing the forum. By using the forum, you agree to abide by these rules and the decision of the administrators and moderators.

General Forum Use

Do NOT make the same post in multiple forums. Moderators will remove multiple posts and you will receive an infraction for doing so.
The User Infraction system is designed to automate the management of misbehaving users. When a user reaches pre-determined number of infractions, the user permissions may be restricted.
Members should post in a way that is respectful of other users. Flaming or abusing users in any way will not be tolerated and will lead to an infraction, followed by a BAN.
Members are asked to not act as “back seat moderators”. If members note an issue which contravenes something in this policy document they are welcome to bring it to the attention of a moderator.
Members should remember this board is aimed at a general audience. Posting pornographic or generally offensive text, images, links, etc. will not be tolerated and will lead to a BAN.
Members are asked to respect the copyright of other users, sites, media, etc. Users linking to or asking for information on warez, crackz, etc. or re-printing material without permission will receive an infraction and their post will be removed. Blatant abuse and links to warez may result in an instant BAN.
Members are asked only to post in English, as this is an English speaking community.
Members should post in a way which is consistent with "normal writing". That is users should not post excessive numbers of emoticons, large, small or coloured text, etc. Similarly users should not SHOUT by writing in upper case or use excessive punctuation (e.g. ! and ?) in topic titles or posts. Users consistently abusing this will receive an infraction.
Members should use an appropriate, descriptive subject when posting a new topic. Examples of bad subjects include; "Help me!", "I'm stuck!", "I've got an error!" etc.
Members are welcome to use the test forum for general "test purposes". These may include checking signatures, testing a link or image, etc. (subject to previous points on decency, warez, etc.).
Spam is not tolerated here under any circumstance. This includes offering hosting services (charged and free), installation services, solicitation etc. Users posting 'SPAM' will be banned.
The moderators may edit, remove or put on moderation queue any post at any time. Please note that currently any very first post by a new user is automatically placed in the moderation queue and will be approved/disapproved according to the present Rules. The determination of what is construed as indecent, vulgar, spam, etc. as noted in these points is up to the admins and moderators, NOT the users.
The above forum rules where applicable also apply to private messaging. Abuse of the private messaging system may lead to an infraction and/or the revocation of private messaging facilities.


Signatures

Signatures containing an image may also include one line of small size text.
Animated images are not allowed.
Links in signatures are permitted to a maximum of four unique pages or sites. Such links may only be to relevant or moderator approved material. Links to sites may be commercial in nature. You may not include links in a way which suggests you offer official support, software, etc. for Crownhill Products. You may not link to warez, porn, racist or other similar hate sites. Links are included in signature size limits.
Users abusing these rules will receive an infraction, their signature will be removed and repeated abuse will result in a BAN.


Policing

Arguing with moderators or admins after having received an infraction or warning will lead to an immediate additional infraction and ultimately a BAN.
Users who feel they have been unfairly warned may contact an admin with their complaint. The admin's decision is final.
Any attempt to circumvent a temporary ban or other moderator action will lead to a permanent ban of your account(s). Circumvention includes re-registering or using an already registered account under a non-banned username. Other examples include changing IP addresses, using a new email account or other action that can be taken to evade moderator action to hide your identity as the owner of the sanctioned account.
An exception to the three strike rule applies when users contact team members personally (via any method) and post insulting, indecent or vulgar material. Such users may be subject to an immediate permanent BAN.
Permanent bans are a last resort and thought is given before implementing them.

Boater
- 2nd April 2018, 10:30
It seems I went off Topic?

Mike, K8LH
- 6th May 2018, 13:33
It seems more intuitive (for me) to depict a Charlieplexed matrix in column and row format. If I take the matrix (below) and fold along the dotted line, so to speak, I end up with a matrix, like Demon's, which should support some relatively inexpensive 2-pin Red/Green LED's I have laying around, right?