16bit gamma correction on Teensy not working as expected

Status
Not open for further replies.

Robbert

Active member
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-tricks-gamma-correction/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
  }
 
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
 
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 "&".
 
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.
 
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
 
Status
Not open for further replies.
Back
Top