Brightness auto adjusting to ambient light level

This is general talk area for things that NOT RELATED WITH TV! Instead, about internal works like web site, forum, wiki, or talking, etc...

tom_van
Official SamyGO Developer
Posts: 147
Joined: Tue Jan 19, 2010 10:44 am

Re: Brightness auto adjusting to ambient light level

Post by tom_van »

erdem_ua wrote:
If you look for any profi made boards with small ATmega (without light sensor etc...), you see prices around 20$.
What boards? I will build from bare chips. Don't buy such a kit. :) I think even no PCB is required for 2 piece.Could solder chips with wire will do the job :)
I mentioned it just for illustration where are prices of professionally build dongles. If you're gonna solder chips together, I wouldn't buy such crap even for 1$.
erdem_ua wrote:2. AFAIK, ATmega8u2 is BGA only.
Not BGA but TQFP, 0.8mm pitch. No problem if used on PCB.
I personally dislike softUSB. It might or might not work depending of precision of Xtals.
erdem_ua wrote:3. RS232/EXLink is good but don't know how to power unit. Trying to power from USB is not meaningfull. Might be possible to pull charge from ExLink interface to an ultracap. ATTiny consumes really low if it on sleep mode or on low frequency. Some programming trick will put sensor on sleep when doesn't on use and I guess that power might be efficient to run ATTiny at full speed on data sending but needed to test first...
Yes, it might work. I used ATmega48 because I hope that hw UART and sleeping CPU consume less power than sw UART on active CPU. But if you do not use Rx (I do just for debugging), soft UART will be ok. The capacitor for supply is nothing "ultra", just ordinary 47uF. And you have to solve one more problem you have not realized - polarity and RS232 levels.
User avatar
erdem_ua
SamyGO Admin
Posts: 3126
Joined: Thu Oct 01, 2009 6:02 am
Location: Istanbul, Turkey
Contact:

Re: Brightness auto adjusting to ambient light level

Post by erdem_ua »

tom_van wrote:I mentioned it just for illustration where are prices of professionally build dongles. If you're gonna solder chips together, I wouldn't buy such crap even for 1$.
Okey, could send just for you from $0.99 plus postage :)
tom_van wrote:I personally dislike softUSB. It might or might not work depending of precision of Xtals.
Xtal? What Xtall? Poormans doesn't have a Xtall. I am gonna use IntRC Osc with PLL :D
tom_van wrote:Yes, it might work. I used ATmega48 because I hope that hw UART and sleeping CPU consume less power than sw UART on active CPU. But if you do not use Rx (I do just for debugging), soft UART will be ok. The capacitor for supply is nothing "ultra", just ordinary 47uF. And you have to solve one more problem you have not realized - polarity and RS232 levels.
I thought it as TTL. Anyway I am gonna use USB :)
juuso wrote:Do not forget give us some detail schematic after you finish ;)
I will If I could draw it. At least I can draw by hand. :)

Today I couldn't find a photocell/phototransistor on local shop. Will buy it later. But I have the chip already. Trying to build soon. ETA next week :D
Stay tuned :)
tom_van
Official SamyGO Developer
Posts: 147
Joined: Tue Jan 19, 2010 10:44 am

Re: Brightness auto adjusting to ambient light level

Post by tom_van »

erdem_ua wrote:
tom_van wrote:I personally dislike softUSB. It might or might not work depending of precision of Xtals.
Xtal? What Xtall? Poormans doesn't have a Xtall. I am gonna use IntRC Osc with PLL :D
You made me to recheck softusb code on the net and YES, V-USB really implements soft pll and intRC tuning (OMG :roll: )
Ok, if you believe that absolutely minimal hw justifies your future work, go on. Wish you good luck.
I'm not gonna switch from my already working Ex-link sensor, but it seems you saved me work with publishing it. ;)
gooseye
Official SamyGO Developer
Posts: 132
Joined: Sat Dec 11, 2010 11:32 am

Re: Brightness auto adjusting to ambient light level

Post by gooseye »

tom_van wrote:I'm not gonna switch from my already working Ex-link sensor, but it seems you saved me work with publishing it. ;)
Shame about that Tom, I favour your simpler solution, especially if it can double up as RS232 level converter for debug. The only downside I see is having to set TV's serial to UART, and not debug, just in case of problems...
tom_van
Official SamyGO Developer
Posts: 147
Joined: Tue Jan 19, 2010 10:44 am

Re: Brightness auto adjusting to ambient light level

Post by tom_van »

gooseye wrote:Shame about that Tom, I favour your simpler solution, especially if it can double up as RS232 level converter for debug. The only downside I see is having to set TV's serial to UART, and not debug, just in case of problems...
Ex-link is already in RS232 levels, no need to convert voltages. UART stays in debug mode with my sensor box connected and debug output is available to connected PC all the time. The only annoyance is that you have to switch a jumper if you want enter debug menus or boot commands (or disconnect the sensor and connect Ex-link cable). The question is what solution is simpler: almost single chip with soft usb dependent on very precise timed program or more conservative solution with bigger AVR, 3 transistors and 4 diodes for RS232 levels converting.
As nobody wants to pay for "commercial grade" product, poor man's solution could be easier to build for an amateur.
User avatar
erdem_ua
SamyGO Admin
Posts: 3126
Joined: Thu Oct 01, 2009 6:02 am
Location: Istanbul, Turkey
Contact:

Re: Brightness auto adjusting to ambient light level

Post by erdem_ua »

Yup, you're right. Thanks for SamyGO Brightness Sensor idea tom_van.
Now I build my first v-usb device on breadboard. Just working as a hid device. Merging that with a photo-transistor viola! Unfortunately I don't have one photocell yet. Will bought soon. Until that I can emulate changing light intensity by feeding some numbers.. I will look around how can I choose PID/VID numbers for device...

Anyway, device uses HID device driver. And we have HID device drivers already on B series. I test it on TV and it recognized properly after loading required modules (evdev and usbhid)...
I also couldn't find where is the event file on TV.
It's structure is different. I found driver directory at /sys/class/input/input0 on TV.
it's different than my 2.6.39 kernel of course :) You can just use a joystick/gamepad or a keyboard for emulating the device...

Now we need a program that reads from HID device and adjust brightness for every X second..
Who want to handle that? juuso?
tom_van
Official SamyGO Developer
Posts: 147
Joined: Tue Jan 19, 2010 10:44 am

Re: Brightness auto adjusting to ambient light level

Post by tom_van »

Good progress, Erdem!
I think some stress testing of v-usb will be useful. Something like that: connect v-usb to a hub with a flash stick. Check if v-usb can communicate concurrently with playing high bit-rate video.

I've made some changes to LExxA956 firmware. Be warned that it is not applicable on other models, but may help anyway.
Backlight is the main parameter which have to be adjusted. I used VDH_SetEnergySave() call to set backlight but
the problem was that only 10 levels were available. Too rough steps for smooth and invisible adjusting.
I compensated steps by changes to brightness and contrast. Backlight changes were still visible although not annoying.

Code: Select all

long backlight, contrast, brightness;

int br_from_profile= 45;            // brightness value from profile    
int cn_from_profile= 75;            // contrast value from profile    
int bl_step_compensation_by_br= 4;  // lower brightness by this value to compensate +1 step in backlight    
int bl_step_compensation_by_cn= 4;  // lower contrast by this value to compensate +1 step in backlight    
float br_slope= 0.0f;               // change brightness with fl value  
float cn_slope= 1.5f;               // change contrast with fl value  

void AmbiLightOld(unsigned light)
{
  int blChanged;
  float fcn, fbr, fl;
  fl= ApproxByTable(delayPhotoRC, light);
  // fl is ambient light level converted to more or less linear value in range 0.0, 10.0 

  blChanged= fabs(fl - backlight) > 0.7f;
  if (blChanged) {
    // backlight lazy follows fl value
    backlight= lroundf(fl); 
  }
  if (backlight > 10) backlight= 10; 
  if (backlight < 0) backlight= 0; 

  //TODO: read profile values

  fbr= br_from_profile + (fl - backlight) * bl_step_compensation_by_br + (fl - 5.f) * br_slope;
  fcn= cn_from_profile + (fl - backlight) * bl_step_compensation_by_cn + (fl - 5.f) * cn_slope;
  
  if (fabs(fbr - brightness) > 0.8f) {
    brightness= lroundf(fbr);
    VDH_SetBrightness(brightness, 0);
  }     
  if (fabs(fcn - contrast) > 0.8f) {
    contrast= lroundf(fcn);
    VDH_SetContrast(contrast, 0);
  }     
  if (blChanged) {
    VDH_SetEnergySave(3, backlight);
  }
  printf("Ambient light %u (%f) %ld %ld %ld\n", light, fl, backlight, brightness, contrast);
} 
Today I dug into disassembly of VDH_SetEnergySave() and found that 10 steps are imposed by firmware
in underlying DevLDSetEnergySaving(). So if almost the lowest level is used, much smoother backlight control
is posible: 128 steps. The problem is that DevLDSetEnergySaving() is used only for LED local dimming models (A956, A756)
so the following will not work on A856:

Code: Select all

float bl_slope= -20.f;
float bl_intercept= 245.f;  

void AmbiLight(unsigned light)
{
  float fl;
  int blChanged;
  if (light==0) light= 1;
  fl= logf(light) * bl_slope + bl_intercept;
  if (fl > 127.99f) {
    fl= 127.99f;    
  }
  if (fabs(fl - backlight) > 9.f) {
    backlight= fl;  // fast change, skip direct to value 
    blChanged= 1;
  } else if (fl - backlight > 0.9f) {
    backlight++;    // increment lazily and smoothly 
    blChanged= 1;
  } else if (fl - backlight < -0.9f) {
    backlight--;    // decrement lazily and smoothly 
    blChanged= 1;
  }
  if (blChanged) {
    LockLocalDimming();
    LocalDimmingIICWrite(0x30, backlight);    
    UnlockLocalDimming();
  }    
  printf("Ambient light %u (%f) %ld\n", light, fl, backlight);
}
Procedure AmbiLight is called every second with a parameter sent from sensor. It is measured as time of RC charge, where R is a photoresistor.
I get ~100 at full sun, more than 50000 at darkness.

I also noticed a special setting for automatic backlight control in DevLDSetEnergySaving(). So there is probably an analogue input for auto-backlight
somewhere on mainboard but no sensor is connected to it. Argggh!

I continue testing.
User avatar
erdem_ua
SamyGO Admin
Posts: 3126
Joined: Thu Oct 01, 2009 6:02 am
Location: Istanbul, Turkey
Contact:

Re: Brightness auto adjusting to ambient light level

Post by erdem_ua »

Thanks for info but I don't want to dive B series disassemble again, at least yet.
And, please don't use "ambilight" term for ambient light sensor. Might be confusing for ambilight by philips for someone. Instead you might be wanted to use AutoBrightness that fits better.

Also I insist that we might place a true Ambilight Property. I think PVR code helps much. We just needed to find which colors are needed for actual frame. If CPU has juice for this, we could easily make a device to emulate ambilight with a USB device...
User avatar
erdem_ua
SamyGO Admin
Posts: 3126
Joined: Thu Oct 01, 2009 6:02 am
Location: Istanbul, Turkey
Contact:

Re: Brightness auto adjusting to ambient light level

Post by erdem_ua »

I have the device on my breadboard for a while, and also could easily convert it to PCB device, I don't know how to integrate it with B series exeDSP...:oops:
Any help appreciated...

Note: I am talking about this...
Image
sbav1
Official SamyGO Developer
Posts: 374
Joined: Fri Jan 15, 2010 10:20 am

Re: Brightness auto adjusting to ambient light level

Post by sbav1 »

erdem_ua wrote:Also I insist that we might place a true Ambilight Property. I think PVR code helps much. We just needed to find which colors are needed for actual frame. If CPU has juice for this, we could easily make a device to emulate ambilight with a USB device...
Quite interesting idea. May be not that easy to implement, though.
Getting current average picture brightness value is actually easy (TV is calculating it in hardware, in real time, for "Dynamic" mode / black control).
Average brightness (0x0 .. 0x3ff range) can be read from 0x302205A8 register; 0x302205AC register is holding another possibly interesting mean value (contrast related, histogram derivative ?).
See uldDp_RunBlackControl() for details.

Sadly, average R/G/B values do not seem to be available this way. Perhaps they can be calculated from DP[023] memory regions (I think current screen content may be readable from there, although video data is stored in some weird, non-trivial format). But I rather doubt such calculations can be performed in real time.

One thing's for certain: poor's man (monochromatic) "ambilight" is totally doable :)

Post Reply

Return to “General”