check if input signal stays high for a given time interval

Thread Starter

fenicento

Joined Jan 11, 2015
4
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 detects and object for more than one second. I'm actually using an Adafruit Trinket, 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:



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?
 

MikeML

Joined Oct 2, 2009
5,444
You need to verify that a signal lasts more than one second before taking action on that signal. A one-shot multivibrator can be used to "time" a signal. For example, the rising edge of the signal triggers the one-shot. If the input signal is still present after the 1 sec period of the one-shot, then you do something, else not.

The thing you want to do after the signal is validated is to "toggle" an output. One (>1s) Push to turn something on; a second (>1s) Push to turn it back off. A flip-flop will do that.

Sounds like your minimum system is a momentary switch, a one-shot, followed by a flip-flop, plus some logic, and a driver for the final output.
 

Thread Starter

fenicento

Joined Jan 11, 2015
4
I googled around, but I only found examples in which one-shot multivibrators produce a high output of arbitrary time length whenever a rising edge is recorded on the input (useful for debouncing inputs). Do you have any link, tutorial or schematics that fit my application?
Regarding the flip-flop, I see that the CD4013 integrated is widely used, hence I think I'll go for it.
 

crutschow

Joined Mar 14, 2008
34,285
Below is the LTspice simulation of a circuit consisting of a comparator delay and FF that should do what you want.
The output has to be low for at least 1.1s (as determined by the R4C1 time-constant) before the CD4013 FF is triggered. (The spec says the proximity sensor output is low when it senses an object)
The power and ground pins for the CD4013 aren't shown but must be wired.
Also all unused inputs for the other FF in the CD4013 package must be grounded.
You will likely have to add a buffer circuit on the CD4013 output, depending upon what you want to drive.

Delayed Sw.gif
 

Thread Starter

fenicento

Joined Jan 11, 2015
4
Wow, that's exactly what I was looking for, thank you! Actually i want to drive a 12V 3A DC halogen lamp, so the idea was to connect the output of the flip flop to the base of an NPN transistor (preceeded by a resistor in series), and to drive the lamp through its collector. So the general scheme of the project is:


12V, 5A power source --> voltage regulator to 5V --> comparator delay of sensor signal and FF --> transistor driving the lamp (whose positive pole is connected to the original, unregulated power source).

Is it right? Do you see any issues?
 

crutschow

Joined Mar 14, 2008
34,285
One problem. A standard NPN BJT requires about 300mA base current to fully turn on with a 3A collector load and the CMOS FF can't deliver that.
Easier is to use a logic-level type N-MOSFET (fully turns on with 5V Vgs), which requires no gate current to drive.

Edit: You can operate everything off the 12Vdc since both the comparator and FF are 12V tolerant. The resistor values just have to be adjusted for the new voltage.
That also means you can use a standard N-MOSFET.
 
Last edited:

Thread Starter

fenicento

Joined Jan 11, 2015
4
unfortunately I need 5V for the proximity sensor. I looked for a similar one working at 12V, but they are much more expensive. I really don't like the idea to use a voltage regulator, since I guess I'll have to include a heat sink, but I see no other options...
 

crutschow

Joined Mar 14, 2008
34,285
unfortunately I need 5V for the proximity sensor. I looked for a similar one working at 12V, but they are much more expensive. I really don't like the idea to use a voltage regulator, since I guess I'll have to include a heat sink, but I see no other options...
You'll need a heat sink only if the regulator power dissipation is above a watt or so (for a TO-220 type case).
What's the total 5V current?
The power dissipated is that current times the voltage drop across the regulator (7V).
 

ebeowulf17

Joined Aug 12, 2014
3,307
Out of curiosity, pros/cons of the N-MOSFET vs a Darlington transistor in a simple switching situation like this? I've used Darlingtons for several projects with good results and haven't played with MOSFETs yet.
 

crutschow

Joined Mar 14, 2008
34,285
Out of curiosity, pros/cons of the N-MOSFET vs a Darlington transistor in a simple switching situation like this? I've used Darlingtons for several projects with good results and haven't played with MOSFETs yet.
Darlingtons still require base current, but it's much less than a single BJT.
MOSFETs draw no steady gate current, but the gate looks like a small capacitor that must be charged and discharged to switch the FET.

MOSFETs have a much lower ON voltage than a comparable Darlington.
The minimum Darlington ON voltage is about one diode drop or 0.7V.
A MOSFET can have an ON resistance in the milliohm to tens of milliohm region.

MOSFETs are a much faster switch, that's why they are used in high frequency power switching applications such as switching regulators and converters.
 
Last edited:

ebeowulf17

Joined Aug 12, 2014
3,307
Fascinating! Thanks for the great descriptions. A lot of isolated things I've read, but not pieced together make a lot more sense now. Thanks!
 
Top