Synchronizing 12x PCA9635 led drivers - i2c question

Pfrogs

Member
Hi all,

I am using a Picaxe 18M2 to control 12x PCA9635 led drivers that individually control 60x RGB LEDs.
For now, I managed to have it all working with the following code:

Code:
#Picaxe 18M2
setfreq m32

symbol R01 = b0
symbol G01 = b1
symbol B01 = b2
symbol R02 = b3
symbol G02 = b4
symbol B02 = b5
symbol R03 = b6
symbol G03 = b7
symbol B03 = b8
symbol R04 = b9
symbol G04 = b10
symbol B04 = b11
symbol R05 = b12
symbol G05 = b13
symbol B05 = b14
symbol Rall = b15 
symbol Gall = b16
symbol Ball = b17
symbol RGBpos = b18
symbol posInc = b19

Powerup:

low B.3 'set OE low - when OE low all LED are enabled and output state defined by LEDOUT register 
i2cslave %11100000, i2cfast_32, i2cbyte 'LED All Call address %1110 000x
writei2c ($00,$a1) 'write to register Mode1 - auto-inc enable, normal mode, respond LED all Call
writei2c ($01,$05) 'write to register Mode2 - Output change on STOP
writei2c ($d4,$aa,$aa,$aa,$2a) 'write to register LEDOUT0 to LEDOUT3 - controls LED0 to 16 - Turn all on, except 16 which is not used
writei2c ($a2,$ff,$00,$00,$ff,$00,$00,$ff,$00,$00,$ff,$00,$00,$ff,$00,$00)
pause 10000
writei2c ($a2,$00,$ff,$00,$00,$ff,$00,$00,$ff,$00,$00,$ff,$00,$00,$ff,$00)
pause 10000
writei2c ($a2,$00,$00,$ff,$00,$00,$ff,$00,$00,$ff,$00,$00,$ff,$00,$00,$ff)
pause 10000
writei2c ($a2,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff)
pause 40000


Options:
let RGBpos = 0 'start position for RGB lookup
let posInc = 4 'position increment for RGB lookup, i.e. color increment between each neighbour' LED


RGBwrite:
gosub RGBattrib
i2cslave %10000000, i2cfast_32, i2cbyte 'PCA9635 #01 address
writei2c ($a2,R01,G01,B01,R02,G02,B02,R03,G03,B03,R04,G04,B04,R05,G05,B05) 'write to register PWM00 to PWM15 - address is incremented by register Mode1
gosub RGBattrib
i2cslave %10000010, i2cfast_32, i2cbyte 'PCA9635 #02 address
writei2c ($a2,R01,G01,B01,R02,G02,B02,R03,G03,B03,R04,G04,B04,R05,G05,B05)
gosub RGBattrib
i2cslave %10000100, i2cfast_32, i2cbyte 'PCA9635 #03 address
writei2c ($a2,R01,G01,B01,R02,G02,B02,R03,G03,B03,R04,G04,B04,R05,G05,B05)
gosub RGBattrib
i2cslave %10001000, i2cfast_32, i2cbyte 'PCA9635 #04 address
writei2c ($a2,R01,G01,B01,R02,G02,B02,R03,G03,B03,R04,G04,B04,R05,G05,B05)
gosub RGBattrib
i2cslave %10000110, i2cfast_32, i2cbyte 'PCA9635 #05 address
writei2c ($a2,R01,G01,B01,R02,G02,B02,R03,G03,B03,R04,G04,B04,R05,G05,B05)
gosub RGBattrib
i2cslave %10001010, i2cfast_32, i2cbyte 'PCA9635 #06 address
writei2c ($a2,R01,G01,B01,R02,G02,B02,R03,G03,B03,R04,G04,B04,R05,G05,B05)
gosub RGBattrib
i2cslave %10001100, i2cfast_32, i2cbyte 'PCA9635 #07 address
writei2c ($a2,R01,G01,B01,R02,G02,B02,R03,G03,B03,R04,G04,B04,R05,G05,B05)
gosub RGBattrib
i2cslave %10001110, i2cfast_32, i2cbyte 'PCA9635 #08 address
writei2c ($a2,R01,G01,B01,R02,G02,B02,R03,G03,B03,R04,G04,B04,R05,G05,B05)
gosub RGBattrib
i2cslave %10100000, i2cfast_32, i2cbyte 'PCA9635 #09 address
writei2c ($a2,R01,G01,B01,R02,G02,B02,R03,G03,B03,R04,G04,B04,R05,G05,B05)
gosub RGBattrib
i2cslave %10100010, i2cfast_32, i2cbyte 'PCA9635 #10 address
writei2c ($a2,R01,G01,B01,R02,G02,B02,R03,G03,B03,R04,G04,B04,R05,G05,B05)
gosub RGBattrib
i2cslave %10100100, i2cfast_32, i2cbyte 'PCA9635 #11 address
writei2c ($a2,R01,G01,B01,R02,G02,B02,R03,G03,B03,R04,G04,B04,R05,G05,B05)
gosub RGBattrib
i2cslave %10101000, i2cfast_32, i2cbyte 'PCA9635 #12 address
writei2c ($a2,R01,G01,B01,R02,G02,B02,R03,G03,B03,R04,G04,B04,R05,G05,B05)
Goto RGBwrite

RGBattrib: 'attribute PWM value for each RGB LED - 5 RGB leds are controlled by each PCA9635
'LED01
gosub RGBData
R01=Rall
G01=Gall
B01=Ball
RGBpos = RGBpos + posInc
'LED02
gosub RGBData
R02=Rall
G02=Gall
B02=Ball
RGBpos = RGBpos + posInc
'LED03
gosub RGBData
R03=Rall
G03=Gall
B03=Ball
RGBpos = RGBpos + posInc
'LED04
gosub RGBData
R04=Rall
G04=Gall
B04=Ball
RGBpos = RGBpos + posInc
'LED05
gosub RGBData
R05=Rall
G05=Gall
B05=Ball
RGBpos = RGBpos + posInc
return

RGBData:'color wheel database
'Red data
LOOKUP RGBpos,(255,255,255,254,254,253,252,251,250,249,247,246,244,242,240,238,235,233,230,228,225,222,219,215,212,208,205,201,197,193,189,184,180,175,171,166,161,156,151,146,141,136,130,125,120,114,108,103,97,91,85,79,73,67,61,55,49,43,36,30,24,18,11,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,9,16,22,28,34,41,47,53,59,65,71,77,83,89,95,101,107,112,118,123,129,134,139,145,150,155,160,165,169,174,179,183,187,191,196,200,203,207,211,214,217,221,224,227,230,232,235,237,239,241,243,245,247,248,250,251,252,253,254,254,255,255,255), Rall
'Green data
LOOKUP RGBpos,(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,10,16,23,29,35,41,48,54,60,66,72,78,84,90,96,101,107,113,118,124,129,135,140,145,150,155,160,165,170,174,179,183,188,192,196,200,204,207,211,215,218,221,224,227,230,232,235,237,240,242,244,245,247,248,250,251,252,253,254,254,255,255,255,255,255,254,254,253,252,251,250,249,248,246,244,242,240,238,236,234,231,228,225,222,219,216,213,209,205,202,198,194,190,185,181,176,172,167,162,157,152,147,142,137,132,126,121,115,110,104,98,92,86,80,74,68,62,56,50,44,38,32,25,19,13,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), Gall
'Blue data
LOOKUP RGBpos,(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,11,17,23,30,36,42,48,54,60,67,73,79,84,90,96,102,108,113,119,124,130,135,141,146,151,156,161,166,170,175,179,184,188,192,196,200,204,208,211,215,218,221,224,227,230,233,235,238,240,242,244,246,247,249,250,251,252,253,254,254,255,255,255,255,255,254,254,253,252,251,250,249,247,246,244,242,240,238,236,233,231,228,225,222,219,216,212,209,205,201,197,193,189,185,180,176,171,167,162,157,152,147,142,136,131,126,120,115,109,103,97,92,86,80,74,68,62,56,49,43,37,31,25,18,12,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), Ball
return
To power-up I am using the AllLED address to light up all LEDs with each RGB color and end with all colors on, i.e. displaying a white color - in this case all the LEDs change color at the same time and in sync).
Then the code starts to lookup for RGB values for each individual LED in order to show a gradient of colors along the 60 RGB leds cycling the gradient of colors between LEDs, i.e. kinda of a color wheel that is spinning - in this case the LEDs's PWM register are updated sequencially one by one.

In the PCA9635 manual (www.nxp.com/documents/data_sheet/PCA9635.pdf), they state that PCA9635 can be synchronized with a STOP bit issued after all PCA's registers have been writen with their PWM value - see page 11, under Table 6, comment [2].

I have tried to set the MODE2 register to "Outputs change on STOP command" instead of the "Outputs change on ACK" option that I had when I started to work on this, but this does not alter anything. The LEDs are still changing colors one by one, sequencially.
My questions are:
- Does the writei2c issue a STOP command after each byte have been written or just after all bytes have been written within a "writei2c" command? My guess is that is after all bytes have been written, which would explain why the AllLED address allows to get a synchronized change of colors between all LEDs. However, if this would be true, than when addressing each individual PCA9635, all the 5x RGB LED that are controlled by each PCA9635 should at least be synchronized, but they are not..they change color one by one.:confused:

- Can anyone point me out on what can I change in this code to have it change all PCA drivers in sync while individually update which LED PWM register?

Thank you for your help.
Best regards,
Pfrogs
 
Top