Go Down

Topic: Which hardware timer should I use for my library (Read 775 times) previous topic - next topic

No Such Nick

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?

wanderson

TMR0, TMR1, or TMR2 depending upon a variety of factors for which you have not provided remotely enough information to narrow the choices.
New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

pYro_65

Quote
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.

No Such Nick


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? ;)


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",...)

Steph

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",...)


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

wanderson


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",...)


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.
New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

Go Up