On Mon, 1 Nov 2004 brusque@HotPOP.com wrote: > Something like R=500/lux (for R in kOhms). How about turning it around in hardware so you don't need inaccurate math: use the a/d as a null detector and feed the ldr with a variable dc voltage from the pwm output through the 4k7 (change to 1k) and a suitable RC filter. Then you can measure lux directly. Uldr = Ildr * Rldr = Ildr * 500 / lux lux = Ildr * 500 / Uldr = (Upwm - Uref) * 500 / Uref Uref constant and make 500->512 for better karma ;-) You measure Uldr using the a/d or a comparator and adjust pwm duty cycle until it is Uref. Then you know Upwm. Lux are linear to Upwm if your initial assumption is correct. Peter _______________________________________________ http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist