Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: 16bit gamma correction on Teensy not working as expected

  1. #1
    Junior Member
    Join Date
    Dec 2018
    Posts
    5

    16bit gamma correction on Teensy not working as expected

    So I'm running an installation with a Teensy 3.5 controlling 10 TLC59711 LED drivers.
    I've been wanting to implement some gamma correction for the LEDs (as described in this article by Adafruit https://learn.adafruit.com/led-trick.../the-quick-fix). And used the processing sketch they distribute to generate a table for 16-bit LED gamma correction. The generated table seems fine but implementing seems a little odd. The LEDs are flickering and Serial.print also confirms odd values (even above the ones that are IN the array). The table is set in PROGREM memory, as Adafruit recommends in their article.

    Hope someone can help me figure out why this is happening, and how to fix it

    Code is available on Github to give a little more context, as the whole is a little to much to post here.
    https://github.com/RobbertGroenendijk/echo_1

    Code:
    for (int i = 0; i < NUM_LIGHTS; i++) {
        lightArray[i].loop();
        tlc.setPWM(i,int(&gamma16[int(lightArray[i].brightness)])); // GAMMA CORRECTION
      }

  2. #2
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    193
    Are you sure about that "&gamma16[...]" instead of "gamma16[...]" ?

  3. #3
    In the Adafruit article, they are using a PROGMEM array (const uint8_t PROGMEM gamma8[] = {...), therefore it must be referenced as such:
    Code:
    strip.setPixelColor(pixelNumber,
      pgm_read_byte(&gamma8[red]),
      pgm_read_byte(&gamma8[green]),
      pgm_read_byte(&gamma8[blue]));
    However, with the Teensy you would normally simply declare it as a normal array (const uint8_t gamma8[] = {...), and reference it like this:
    Code:
    strip.setPixelColor(pixelNumber,
      gamma8[red],
      gamma8[green],
      gamma8[blue]);
    Marc

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,169
    Teensy does support using pgm_read_byte(), so you can (usually) run code written for AVR and have it "just work".

    If you remove the (unnecessary on Teensy) pgm_read_byte, you also need to remove the extra "&".

  5. #5
    Junior Member
    Join Date
    Dec 2018
    Posts
    5
    I've declared it in the code with the PROGREM keyword. Does that mean the Teensy doesn't store it in PROGREM memory anyway? Because taking away the & actually fixed it now... Kind of overlooked that I guess.

  6. #6
    I just had to check for myself - indeed PROGMEM doesn't do anything on the Teensy:
    Code:
    #define PROGMEM
    , and pgm_read_byte() is simply doing a reference cast to make it compatible with Arduino:
    Code:
    #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
    Declaring strings & arrays with PROGMEM is normally done to save memory, which is more of a problem on legacy AVR stuff that it is on the Teensy - even the LC has 3-4 time the ram of a Leonardo

    Marc

  7. #7
    Junior Member
    Join Date
    Dec 2018
    Posts
    5
    Thanks everyone for the replies.
    Fixed the problem and learned something again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •