Pages: [1]   Go Down
Author Topic: Which hardware timer should I use for my library  (Read 689 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 3
Posts: 717
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 0.7.2

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 53
Posts: 1782
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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? smiley-wink

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

Canada
Offline Offline
Jr. Member
**
Karma: 1
Posts: 81
Frequently Befuddled
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Dallas, Texas
Offline Offline
God Member
*****
Karma: 3
Posts: 717
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 0.7.2

Pages: [1]   Go Up
Jump to: