Go Down

Topic: Tlc5940 multiplexing code (Read 5045 times) previous topic - next topic

elemeno


Quote
'm left with D5 and D13 pins open

Not quite follow what you are saying, sorry.


Sorry for being unclear. With everything wired up as per the 4x4 schematic all the digital pins are used except D5 and D13, so I figure I can use those to control FETs #5 and #6, but I'm not sure where to hookup FET #7.

Grumpy_Mike

Oh I see, yes you can use these to control other FETs and also use the analogue pins to control others.
A better way would be to use a 74LS42 as in this project http://www.thebox.myzen.co.uk/Hardware/Econo_Monome.html to drive more FETs with fewer lines.

elemeno


Oh I see, yes you can use these to control other FETs and also use the analogue pins to control others.
A better way would be to use a 74LS42 as in this project http://www.thebox.myzen.co.uk/Hardware/Econo_Monome.html to drive more FETs with fewer lines.


An in doing so, I figure i'd need to change the line in TLC5940Multiplex.cpp:

Code: [Select]
static int8_t rowPin[4] = {8, 2, 11, 7};   // pins to enable or turn on each row, low = on
to
Code: [Select]
static int8_t rowPin[7] = {8, 2, 11, 7, 5, 13, 16};   // pins to enable or turn on each row, low = on

Did I do that right and is there anything else I'd need to update?

Grumpy_Mike

That looks OK, did you also set the pin mode to output for the extra pins?

elemeno


That looks OK, did you also set the pin mode to output for the extra pins?


I'm trying to but am a little confused.

If I put pinMode(A0, OUTPUT); into TLC5940Multiplex.cpp I get an error like
Code: [Select]
'A0' was not declared in this scope

I also tried it in void setup within Arduinome_4x4_RGB.pde but I still have the same row and columns not lighting up.

Lastly, I noticed this in TLC5940Multiplex.cpp
Code: [Select]
// iniilise multiplex row selects and turn them all off (off = 1 as we have a P channel FET)
    for (i = 0; i<4; i++){

I tried changing the 4 to 7, but then just one column lit up.

Grumpy_Mike

You already have:-
Quote
static int8_t rowPin[7] = {8, 2, 11, 7, 5, 13, 16};   // pins to enable or turn on each row, low = on

Which is using the A2 pin (that's the 16) so all you have to do is to use:-
pinMode(16, OUTPUT);

elemeno


You already have:-
Quote
static int8_t rowPin[7] = {8, 2, 11, 7, 5, 13, 16};   // pins to enable or turn on each row, low = on

Which is using the A2 pin (that's the 16) so all you have to do is to use:-
pinMode(16, OUTPUT);


I did this in void setup() in Arduinome_4x4_RGB.pde but I'm not getting output for pin A2 or D13. From looking at the code it seems it's only setup for 4x4 RGB (48 LEDs), but my setup is now 7x7 (147 LEDs). I took several passes trying to scale the code for 7x7 but had no luck.

Do you have the code you used for your 8x8 project available online?

Grumpy_Mike

Yes it is the library code you have to hack as well. Unfortunately the 8X8 monome is a different arrangement and so the code won't help you. I have never done more than a 4:1 multiplex on the TLC9540.
What you have to do is to increase the count before you wrap round. At the moment this is done with an increment and an AND with 3 instruction. That will only work for multiplex lines that are powers of two. You need to do something like:-
index++;
if(index >= 7) index=0;

elemeno

#38
Jun 19, 2011, 09:25 pm Last Edit: Jun 19, 2011, 10:04 pm by elemeno Reason: 1

Yes it is the library code you have to hack as well. Unfortunately the 8X8 monome is a different arrangement and so the code won't help you. I have never done more than a 4:1 multiplex on the TLC9540.
What you have to do is to increase the count before you wrap round. At the moment this is done with an increment and an AND with 3 instruction. That will only work for multiplex lines that are powers of two. You need to do something like:-
index++;
if(index >= 7) index=0;


Okay, I'm going to try to take it slow and do as much research on my own as to not drive you crazy while I figure this out.  :)

A couple of questions to help get me going though..

1) Are there any resources/documentation on multiplexing in general or this driver that I can reference?

2) I'm trying to wrap my head around the LED buffer code. If I read the comment correctly, each LED is 12 bits (0-4095) and each hex number is 1 byte (8 bits). Does this mean that each led 'shares' a byte with its neighbor? Also, what does 'bb', 'bg', 'gg' etc refer to? I figure this is some simple math thing

Code: [Select]
* Each value is 12 bits (0-4095).  24 bytes is 192 bits, which is 16 led's * 12 bits each.  Each of the numbers in the array below is 1 byte (0-255).
*    For example,
*
*  | 1st byte | 2nd byte | 3rd byte | 4th byte | 5th byte | 6th byte | ...
*  | LED 16 value   | LED 15 value  | LED 14 value   | LED 13 value  | ...
*/

// Change this array initilisation to get a diffrent switch on pattern

static uint8_t ledBuffer[] = {
// row 1 (botom)
  //     lower LEDs not used        bb    bg    gg    rr    rb    bb    gg    gr    rr    bb    bg    gg     rr    rb    bb      gg    gr    rr
// row 2
   0x0, 0x0, 0x0, 0x0, 0x0, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,  0x40, 0x00, 0x00,   0x00, 0x04, 0x00, // red row



Also, this doesn't work yet, but do you mean something like this?
Code: [Select]
    scanindex++;
    if (scanindex >=7) {
        scanindex=0;
    }
   
    scan = (scanindex) & 3; // Increment row count
    bRow = pBuffer[scan];   // point at next row in the bufer precalculated to save time

Grumpy_Mike

Quote
Also, what does 'bb', 'bg', 'gg' etc refer to?


that is the distribution of bits in the array and so is the answer to your second question
so in the blue (b) is defined by the first two nibbles (4 bits is a nibble two nibbles in a byte) of the first byte and the most significant nibble of the second byte. That second byte has it's least significant nibble as the most significant nibble of the green brightness with the two lease significant nibbles in the third byte.
so in binary you have
bbbb bbbb  - bbbb gggg       - gggg gggg
First byte --- second byte  ---- third byte
This puts together two 12 bit numbers in three bytes.

Code: [Select]
scan = (scanindex) & 3; // Increment row count
This is the bit you have to remove as that constrains scan to a number between 0 and 3

elemeno

Some good news and a question.

After tinkering all day I finally 'got it' and was able to scale and layout a new ledBuffer. The trouble was that I was only getting the last 4 rows to light up. After some trial and error I found if I comment out the code to get the state of the push-buttons, the rest of the rows turn on as expected. I don't  have buttons on my project. Do you know why that bit of code would interfere?

Here's the code I commented out:
Code: [Select]
// read the state of the push buttons
    for(uint8_t i = 0 ; i<multiplexColoums; i++){
        buttonPressed[i][scan] = digitalRead(switchInput[i]);
    }


Full code:
Modified driver: http://pastebin.com/HQa1mWvb
Modified sketch: http://pastebin.com/zXKJjJ8P

Grumpy_Mike

Well done for getting it, my Wife looked at my last post and said "that is just rubbish!"

It looks like you hadn't expanded the keyboard buffer to take the extra non existent keys and that was over writing your LED buffer.

Go Up