0
\$\begingroup\$

I have a line pulled to +5V. When a button is pressed, it should ground the line after a 100ms delay. How would I implement such a delay?

\$\endgroup\$
  • 1
    \$\begingroup\$ How accurate does the 100ms delay need to be? If not very, then I would probably use a 555, but that's mainly because I know I've got several scattered about in old parts bins. \$\endgroup\$ – Glen Yates Aug 3 '17 at 19:55
  • 2
    \$\begingroup\$ What are your design constraints? Do you really want to "ground the line"? Is the line some kind of weak pull up for a microcontroller? \$\endgroup\$ – PICyPICyPICy Aug 3 '17 at 19:57
  • \$\begingroup\$ I realized that I asked a bad question -- sorry. I will now ask the correct one. \$\endgroup\$ – the_rover Aug 3 '17 at 20:22
3
\$\begingroup\$

schematic

simulate this circuit – Schematic created using CircuitLab

OA1 is an open drain comparator who's output is your line that's pulled up to 5V. The value of R1 will determine the length of the delay with larger values resulting in larger delays. The delay can be calculated as t = -ln(.5)*R1*C1.

If there are debounching issues, use a comparator with hysteresis (schmitt trigger).

Another, maybe better, way to change the timing is to change the voltage on the non-inverting input. This could be done with a DAC for digital control of the timing.

\$\endgroup\$
8
\$\begingroup\$

Here is the circuit:

The rest is firmware.

The passive pullup on the GP3 pin is enabled. The pin therefore goes low when the button is pressed and high when not. The firmware debounces this and puts the result on the OUT pin. Since debouncing includes a delay, you simply make this delay your desired 100 ms.

Normally I use 50 ms debouncing delay, because that's about the maximum where humans still feel the action is immediate. If you want a deliberate delay, make the debouncing delay as long as you need.

Look at the button every iteration of a timed loop. If the instantaneous state of the button is the same as the debounced state, reset the debounce counter to maximum.

Decrement the debounce counter each loop. If it reaches 0, then then the last state of the input line becomes the new debounced state. Reset the counter to maximum.

Adjust the debounce counter maximum value to however many loop iterations you do in your desired 100 ms delay time.

For example, lets say you run the loop every overflow of the free-running timer 0. That's every 256 instruction cycles, which is every 256 µs. It would take 391 iterations to get to 100 ms. Since it would be easier to use a 8 bit counter, you could divide the timer 0 overflows by 2 (run the loop every second time). Now it takes 195 iterations for 100 ms, which fits nicely into a 8-bit variable.

\$\endgroup\$
6
\$\begingroup\$

Since no background information was given we seem to be limited to a button, a ground line, a 5 V supply and an unspecified pull-up resistor. Assuming that the circuit will be used on Earth we can use gravity and distance to provide an accurate timer.

From \$ h = \frac {1}{2} gt^2 \$ where h is height, g is the acceleration due to gravity and t is time, and \$ v = gt \$, where v is final velocity we can calculate that a body in free fall will travel 0.04903325m in 100 ms.

schematic

simulate this circuit – Schematic created using CircuitLab

Figure 1. Gravity timer. On push the OUT line will be pulled low after 100 ms.

The circuit requires a manual reset.

\$\endgroup\$
  • 3
    \$\begingroup\$ +1 just for the silliness, and to point out how important providing good specs is. \$\endgroup\$ – Olin Lathrop Aug 3 '17 at 20:13
  • \$\begingroup\$ I was going to say an RC circuit and an op amp, but this is better. \$\endgroup\$ – PICyPICyPICy Aug 3 '17 at 20:14
  • \$\begingroup\$ You should probably make the height adjustable, the gravitational acceleration (g) is slightly different in different locations on the planet. Bouncing and sensitivity to shock and vibration are probably only some very minor issues and can be ignored. \$\endgroup\$ – Oskar Skog Aug 3 '17 at 20:15
1
\$\begingroup\$

You can use monostable circuit. For example, a 555 timer can be configured into a monostable circuit. Once trigger is activated the output will be high for given period of time (say 100ms). This can be used to develop a circuit for your requirements. Other than 555 timer, same operation can be realized using a micro-controllers or two transistors or logic gates etc. More ideas can be given, depending upon your interest.

\$\endgroup\$
0
\$\begingroup\$

How would I implement such a delay?

Depending on your comfort level.

A timer would do it all day long, for example.

That kind of timer can be done with a 555 or its modern equivalent, an opamp, a logic gate, or even a transistor.....

The other route is a digital solution. Like a mcu.

Again, all depends on what's available to you.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.