atmega8 algoritm corrected