# What circuit can detect a number of pulses within a time period ?

#### Externet

Joined Nov 29, 2005
2,241
Greetings.
What circuit can count if eight pulses happen within 5 seconds; and reset if not ? -No microcontrollers-

Last edited:

#### WBahn

Joined Mar 31, 2012
30,290
A queue comes to mind.

Every time a pulse happens, add a time stamp into the queue. Monitor the head of the queue and remove it if it has expired (is more than five seconds old). If the queue ever has less than eight items in it, then trigger a reset.

To size the queue you need to determine what the maximum number of pulses is that you can get within five seconds. If that number is too high, then there are other strategies that you could use. One would be to ask whether or not time could be binned. For instance, if you could decide either that multiple pulses that occur within a 10 ms window only count as one pulse. Or, if they can't, then you could use a counter to count how many pulses occurred within that window and add that to the timestamp data added to the queue. When the data is added, a register is incremented by that count and that register is decremented by that count when the data is removed from the queue. Now you just have to decide what a useful maximum is for the number of pulses within each time bin.

#### sghioto

Joined Dec 31, 2017
5,427
What happens if it does count 8 pulses in 5 seconds?
Thinking a 4017 decade counter and a 555 timer to start.

#### Externet

Joined Nov 29, 2005
2,241
Thanks.
Does it make sense to start a timer when a first pulse is received and reset the counter and timer if the counter did not reach 8 ? If it does reach the count of 8; latch an output (high or low) If does count more than 8, also reset.
Is there a name for such circuit that can be searched for different ways of doing it ? Seems I have seen something alike when a lock waits for digits to be entered...

#### WBahn

Joined Mar 31, 2012
30,290
What happens if it does count 8 pulses in 5 seconds?
Thinking a 4017 decade counter and a 555 timer to start.
But that doesn't give you a moving window.

For instance, what if the pulses occurred at the following times:

0.0 s - You start the timer. Count = 1
0.1 s - Count = 2
0.2 s - Count = 3
0.3 s - Count = 4
0.4 s - Count = 5
0.5 s - Count = 6
0.6 s - Count = 7
0.7 s - Count = 8
At 5.0 s, the timer expires and you have seen eight pulses, so you don't reset anything.
5.1 s - You start the timer. Count = 1
9.1 s - Count = 2
9.2 s - Count = 3
9.3 s - Count = 4
9.4 s - Count = 5
9.5 s - Count = 6
9.6 s - Count = 7
9.7 s - Count = 8
At 5.0 s, the timer expires and you have seen eight pulses, so you don't reset anything.

Yet between, say, 0.8 s and 9.0 s there was only a single pulse.

The same thing can happen the other way and your circuit will trigger a reset even though there was never a five second interval that had fewer than five pulses.

You need to, one way or another, start a new timer with EVERY pulse that is received.

#### sghioto

Joined Dec 31, 2017
5,427
Another scenario, the first pulse is counted and simultaneously starts a 5 second one-shot timer that resets the counter if 8 pulses are not registered during that time. If 8 pulses are received by the counter within the 5 second window the timer is disabled and whatever is supposed to happen at that point proceeds.

Joined Jan 15, 2015
7,578
Simplest way which comes to mind is open an and gate for 5 seconds and count the pulses. Depending on the counted pulses pulse width you could count a half pulse as a pulse. Pretty much the way a basic frequency counter of years ago worked.

Ron

#### WBahn

Joined Mar 31, 2012
30,290
Thanks.
Does it make sense to start a timer when a first pulse is received and reset the counter and timer if the counter did not reach 8 ? If it does reach the count of 8; latch an output (high or low) If does count more than 8, also reset.
Is there a name for such circuit that can be searched for different ways of doing it ? Seems I have seen something alike when a lock waits for digits to be entered...
Waiting for an input is a very different, and easier, approach. You are either starting the timer over each time a digit is entered, not carrying about the overall time. Or you are starting a timer with the first press and requiring that the last press be done before the time expires. But in either event, whether the required number of presses was met or not, the system stops (or moves to a different state) because either it got a combination and now has to process it, or it timed-out and requires the person to start over. But what you are asking for is a lock that, after entering the required number of digits within the time window, continues on and lets the person continue entering digits as long as, at any moment, they've entered that number within the prior amount of time corresponding to the window.

#### MrSalts

Joined Apr 2, 2020
2,767
Greetings.
What circuit can count if eight pulses happen within 5 seconds; and reset if not ? -No microcontrollers-
How accurate does the 5-seconds have to be? Is a 555 timer good enough?

Does it latch (lock) if the 8-pulses are received until your manual intervention, or
simply light an LED for the remainder of the 5-second window and then reset?

#### WBahn

Joined Mar 31, 2012
30,290
Simplest way which comes to mind is open an and gate for 5 seconds and count the pulses. Depending on the counted pulses pulse width you could count a half pulse as a pulse. Pretty much the way a basic frequency counter of years ago worked.

Ron
Same issue. You are creating back-to-back windows and requiring that each window have at least eight pulses in it. But what about a window that overlaps those two?

#### WBahn

Joined Mar 31, 2012
30,290
Another scenario, the first pulse is counted and simultaneously starts a 5 second one-shot timer that resets the counter if 8 pulses are not registered during that time. If 8 pulses are received by the counter within the 5 second window the timer is disabled and whatever is supposed to happen at that point proceeds.
And what do you do after the five seconds? What if all eight of those pulses happened in the first second? Just a second after the timer expires and says everything is okay, you end up in the situation where it has been more than five seconds without seeing ANY pulses. How is this detected with this approach.

#### MrSalts

Joined Apr 2, 2020
2,767
Are the pulses low from a normally high signal or high from a normally low signal?

#### MrSalts

Joined Apr 2, 2020
2,767
Thanks.
Does it make sense to start a timer when a first pulse is received and reset the counter and timer if the counter did not reach 8 ? If it does reach the count of 8; latch an output (high or low) If does count more than 8, also reset.
Is there a name for such circuit that can be searched for different ways of doing it ? Seems I have seen something alike when a lock waits for digits to be entered...
Locks are typically some with lines of code on a microcontroller.

#### WBahn

Joined Mar 31, 2012
30,290
Greetings.
What circuit can count if eight pulses happen within 5 seconds; and reset if not ? -No microcontrollers-
Please clarify the problem. There are at least two ways to read this.

One way is that you are monitoring a stream of pulses and you want to issue a reset if there is ever a five second span of time in which there weren't at least eight pulses.

The other way is that your system starts a clock based on something, and then has a single five-second window during which there has to be eight pulses.

The first is the way that I interpreted it.

If the second is what you meant, then that is MUCH simpler.

#### sghioto

Joined Dec 31, 2017
5,427
And what do you do after the five seconds? What if all eight of those pulses happened in the first second?
I said the timer would be disabled if it receives the 8 pulses within the 5 second window regardless if it took one second or 4.5 seconds.
Externet needs to cut to the chase and tell us what wants to make.

Joined Jan 15, 2015
7,578
I guess we just wait and hope for more clarity.

Ron

#### Externet

Joined Nov 29, 2005
2,241
Thank you.
For a constant stream of square wave pulses either normally low or high that can vary in width and interval; from as short as 0.1 seconds wide and hours without any pulse arriving; only if 8 (not 7, not 9) arrive in a 5 second window a relay to flip state to enable a second circuitry to be energized. The second circuitry can be manually reset by a person and is too involved and not matter of this thread.

The other way is that your system starts a clock based on something, and then has a single five-second window during which there has to be eight pulses.
This appears proper. If the count is not 8 then discards the count and uses the next pulse to start the timer and the counter again.

#### MrSalts

Joined Apr 2, 2020
2,767
Thank you.
For a constant stream of square wave pulses either normally low or high that can vary in width and interval; from as short as 0.1 seconds wide and hours without any pulse arriving; only if 8 (not 7, not 9) arrive in a 5 second window a relay to flip state to enable a second circuitry to be energized. The second circuitry can be manually reset by a person and is too involved and not matter of this thread.

This appears proper. If the count is not 8 then discards the count and uses the next pulse to start the timer and the counter again.
So then I assume the full 5-seconds must pass to make sure we don't get 9 or more pulses in the 5-second window before signaling to the downstream circuit. Correct?

#### MrSalts

Joined Apr 2, 2020
2,767
So then I assume the full 5-seconds must pass to make sure we don't get 9 or more pulses in the 5-second window before signaling to the downstream circuit. Correct?
Also, can 5-second windows overlap? As in, if a 9th pulse is detected in the first 5-second window the trigger doesn't fire for that five second window but, what if that 9th pulse is followed by 7 more pulses in the next three seconds (and nothing for two more seconds), should the trigger fire?

That is, can that 9th pulse count as both a reset and a first pulse in a new 5-second window?

#### WBahn

Joined Mar 31, 2012
30,290
Thank you.
For a constant stream of square wave pulses either normally low or high that can vary in width and interval; from as short as 0.1 seconds wide and hours without any pulse arriving; only if 8 (not 7, not 9) arrive in a 5 second window a relay to flip state to enable a second circuitry to be energized. The second circuitry can be manually reset by a person and is too involved and not matter of this thread.

This appears proper. If the count is not 8 then discards the count and uses the next pulse to start the timer and the counter again.
If they can be either low or high normally, what do you define as a pulse? Is it when the signal goes LO->HI->LO, or when it goes HI-LO-HI? For the same signal, you will get different results under the two definitions. If you want to count transitions, that's yet something else.

What is special about the pulses that start the timer as opposed to the other pulses that didn't? Why shouldn't a pulse be countable in multiple five second windows?

The approach you are using will either catch an exactly-eight-pulses-within-five-seconds event or not depending on the entire history of your system since it was last started because that will determine which are the special pulses that get to start timing windows.

Is that really the behavior you want?

That further brings up issues of time accuracy and resolution. Also, what is considered to be a pulse as far as whether it gets counted? Only pulses that start within the five second window? Only pulses that end within it? Or pulses that exist at least at some point within the window even if they started before it or ended after it?

If the 8th pulse happens 5.0000000001 s after the window opened, is that too late and it should not be counted, while if the 8th pulses happens at 4.99999999999 s it should?

It would REALLY help if you described the PROBLEM you are trying to solve, and not just how you think you need or want to go about solving it.