Electronic – Generating pulses via timer match output or timer ISR

interruptslpcmicrocontrollertimer

I'm using LPC1778 uC for a project and want to know what is the difference between generating pulses via timer match output and via toggling a pin in a timer ISR. What are the pros and cons of both the approaches? Which one would generate more accurate pulses? Or is there no difference between them?

The only downside I can see to generating pulses via match pins is that uC's generally have only few match pins and hence only a few pulses can be generated via a timer match, while it's possible to generate pulses at any GPIO from a timer ISR.

Best Answer

Timer match is by far more accurate and is the best solution if you need high precision and the most deterministic behavior.

Timer match has a precision of the CPU bus frequency (to 60 MHz on that part). Interrupts have uncertainty of a few clocks (e.g. if the CPU is in the middle of a long instruction when the interrupt happens). In addition, some CPUs have small caches and the fetch time affects the interrupt latency.

Interrupts can be more flexible if you need some additional decision making on the pin action -- toggle or not, perform calculations etc.