TimerOne updates

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?


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

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

Hope this makes sense.


TimerOne.cpp (7.28 KB)

TimerOne.h (1.65 KB)