Which hardware timer should I use for my library

I'm working on a new communications library, for this I need access to one or two hardware timer interrupts, with a speed of at least 20 kHz. I plan on making this library available on the playground, after I'm reasonably satisfied with its performance.

Which hardware timer should I use to make sure the library play well with most of the other libraries?

TMR0, TMR1, or TMR2 depending upon a variety of factors for which you have not provided remotely enough information to narrow the choices.

Which hardware timer should I use to make sure the library play well with most of the other libraries

That one is easy, let the user decide which timer to use and provide a suitable default.

pYro_65:
That one is easy, let the user decide which timer to use and provide a suitable default.

Sounds like a good idea,which one would be a reasonable default? :wink:

wanderson:
TMR0, TMR1, or TMR2 depending upon a variety of factors for which you have not provided remotely enough information to narrow the choices.

Ok, the basic idea is to implement a duplex communications library. There is one rx and one tx line. The data would be send out manchester encoded at a speed selectable by the user. In general the speed would be between 1kBaud and 20kBaud. I want this to be a general purpose library, so the rx and tx pin should be freely assignable and not tied to INT0, INT1 or any of the OCnx pins. The timer would be used to both sample the rx pin and set the tx pin. From the programming requirements, any timer would work.

I will probably first prototype this on an Atmega32u4, since I like having the direct USB connection, but I want to make this available as an arduino library, and I was wondering if there are any conventions, which timers should be used by addon libraries (e.g. "TMR0 is used by the milis() function, don't use that one" or "the servo library already uses TMR2",...)

[quote author=No Such Nick link=topic=116985.msg881119#msg881119 date=1343997239]I will probably first prototype this on an Atmega32u4, since I like having the direct USB connection, but I want to make this available as an arduino library, and I was wondering if there are any conventions, which timers should be used by addon libraries (e.g. "TMR0 is used by the milis() function, don't use that one" or "the servo library already uses TMR2",...)
[/quote]

The 32u4 doesn't have a timer2... a great reason why it would be nice to let the user decide which timer to use.

I believe the use of any of the timers will affect some functionality of the Arduino environment. As you said TMR0 affects millis(), while TMR1 and TMR2 are usually used for PWM (analogWrite) functionality among other things. I like the idea of letting the user decide which to use.