|
From: ElderUberGeek on 19 Jan 2006 04:06 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. So which method is prefered? Any suggestions? Thanks
From: dave on 19 Jan 2006 05:26 On Thu, 19 Jan 2006 01:06:02 -0800, 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. > > So which method is prefered? Any suggestions? Depends on your pulse rate and processor loading. One thing to look at is the Time Processor Unit (TPU) on Freescale 683xx and PowerPC micros. It is a microcoded coprocessor with the ability to execute either ROM-based or RAM-based microcode. Freescale provides a variety of routines in ROM for various functions. Infineon probably has micros with similar units. See http://www.eslave.net/index.shtml for some TPU info. ~Dave~
From: Paul Burke on 19 Jan 2006 05:33 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
From: cbarn24050 on 19 Jan 2006 07:47 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. > > So which method is prefered? Any suggestions? > > Thanks Most micros allow you to use a counter directly only interrupting at over/underflow, this is by far the best method. For counting from an encoder there are micros with up/down biphase counters especialy for this application.Useing interrupts is the next best method but you are quite restricted as to how fast you can go. Polling is the very worst option only suited to slow rates and non critical counts.
From: Ian Bell on 19 Jan 2006 08:26
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. > I assume you really mean counting pulses rather than measuring the time between pulses. For counting pulses, most microcontrollers have counters which can be driven from an input pin in order to count pulses. If you want to measure speed and current position you can read the counter at fixed intervals. If you want to do something after a fixed number of pulses you can usually pre-load the counter with 0-counts required so it overflows at the required count. Most counters can be made to cause an interrupt on overflow. If you need to do something every pulse that is a whole different ball game. Ian |