Converting super short button press into longer input signal

Thread Starter

MrSoftware

Joined Oct 29, 2013
1,780
Is there a better way to do this? The goal is to catch extremely short button presses, and turn that short button press into a relatively long (~500ms) input signal.

The use case is a processor that polls its input lines every few msec. I wish it was an interrupt, but the code is in a library and I don't have time to re-write it. There is a momentary push button on one of the inputs, and the user will frequently smack the button resulting in a button press so short that the processor misses it. So I need to catch an extremely short button press and hold it for a relatively long time (500ms) to be sure the processor reads it. We are expecting multiple seconds between successive button presses. Is there a better (less parts, cheaper) way to do it than this? In the graph, green represents the input line into the processor that needs to be held low for ~500ms on each button press. My fear is I will need a relatively expensive OpAmp (rail to rail) to make this work. The processor considers any input above about 0.9v to be "high".


upload_2019-2-19_12-6-10.png

upload_2019-2-19_12-6-52.png
 

Attachments

AnalogKid

Joined Aug 1, 2013
8,464
AH beat me to it. A uC input pin is a comparator, so all you need are the 30 K and 20 uF from your schematic. To reduce wear on the switch contacts, I would reduce the capacitor to 1 uF and increase the R to 620 K.

There are several other options, all of which are less complex than an analog comparator.

Can the uC internal 13 K resistor be disconnected? If not, then you could use a 47 uF capacitor and no other components, if the switch contacts are rated over 1 A.

Or, your opamp can be replaced by a single 2N7000 MOSFET. Or an inverter or NAND gate (with or without hysteresis), BJT, FET, etc.

1. Does the input to the uC have to be negative true?
2. Does the switch have to pull to GND?
3. How many inputs?

ak
 
Last edited:

Thread Starter

MrSoftware

Joined Oct 29, 2013
1,780
Thanks guys. I thought about just a resistor and capacitor, but I'm concerned that I'll get false triggers as the voltage rises relatively-slowly through the 0.9v high / low threshold as the capacitor recharges. There will be audio and other things happening on the board that may result in less than perfect DC, which could exacerbate this. Something like a schmitt trigger (or a 555?) would prevent this. What would be the configuration for getting similar binary on/off with no gray-area behavior from a MOSFET based design?

The uC can use high or low as a trigger, and I can wire the switch to pull up or down. One input. The 13k internal pullup can be disabled, but I would like to use it IF it can reduce my parts count.

Side note; I think I see what you're thinking by using "high" as true; use the button to charge a cap then bleed it down slowly through a pull down resistor. I would have the same concern about false triggers as it relatively-slowly passes through the high/low threshold voltage on the way down to 0.
 

crutschow

Joined Mar 14, 2008
24,969
How about a CMOS Schmitt-trigger inverter:
R2 limits the peak switch current.
You can use just one inverter, depending upon the polarity you want as logic 1.
Connect all unused inputs to ground, of course.

upload_2019-2-19_12-58-47.png
 
Last edited:

AlbertHall

Joined Jun 4, 2014
9,873
Thanks guys. I thought about just a resistor and capacitor, but I'm concerned that I'll get false triggers as the voltage rises relatively-slowly through the 0.9v high / low threshold as the capacitor recharges. There will be audio and other things happening on the board that may result in less than perfect DC, which could exacerbate this.
When the uC detects a low signal then don't read the pin for the next period of time - perhaps 200mS - while the voltage slowly rises through the 'at risk' zone. No components needed, and probably not much code either depending what you have already got.
 

MisterBill2

Joined Jan 23, 2018
6,072
Why not just the capacitor across the button?
A capacitor will not only possibly stretch the pulse enough, it will also stretch the other side of the pulse. AND often capacitors have enough effective internal resistance that it still may not work reliably.
In addition, cheaper than a one-shot IC as described, a flop-shot can also serve to stretch the pulse.
 

AnalogKid

Joined Aug 1, 2013
8,464
When the uC detects a low signal then don't read the pin for the next period of time - perhaps 200mS - while the voltage slowly rises through the 'at risk' zone.
I have used that technique in the past, but you don't know when the transition through the 'zone' will start because human/switch dwell time is unknown.

ak
 
Last edited:

eetech00

Joined Jun 8, 2013
1,898
Is there a better way to do this? The goal is to catch extremely short button presses, and turn that short button press into a relatively long (~500ms) input signal.

The use case is a processor that polls its input lines every few msec. I wish it was an interrupt, but the code is in a library and I don't have time to re-write it. There is a momentary push button on one of the inputs, and the user will frequently smack the button resulting in a button press so short that the processor misses it. So I need to catch an extremely short button press and hold it for a relatively long time (500ms) to be sure the processor reads it. We are expecting multiple seconds between successive button presses. Is there a better (less parts, cheaper) way to do it than this? In the graph, green represents the input line into the processor that needs to be held low for ~500ms on each button press. My fear is I will need a relatively expensive OpAmp (rail to rail) to make this work. The processor considers any input above about 0.9v to be "high".


View attachment 170481

View attachment 170482
Hi

The problem with the circuit is the input delay is so long that it doesn't trigger the comparator circuit. The time delay should be produced at the output of the circuit instead of at the input. That's basically what a properly designed monostable multivibrator circuit (or "one-shot") will provide....the input trigger, however short, will reliably produce a delayed output of a fixed duration.

eT
 

eetech00

Joined Jun 8, 2013
1,898
Hello,

This should work. The output will go low for approx. 500mS after a quick button press. If the circuit needs to account for a long button press, then a differentiator will need to be added to the input.

If a weak PU is enabled on the uC input, disabled it.

eT

upload_2019-2-20_19-4-56.png

Edit: Updated to include input differentiator.
 
Last edited:

danadak

Joined Mar 10, 2018
4,057
A waste of the other 95% resources on this part, but a simple code-less
design. One chip. Resources onchip needed/used, and left in right hand window.

Mechanical switch debounced, then extended by pulse converter to 500 mS,
or whatever you need.

upload_2019-2-20_9-14-42.png


Only external component needed is a C to bypass power pin of PSOC and
switch. If you use onboard capsense component then that would eliminate
switch, switch becomes a trace and pad on PCB. But you would have to do
some simple code to handle it, like issue a start to the capsense component.

Chip power up inhibits any stray pulse generation.


Regards, Dana.
 
Last edited:

MisterBill2

Joined Jan 23, 2018
6,072
The circuit does depend on the load, which in this case is a processor board with a 10K ohm pullup resistor to 3 volts. So the interface needs to pull down well below the 0.9 volts considered a "0". That is well within a CMOS pull down range at 3 volts supply. The very best way would be a flipflop with the button setting it and then the processor acknowledging with a reset. So a monostable as mentioned early with a time set to perhaps 100 milliseconds would work, but a flop-shot CD4013 with a 100k resistor from Q out to reset in, along with a 0.01mFd cap to ground, will cost less. AND there are two of them in a package. Use the set and reset because they don't respond to contact bounce and trigger multiple times. or toggle back and forth with successive contact bounce pulses. Less than a dollar for two lines, a good price as well. AND all of the parts available from MANY sources.
 

Thread Starter

MrSoftware

Joined Oct 29, 2013
1,780
Thanks all for the great info, it looks like there are multiple options here. I'm debating which is better between the inverter option that @crutschow mentioned above, or a monostable multivibrator llike this one. They are both similar in price and require few external parts. The inverter option allows a long button press to remain a long button press which is actually useful in this project, but are there any down sides to this method, or advantages to using the multivibrator that I'm not seeing?
 
Top