TLC5940 library and individual dot correction control

I'm using a Mega and the TLC5940 library by AC (Arduino Tlc5940 Library: Tlc5940 Class Reference).

The library works great. I can control PWM (called GS or grey scale mode) of each LED individually and I can control current (called dot correction or DC mode) of all LEDs together using the library functions. I want to be able to control the DC of each channel individually. After a ton of searching I haven't found any references in the library or on the web to this functionality. I've not done any library development before, so I fear this may be a bit out of my league. I'd really appreciate any advice, code snippets or words of warning on this.

Because the setAllDC function is almost what I want (but I need control over each individual channel), my plan would be to duplicate the setAll function but using the setAllDC format (and create a new data array like tlc_GSData, probably called tlc_DCData).

Any thoughts? Has anyone tried this already?

It turns out there is a function in the library to set the dot correction (DC) from progmem: tlc_setDCfromProgmem, which operates much like Tlc.setAllDC but allows setting of the dot correction values (0-63) for each LED channel. This seems very close to what I want. Thanks (again) to Alex for pointing this out. Alas, there are two problems:

  1. Tlc.setAllDC and tlc_setDCfromProgmem give different behavior for the same inputs. Weird. I think Tlc.setAllDC is right.
  2. The DC behavior is lost as soon as a GS call (like Tlc.setAll followed by Tlc.update) is made. The data sheet says that the DC data should stick, so I'm wondering what the problem could be. Perhaps the latch pulse isn't firing at the right time?

Here's some of the early behavior. This first one sets the DC to a very low intensity level, but the LEDs turn back on to full brightness after about 2 seconds, presumably when the Tlc.update gets called:

  Tlc.init(0);
  Tlc.update();
  delay(100);
  Tlc.setAllDC(1);     // this gives all off for 0, and all very dim for 1
  delay(2000);
  Tlc.setAll(4095);
  Tlc.update();     // at this update the DC information is lost

If I change the input to the Tlc.setAllDC(1) from 1 to 0 the LEDs are completely off, as expected. The problem here is that the GS call (Tlc.setAll and Tlc.update) appears to wipe out the DC information set earlier.

Here's a 2nd version using tlc_setDCfromProgmem. This has the same behavior as above (GS commands wiping out the DC commands) but also all of the LEDs are much brighter for DC setting of 1 (out of a max of 63) and the LEDs are still on even when the DC value is set to 0:

const prog_uint8_t iDC = 0;

prog_uint8_t dcArray1[NUM_TLCS * 12] = {
	DC_QUARTET(iDC, iDC, iDC, iDC), DC_QUARTET(iDC, iDC, iDC, iDC),
	DC_QUARTET(iDC, iDC, iDC, iDC), DC_QUARTET(iDC, iDC, iDC, iDC),
};

void setup()
{
  Tlc.init(0);
  Tlc.update();
  delay(100);
  tlc_setDCfromProgmem(dcArray1);     // this does NOT give all off for 0, fairly bright for 1
  delay(2000);
  Tlc.setAll(4095);
  Tlc.update();     // at this update the DC information is lost
}

I'm a bit out of my depth working inside of the library, but I need to figure this out. If anyone has any suggestions, tips or resources, I would appreciate a push in the right direction.