Timer1 does not work when interval is one second

I downloaded Timer1 from the Arduino playground and wrote a sketch that would blink the LED every second. I could not get the timer to work properly until I realized that the calculation in TimerOne::setPeriod() probably overflowed. If you call setPeriod(1000000), the first line in the function is: long cycles = (F_CPU * microseconds) / 2000000; A long int is 32 bits, and if F_CPU is 8000000, you get a numerator of 8,000,000,000,000. This does not fit in 32 bits. The function worked for me when I changed the units to milliseconds. Then I called the setPeriod(1000) and the first line becomes long cycles = (F_CPU * milliseconds) / 2000; In this case, the numerator is only 8,000,000,000. I am not sure if this will work for others--I have a 3.2 Mhz crystal, so my numerator is even smaller. Perhaps the Timer1 class should have a member called Units. You could have these defines:

define MICROSECONDS 1000000

define MILLISECONDS 1000

define SECONDS 1

Then the first line in setPeriod() could be long cycles = (F_CPU * period) / (2*Units);

Here is an easy correction to the Timer1 program. In TimerOne::setPeriod(), replace the line
long cycles = (F_CPU * microseconds) / 2000000;
long cycles = (F_CPU * (long long) microseconds) / 2000000;
This causes 64-bit arithmetic to be used, so the overflow does not occur.

Timer3 has the same problem and needs the same correction.