Arduino with TLC5940

I seem to be having a problem where some of the channels on my TLC5940 are not working in that they fail to light up a led.

I have checked the LEDs and there is nothing wrong with them.

I have also noticed that if I have a Serial.println("....") call in the loop() function it seems to interfere with the TLC5940 some how and cause some of the channels to not work. Removing the call seemed to allow some of the previously not working channels to light up the LEDs.

Repeated calls to TLC.clear() in the loop function also seemed to have a similar effect, but I removed those calls and did a Tlc.set(nLastLed, 0) sort of thing instead.

But there still seems to be channels that don't work if I just activate single channels at a time in the loop() function.

Is there a problem with my TLC5940 or are there, for instances, any know problems with this function in the library that causes some channels not to work:

/** Sets channel to value in the grayscale data array, #tlc_GSData.
    \param channel (0 to #NUM_TLCS * 16 - 1).  OUT0 of the first TLC is
           channel 0, OUT0 of the next TLC is channel 16, etc.
    \param value (0-4095).  The grayscale value, 4095 is maximum.
    \see get */
void Tlc5940::set(TLC_CHANNEL_TYPE channel, uint16_t value)
{
    TLC_CHANNEL_TYPE index8 = (NUM_TLCS * 16 - 1) - channel;
    uint8_t *index12p = tlc_GSData + ((((uint16_t)index8) * 3) >> 1);
    if (index8 & 1) { // starts in the middle
                      // first 4 bits intact | 4 top bits of value
        *index12p = (*index12p & 0xF0) | (value >> 8);
                      // 8 lower bits of value
        *(++index12p) = value & 0xFF;
    } else { // starts clean
                      // 8 upper bits of value
        *(index12p++) = value >> 4;
                      // 4 lower bits of value | last 4 bits intact
        *index12p = ((uint8_t)(value << 4)) | (*index12p & 0xF);
    }
}

I don't see a loop function there.

Read this before posting a programming question

It is not really a programming question as defined at the top of that section Nick, i.e. t is not a question about syntax and compiler errors etc.

It is more about the use of a specific LED driver IC and arduino libraries associated with it.

Hence why I put it in here.

There is a loop function but my query was about how the above function compacts 16 bit values down into 12 bit values that the TLC5940 expects for grey scale values.

I just wondered if there was an known issue in this library of some grey scale values being lost in the compaction process.

But after some fiddling around with my bread board I believe I am having an issue with current draw of 12 LEDs plus 2 x TLC5940 from 4 x 1.2V NiMH batteries that is leading to a drop in supply voltage that is in turn causing some instability with the operation of the TLC5940s. This time some of the LEDs were flickering and I noticed that my little battery pack and dropped off in voltage.

I have swapped to a 5V/800mA wall plug and the flickering has disappeared although some of the first of two TLC5940 channels still don't work.

Possibly a faulty or damaged TLC5940.

boylesg:
There is a loop function but my query was about how the above function compacts 16 bit values down into 12 bit values that the TLC5940 expects for grey scale values.

I just wondered if there was an known issue in this library of some grey scale values being lost in the compaction process.

Thousands of people use that library every day. I've used it myself. It's not a problem with that function, it's most likely a problem with the way you're using it. Which is why you were asked to show your loop() function. Your setup() function is probably worth showing as well.

Is it a hardware problem? The easy way to find out is to run one of the demos supplied with that library, eg. "BasicUse".

boylesg:
It is not really a programming question as defined at the top of that section Nick, i.e. t is not a question about syntax and compiler errors etc.

Nevertheless:

I have also noticed that if I have a Serial.println("....") call in the loop() function it seems to interfere with the TLC5940 some how and cause some of the channels to not work.

Describing code never quite reaches the same level of information as posting it. For example, are interrupts off?

We are happy to help with programming problems over and above mere syntax errors.

fungus:

boylesg:
There is a loop function but my query was about how the above function compacts 16 bit values down into 12 bit values that the TLC5940 expects for grey scale values.

I just wondered if there was an known issue in this library of some grey scale values being lost in the compaction process.

Thousands of people use that library every day. I've used it myself. It's not a problem with that function, it's most likely a problem with the way you're using it. Which is why you were asked to show your loop() function. Your setup() function is probably worth showing as well.

Is it a hardware problem? The easy way to find out is to run one of the demos supplied with that library, eg. "BasicUse".

Well here is my loop() function any how:

I have just been trying different methods of updating the LEDS.

void loop()
{
/*
  Tlc.set(4,    );
  Tlc.update();
*/
/*  
  static int nLED = 0;
  static int nLastLED = 0;
  
  //Tlc.clear();
  Tlc.set(nLastLED, 0);
  nLastLED = nLED;
  Tlc.set(nLED, 4095);
  Tlc.update();
  if (nLED == 16)
    nLED = 0;
   else
     nLED++;
  delay(500);

  //Serial.println("in function loop()......");
*/
  tlc_setGSfromProgmem(arrayGSVals);
  Tlc.update();
}