I'm trying to get the ADC on an ATtiny13 (@1MHz) working with the timer triggering a conversion every 1/25 sec (i.e. 25 conversions per second).
What I have:
Timer0 in CTC mode, prescaler 1024
top value set to 40 (1024/41=25)
interrupt "output compare a" activated
ADC using Vcc as reference, value right-adjusted, ADC1 used
AD-Conversion enabled, interrupt on conversion end enabled, prescaler 8 (1MHz/8=125kHz)
Conversion start on above interrupt
In the current AVR Studio Simulator, the counter does run, the output compare interrupt does fire but a conversion doesn't start. If I manually start a conversion by setting the ADSC bit (ADCSRA bit 6), it does convert, it does fire the "conversion finished" interrupt and it does return to the main loop.
So I guess there is a bit set to the wrong value in the above registers and I can't find it. Can anyone help me here with this?
I'm trying to build a light barrier using a photoresistor, pulsed for ambient light compensation. The photoresistor is fast enough (says the datasheet), it'll be a reflecting light barrier (photoresistor and IR-LED on one side, a reflector on the other one).
First, the LED is switched on, the photoresistor gets its time to set the voltage right (approx. 40ms), the brightness is measured and compared to the internal "1" value. Then, the LED is switched off, the photoresistor gets time again, again measurement and comparison to the internal "0" value. On each measure, the "1" or "0" value (depending on the LED being on or off) is adjusted by 4 into the right direction. So adaption to ambient light can take up to 10 seconds. This will be tweaked to a shorter time (without misfiring) as soon as it's running on hardware.
Thanks a lot for any hints!