The best solution to at least half of all timing problems is using a timer interrupt. I don't know why so many people avoid that technique!

If you use an interrupt, you can do all your timing in the background.