Re: Polling vs. Interrupts in counting pulses - what is better?



ElderUberGeek wrote:
Hi. When counting pulses using a microcontroller (say from an encoder
or pulse generator), there are two methods: polling and using
interrupts. Two alternative designs can be used (well, at least), one
is to have the Microcontroller do it directly, and the other is to use
a dedicated chip to do it. The concern is of course that the
microcontroller might miss pulses if it is loaded with other tasks.

Depends on processor speed, loading and data rate, plus the consequences of missing the odd change.


If the change is slow compared with the polling cycle you can do (say, it's never going to be > 1k changes/ second), you can simply poll the inputs in a 1ms rate interrupt.

If you don't mind losing the odd pulse (say a mouse or an encoder used as a volume etc. control), just ignore cycles where there's more than 1 state change, and resynch the process.

Faster than that, it's quite economical to add a PLD to do the encoder for you (example on OpenCores if you can't work it out), depending on the application you might only need a short counter which can be extended in the interrupt.

Paul Burke
.



Relevant Pages