It's not (ok, I'll rephrase...for me it's not!)

Now the high level concept....for a bit of fun (& learning) I'd like to be able to flash some LEDs at the same rate a switch has been manuall pressed (the average of say 4 switch presses), so...

Switch get pressed ....start a timer running.
Switch gets pressed again (1st 'timed press')...store the timer value, clear down the timer
Switch gets pressed again (2nd 'timed press')...store the timer value, clear down the timer
Switch gets pressed again (3rd 'timed press')....store the timer value, clear down the timer
Switch gets pressed again (4th 'timed press')....store the timer value - now add all the timer values & divide by 4- this gives the average count....convert the count into time....use the time to toggle some LEDS?

So what's the problem?

Timer overflows!

If my calculations are correct, even a 16 bit timer at a maximum prescale setting of 8 (@4mhz oscillator), will overflow after 0.524288 seconds - that aint a lot, so then I think ok, let's have an interrupt to track the number of timer overflows too, and then simply use that number multiplied by 65536 and add it to the existing timer count ....that ought to be easy....hmm, maybe not, because if I'm already in an IOC switch interrupt routine, then what happens when the timer overflows?


How should I be approaching this supposedly fun task?!!