Pages: [1]   Go Down
Author Topic: TimerOne updates  (Read 1238 times)
0 Members and 1 Guest are viewing this topic.
Kent
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Posted previously under Programming, but perhaps better here - modified.

I started development of a timer using Timer1, but then came across the TimerOne library.  Rather than create something new, I've made some amendments to the existing library, but I'm not sure how I go about getting these incorporated into the official library.

To give you a feel, the amendments I've made are as follows:

 *  - Add (long) assignments and casts to TimerOne::read() to ensure calculations involving tmp, ICR1 and TCNT1 aren't truncated
 *  - Ensure 16 bit registers accesses are atomic - run with interrupts disabled when accessing
 *  - Remove global enable of interrupts (sei())- could be running within an interrupt routine)
 *  - Counter reset to 1 rather than zero.  Datasheet vague on this, but experiment shows that overflow interrupt
 *  - flag gets set whilst TCNT1 == BOTTOM, resulting in a phantom interrupt.  Could code around, but unnecessary complexity
 *  - Start() amended to start counter and handle all interrupt enabling. 
 *  - Point restart() at start().  Can't see any real difference

I can post the modified code, if that would help?
 
Andrew
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13896
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I can post the modified code, if that would help?
Sure, as people can test and review it !!

Please use [ code] tags or attach it as a ZIP file
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Kent
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have since made contact with Lex, who maintains the library, but I've attached the suggested amendments to the code.

Hope this makes sense.

Andrew

* TimerOne.cpp (7.28 KB - downloaded 14 times.)
* TimerOne.h (1.65 KB - downloaded 8 times.)
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13896
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: