Pulse counting

Hey guys, what is the best way to do pulse counting ? Let's say I have a photo eye at one end and an AVR micro controller at the other.

Thanks G

Reply to
Giorgis
Loading thread data ...

It depends on the pulse rate, which you didn't mention.

Generally, if your micro has a external timer clock input, the timer module can count pulses. If you need more bits, you can extend the counter in software by enabling the timer overflow interupt. This is the easiest method, and typically allow fairly high pulse rates (>MHz)

Otherwise, if you don't have an external clock input, you may be able to use an external interrupt pin, and count all pulses in software. Depending on the rate, this may or may not be feasible (up to few kHz, typically)

You could also use a generic input pin, and poll the pin in a software loop, or by timer interrupt. This will generally only work for slow pulse rates, but can be used if timers/ext interrupts are already used.

For very high pulse rates, you could add external hardware to count or divide the pulses.

Reply to
Arlet

You might also need to think about debouncing: if your pulses are clean and have nice edges, you won't need this, but often you find your CPU interacting with the real world, where things tend to be everything but clean end nice.

For example, the output of your photo eye probably has some noise on it, either from electrical sources nearby or from other light sources like fluorescent lighting shining on it. If you just connect the analog output of the detector to a digital input, you can expect to see some 'false' pulses on every zero-crossing.

If you plan to use the timer/counter module on your processor, you probably have to do some kind of debouncing in hardware. If you choose the polling method, it's very well possible to solve this in software.

--
:wq
^X^Cy^K^X^C^C^C^C
Reply to
Ico

Thanks for the pointers guys. This is not for a specific project yet but I am collecting my thaughts as a newbie and doing different tutorials. I have an ultimate project so I am attacking it piecemeal.

Thanks again G

Reply to
Giorgis

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.