Which AVR chip you are using? If it supports clear-on-compare match you just need to setup your timer to use this feature, after that timer will automatically take care of toggaling the output line at required frequencey and you can use the processor for doing some other work. (ATMEAG128 has this feature)