From: Jan "Yenya" Kasprzak Date: Tue, 2 Jul 2013 10:06:26 +0000 (+0200) Subject: adc.c: sub-LSB resolution of PWM X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=bike-lights.git;a=commitdiff_plain;h=22f204ec3a908acbf879f36e2826eed281c5f2a6;hp=b34429defa04d493a49e24ad8840e42600bd0f28 adc.c: sub-LSB resolution of PWM Simulate a sub-LSB resolution inside the ADC IRQ handler. We do multiple measurements of PWMLED resistor anyway, so it makes sense to modify the PWM value after each reading. And indeed, experiments show less flicker of PWM LEDs with this patch. It is probably an overkill, and can be called only when measuring the PWMLED output (and not ambient light sensor, for example). But it works and it is simple enough. --- diff --git a/firmware/adc.c b/firmware/adc.c index 5ebc0a6..2bca0cf 100644 --- a/firmware/adc.c +++ b/firmware/adc.c @@ -238,6 +238,7 @@ ISR(ADC_vect) { // IRQ handler ADCSRA |= _BV(ADSC); adc_sum += adcval; read_count--; + pwm_timer(); return; }