Andy4495 / TLC591x

Library for Texas Instruments TLC5916 and TLC5917 constant current LED sink driver for Arduino.
MIT License
14 stars 3 forks source link

How to control individual LEDS intensity? #7

Closed BioEngLuisPereira closed 9 months ago

BioEngLuisPereira commented 9 months ago

Hi Great library! But I'm having dificulty figuring out how to control a LED intensity without turning the other Off. All I want is to be able to have and LED at 50% for example and another at 75%, but every time I change an LED intensity, the other turn off. For example, trying to have OUT0 and OUT1 On, but with different intensities, in a single TLC5917:


//Setting an intensity on OUT0:
  myLED.normalMode();
  n[0] = 0x80;
  myLED.print(n[0]);
  delay(5000);
  myLED.specialMode();
  Bright[0] = 0xff;
  myLED.specialMode();
  Bright[0] = 0xff;
  myLED.printDirect(Bright);
  myLED.normalMode();

//Now setting an intensity on OUT1:
  n[0] = 0x60;
  myLED.print(n[0]);
  delay(5000);
  myLED.specialMode();
  Bright[0] = 0xff;
  myLED.specialMode();
  Bright[0] = 0xcc;
  myLED.printDirect(Bright);
  myLED.printDirect(Bright);
  myLED.normalMode();

//Now only LED OUT1 is ON =\

Either I got the datasheet wrong or I'm missing something here.

Hopefully its something simple.

Thank you.

Cheers, Luís Pereira.

Andy4495 commented 9 months ago

I don't have my test setup available at the moment, but if I had to guess, the problem might come from calling specialMode() while the chip is already in Special Mode.

The chip has specific timing requirements to get into and out of Special Mode, so the calling sequence that you are using might be inadvertently putting the chip back in Normal Mode before you call printDirect().

In other words, change your code to the following and see if that fixes the problem:


//Setting an intensity on OUT0:
  myLED.normalMode();
  n[0] = 0x80;
  myLED.print(n[0]);
  delay(5000);
  myLED.specialMode();
  Bright[0] = 0xff;
  // myLED.specialMode();   // Not needed
  // Bright[0] = 0xff;      // Not needed
  myLED.printDirect(Bright);
  myLED.normalMode();

//Now setting an intensity on OUT1:
  n[0] = 0x60;
  myLED.print(n[0]);
  delay(5000);
  // myLED.specialMode(); // Not needed
  // Bright[0] = 0xff;    // Not needed
  myLED.specialMode();
  Bright[0] = 0xcc;
  // myLED.printDirect(Bright); // Not needed
  myLED.printDirect(Bright);
  myLED.normalMode();

//Now only LED OUT1 is ON =\

If you send your complete test sketch and a drawing of your hardware connections/schematic, I can get my setup running tomorrow and take a closer look.

Also, I might be misunderstanding your question: are you trying to have two different intensities on different LEDs connected to the same chip at the same time?

Andy

BioEngLuisPereira commented 9 months ago

Hi Andy

Thank you for your quick answer. Yes thats correct, I want two different intensities on different LEDs connected to the same chip at the same time. At this point I'm pretty sure It cannot be done in this chip. I'm ordering something more like TLC5947 (and its family TLC5940 and TLC5941), those according to the datasheet can control LED's PWM independently.

I just tried your code and it also turns OFF the OUT0 and on the moment it turns ON the OUT1 . If you really think the TLC5917 should be able to do idependent PWM on different LED's on the same IC, I'll send you the schematic and code - otherwise no sense in spending more of your time.

Again, thank you.

Cheers, Luís Pereira.

Andy4495 commented 9 months ago

Yes, the TLC5917 only has a single intensity setting for all LEDs connected to the same chip. The '5947 should support what you are trying to do.