EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: fenicento on January 11, 2015, 03:17:57 pm

Title: Check if input signal is high for a given time interval
Post by: fenicento on January 11, 2015, 03:17:57 pm
Hi all,
I'm an Arduino user and not to skilled in electronics (not at all actually). I'm trying to build a lamp that switches on and off  if a digital proximity sensor (http://www.adafruit.com/products/1927) detects and object for more than one second. I'm actually using an Adafruit Trinket (https://learn.adafruit.com/introducing-trinket/introduction), but I'd really like to use integrated circuits thant don't need to be programmed, since the application is really easy.

In order to toggle the on/off I guess I can use a T-type flip flop, but I really don't know how to check if the signal of the sensor stays high for one second. In short, I need an integrated chip or a circuit that reproduces this behaviour:



Quote
The On-Delay S5 Timer instruction starts a specified timer if there is a
positive edge (that is, a change in signal state from 0 to 1) at the Start (S)
input. A signal change is always necessary to start a timer. The timer
continues to run with the specified time at the Time Value (TV) input as long
as the signal state at input S is 1. A signal state check for 1 at output Q
produces a result of 1 when the time has elapsed without error and when the
signal state at input S is still 1. When the signal state at input S changes from
1 to 0 while the timer is running, the timer is stopped. In this case, a signal
state check for 1 at output Q always produces the result 0.




Any ideas?
Title: Re: Check if input signal is high for a given time interval
Post by: German_EE on January 11, 2015, 07:01:44 pm
Take a 74HC132 chip, it's four two input NAND gates but they have Schmitt trigger inputs so slow inputs can be used. One input is directly from your sensor, the second input has a series resistor and a capacitor down to 0V. So, the sensor output goes high, input one goes high and input two slowly ramps up to 5V over 1 second, after which the output of the NAND goes low.
Title: Re: Check if input signal is high for a given time interval
Post by: fenicento on January 12, 2015, 06:08:44 pm
That sounds just fine, thanks.

I just read that the sensor signal is normally HIGH, and becomes LOW when something is in the way. So I guess I have to turn thing around and use a NOR gate. In this case I'd have the first input coming directly from the output of the sensor, and the second one connected in series with R and C. Is it right? Do you know where I can find a formula to correctly estimate the right R and C in order to obtain a desired time T? 
Title: Re: Check if input signal is high for a given time interval
Post by: katzohki on January 12, 2015, 06:21:35 pm
Or you could get a simple clock going and count how many clock pulses something is high / low.
Title: Re: Check if input signal is high for a given time interval
Post by: fenicento on January 13, 2015, 12:18:03 am
as I said, I'm a newbie and making circuits without a MCU is really difficult for me. Can you count the clock cycles in which a signal is high or low just using integrated circuits?
Title: Re: Check if input signal is high for a given time interval
Post by: Rick Law on January 13, 2015, 12:29:49 am
as I said, I'm a newbie and making circuits without a MCU is really difficult for me. Can you count the clock cycles in which a signal is high or low just using integrated circuits?

Try the millisec() function.   Save the milliseconds it first turn on, and now you can subtract that off to get how long it has been on:

...
unsigned long lastTurnOn=0;
unsigned long turnOnTime=0;
int itIsOn=0;
...
if (decidedIfOn()==yes) {
    if (itIsOn==0) {
        lastTurnOn=millisec();
        itIsOn=1;
    }
    //
    turnOnTime = millisec()-lastTurnOn; // how many milli seconds ago did it turn on
} else {
    itIsOn=0L;
}


Give that a try... & good luck...
Title: Re: Check if input signal is high for a given time interval
Post by: dannyf on January 13, 2015, 02:20:46 am
Quote
I'm an Arduino user ... but I'd really like to use integrated circuits thant don't need to be programmed, since the application is really easy.

Tough to reconcile the two, :)

Anyway, a 555 would do that, as well as some logic gates. But a mcu is probably the most versatile of them all.

But without knowing which path you want to go down, it is hard to help you.
Title: Re: Check if input signal is high for a given time interval
Post by: dannyf on January 13, 2015, 02:24:21 am
Code: [Select]
    turnOnTime = millisec()-lastTurnOn; // how many milli seconds ago did it turn on
The logic can be made simpler: you just need to reset the counter if nothing is detected.

Something like this:

Code: [Select]
  if nothing_detected start_time=milliesec(); //reset start time is nothing is detected
  if (milliesec() - start_time > desired_duration) do_something();

Title: Re: Check if input signal is high for a given time interval
Post by: katzohki on January 13, 2015, 03:52:52 pm
as I said, I'm a newbie and making circuits without a MCU is really difficult for me. Can you count the clock cycles in which a signal is high or low just using integrated circuits?

Yes. Let's say you want to check if your signal is high (just use an inverter if you want to check low). Take your signal and AND it with a clock signal (you can use a crystal or clock IC). Feed that into a counter. AND the outputs of the counter together and when they are all = 1 the output will be 1. You will have to experiment with maybe multiple counters to get it to the timing you want.

https://www.fairchildsemi.com/datasheets/74/74VHC393.pdf (https://www.fairchildsemi.com/datasheets/74/74VHC393.pdf)

Edit: On the subject of doing this with an MCU, you could do this with an absolute minimum if you learn to program directly without all the extras that the adafruit board gives you. I reckon that a 6 pin MCU (e.g. ATTiny or PIC10F), decoupling cap, couple resistors, transistor, a relay and your sensor could accomplish the entire project.