# combining two pulse streams for counting

Discussion in 'Electronic Basics' started by Paul Ciszek, Sep 20, 2005.

1. ### Paul CiszekGuest

Suppose I have two sensors that give off a pulse every time an
event occurs; I have a choice of negative-going or positive-going
pulse. I also have a counter that is triggered by a falling edge
followed by a rising edge. I am looking for a simple way to
combine these two streams of pulses to get an accurate combined
count. The problem with using an AND or OR gate is that it wouldn't
correctly handle the case where one pulse arrives while another is
still in progress. So, I was thinking of doing the following:
Have one of the streams be normally high and negative-going; have
the other be normally low and positive-going. Feed the two signals
to the inputs of an XOR gate. That way, a lone pulse on either
line would cause the output of the gate to fall and rise; a
pair of overlapping pulses should make the output fall and rise
twice.

So, what's wrong with this? Usually something this simple is
wrong.

2. ### petrus bitbyterGuest

Alas, it will not be reliable. As apparently both streams are not related,
what will happen when two pulses arrive at the same time? Or, maybe even
worse, when they arrive almost at the same time? The first thing may be very
rare and you will have -theoretically - no output at all. The second will
give pulses that are too small or too low to be seen by the counter.

A simple, straight forward solution will be counting both streams seprately
and then use a full adder to obtain the result.

Otherwise you will have to build a circuit that samples both streams and
give exactly one outputpuls for every inputpuls, separated when both occur
at the same time. For not too high frequencies - let's say some hundreds of
kHz - a small micro is an ideal component. If you can't use one, you will
need some flipflops and glue logic to build a state machine plus a clock to
drive it.

petrus bitbyter

3. ### mikeGuest

This won't work when the edges are coincident.
Simplest general solution might be to use two counters and sum
the outputs digitally.
If you can restrict the relationships between the input signals,
things could get very much easier.
mike

--
Wanted, Serial cable for Dell Axim X5 PDA.
FS 512MB 45X SD Flash memory.
Return address is VALID but some sites block emails
with links. Delete this sig when replying.
FS 500MHz Tek DSOscilloscope TDS540 Make Offer
Bunch of stuff For Sale and Wanted at the link below.
MAKE THE OBVIOUS CHANGES TO THE LINK
ht<removethis>tp://www.geocities.com/SiliconValley/Monitor/4710/

4. ### ehsjrGuest

Regarding the XOR, simultaneous same duration pulses will fail
(3rd example below), as will simultaneous rise or fall with
different durations (examples 4 & 5)

Can you control the duration of the pulses from the sensors?
I'm envisioning the possibility of "pulses" from sensors that
are of random duration. For example, a power failure sensor
or low water level sensor could be low (or high) anywhere from
seconds to days.

Ed

Example1
========
--------
Sensor 1: ________| |_________
---
Sensor 2: __________| |__________
- --
XOR : ________| |___| |_________ GOOD!

Example2
========
--------
Sensor 1: ________| |_________
----------
Sensor 2: __________| |__________
- ---
XOR : ________| |______| |_________ GOOD!

Example3
========
--------
Sensor 1: ________| |_________
--------
Sensor 2: ________| |__________

XOR : __________________________ BAD!

Example4
========
--------
Sensor 1: ________| |_________
---
Sensor 2: ________| |__________
----
XOR : ____________| |_________ BAD!

Example5
========

5. ### Jasen BettsGuest

If you get two events at exactly the same time they won't get counted.

or if ome pulse ends as the other begins it produces one pulse on the output.

Bye.
Jasen