Working with Timers - which ones are free?

Guys, for the Arduino Atmega328 based boards, which timers can I use safely? I see that Micros() and Millis() uses Timer0, right? So am I ok to assume that Timer2 is free (8-bit) and also what about the 16-bit timer? (What's the name of it?)

I looked at the Data-Sheet, but couldn't figure out the actual names of each timer. But I did find the info on the Tone file included with the Arduino IDE. (under Hardware)

I wonder if the 16 bit timer could be used to produce better audio output using a single pin? Or I'm just dreaming? ;-)

Best Regards, WilliamK

As you stated timer0 is used for the various time functions provided by the arduino core libary. Timer0 also supports two of the pwm output pins used in analogWrite() statements. The other two timers on a 328 based board support 2 each of pwm output pins again used in analogWrite statements. So as long as you don't require use of the analogWrite commands for specific pins you are free to use timers1 & 2 as you see fit.

As far as getting better sound out of a arduino, you might want to check out a new library that was developed and posted recently. I don't think you can do much better without the help of external components.

http://arduino.cc/forum/index.php/topic,51462.msg367203.html#msg367203

Lefty

Thanks.

BTW: that lib uses timers 2 to 6, so its only Arduino Mega compatible. :(

I wonder if the 16 bit timer could be used to produce better audio output using a single pin? Or I’m just dreaming? :wink:

The bitness of the timer doesn’t matter much. It’s unlikely a human would be able to tell the difference.

Directly driving the output pins does matter. There is audible “noise” when using an interrupt service routine; especially when the processor speed is 8 MHz or below. The tone function in this core enables direct output when possible and the sound quality is noticeably better…

http://code.google.com/p/arduino-tiny/

If you have trouble getting it to work on a 328 processor, let me know.

WilliamK: Thanks.

BTW: that lib uses timers 2 to 6, so its only Arduino Mega compatible. :(

If you read the authors link you find that his library is processor model aware and will only assign the number of timers avalible on the chip, so it will still function, just with fewer monotone channel outputs.

Lefty