## Linear intensity !

16 posts / 0 new
Author
Message

Dea freinds
I have used a 8 bit pwm wave to control the intensity of 128 leds! using my spartan device!( i have used 74xx buffers).but the problem is that the led intensities are not linear respect to the 8 bit value.Is there a solution for the problem?

Any ideas are welcome :idea:

I love Digital
and you who involved in it!

lookup table?

Linear in respect to what? Your perceived intensity? In which case remember the human eye is not linear!

It's logarithmic, like hearing.

Leon Heller G1HSM

The light intensity from a LED is very linear to its current. We have done a lot of tests with this for current measuring on the high side of a 4000V power supply, and we only had to do gain and offset compensation. The same was seen when we did a ~2 inch separation optocoupler.

A more complicating problem is aging. The LEDs loose intensity quite fast over the hours. If you want them stable you need to age them. Let them run for 2-3 weeks and they should be a lot more stable. Some LEDs are a little less sensitive to aging.

But intensity and perceived intensity are not the same! and I guess Ali wants visually linear dimming! So he needs to implement gamma correction!

This Maxim appnote might be useful: http://www.maxim-ic.com/app-notes/index.mvp/id/3667!

Yes, but since the LEDs are linear he should focus on the human eye model for light perception.

So something logarithmic.

and to accomplish that, he's going to need more than an 8 bit PWM if he wants to have 8 bits of intensity.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

He did say he was using a Spartan programmable logic chip, so he should not be limited to a 8-bit PWM. It's pretty easy to switch a 8-bit peripheral core to a 10 or 16 bits PWM.

yeah, was just pointing it out. IIRC the bare minimum is 12bits.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

Guys thanks for your replies.
there is another question.
can you suggest a better solution? dose 12bit pwm solve the problem? how should i connect the 8 bit data to 12bit pwm module? what is the bit order? can you give me a hint on led driver circuit? remember i need things to be as cheap as possible.

I love Digital
and you who involved in it!

It is not a simple mapping, you need to calculate the 12bit value from the 8 bit one. [or look it up from a pre-calculated table] The relationship is logarithmic. Do as suggested earlier, study on the human eye model.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

8-bit data in, 12-bit lookup table with 256 entries.

You could use PPM or PWM modulation, whatever is easier for you - same duty cycle. Drive the LED via resistor.

But the real question is, do you really need 256 different intensities? Are you able to see the difference between two of them? Would 16 intensities suffice to create 8-bit logarithmic PWM values?

Quote:
8-bit data in, 12-bit lookup table with 256 entries.

Hi Jespael.
can you explain it more to me.And in fact i need the 8bit intensities.

I love Digital
and you who involved in it!

Let me explain in pseudocode:

```uint16_t LEDLUT[256];

for (uint8_t i=0; i<=255; i++)
LEDLUT[i]=exp_something_curve(i);

later on:
intensity=42; // 0..255 = linear intensity
PWMVALUE=LEDLUT[intensity]; // convert to 12 or 16-bit pwm value
```

Point being, when you use 8-bit linear values for PWM, you see big difference between 0 and 1 or 1 and 2, but you don't see any difference between 254 and 255. So you must make a lookup table so, that in the low end, lut[0]=0 and lut[1]=1, but in the high end, the values may be lut[255]=4000 and lut[254]=3500, i.e. bigger spacing.

Thanks for your reply.but the problem is how to calculate the table data.do you have any suggestion.

thanks for your time.

I love Digital
and you who involved in it!