Content originally posted in LPCWare by ub3r on Wed Jul 11 21:34:50 MST 2012
Quote: elef
ub3r, i had the same problem. I'm used to having more advanced timers on my MCU's where you can also clear the timer on capture.
Anyways, easy solution, but it uses more memory (a tiny bit of ram and flash, but i assume you have heaps spare):
[B]Don't clear the timer.[/B] Each time you enter the interrupt, subtract the previous interrupt value from the new one. Then save the new one to overwrite the old one before you exit the interrupt.
Then you might need to take care when it wraps around, but if you use "unsigned short int" (size needs to match your timer size, so unsigned int for 32 bit timer) you should be ok...
Very good idea. Ill try implement it in the next few days and let you know how i go. :)