# Detecting falling edge of signal and stretch the pulse width

#### Mehri01

Joined Nov 10, 2023
8
Hi,
I have a signal with 3.3 V amplitude , when error happens voltage drops to 0 V pulse width is around 1.7 ms. I am working with RPI . This frequency is too high for RPI so it cant count the error, It should be around 20 ms . How can I stretch pulse width of this 0 V pulse ?

#### AnalogKid

Joined Aug 1, 2013
10,944
Should be easy to do with a circuit called a monostable (short for monostable multivibrator). The circuit requires two inverting gates, such as 2-input NAND or NOR gates. I prefer the CD4093 quad NAND gate for this. Here is a sample schematic grab from the innergoogle:

An RPI could have a problem detecting when a digital input goes low for 1.7 microseconds, but 1.7 microseconds should not be difficult. But separate from that, how long is the minimum time period between error pulses? The question is about this: what should the circuit do if another error pulse happens during the timing period? If an error pulse is stretched to 20 ms, what happens if another error pulse shows up at the input in the middle of the output pulse? The classic monostable will ignore it; once it is triggered, it will ignore any other activity at the trigger input until it has finished its timing period. This is a defining characteristic of a true monostable. If you want the output pulse to restart if another error pulse shows up early, that requires a retriggerable monostable, a slightly different circuit.

Also, what device or circuit does the 20 ms output pulse drive? Current requirement / input impedance?

ak

Last edited:

#### Mehri01

Joined Nov 10, 2023
8
By detecting first error , RPI will disconnect high voltage of the other board to prevent damaging tube, catching first error is important . Programmer asked for stretching PW to do not miss errors. Now with 1.7 ms RPI misses many errors. Base on the written code , suggested PW is around 20 ms to make sure RPI could read it .
Error happens random , sometimes 1 , sometimes consecutive (Completely depends on tube and high voltage value).
I just need to stretch pulse width of the first falling pulse.

#### crutschow

Joined Mar 14, 2008
34,044
I prefer the CD4093 quad NAND gate for this
Yes, that's a good choice for this, as it has Schmitt-trigger inputs to minimize any oscillations that may occur from the slow fall of the signal at V1.

#### ronsimpson

Joined Oct 7, 2019
2,893
SN74LS122 There are a number of IC that do this job.

#### eetech00

Joined Jun 8, 2013
3,820
Hi,
I have a signal with 3.3 V amplitude , when error happens voltage drops to 0 V pulse width is around 1.7 ms. I am working with RPI . This frequency is too high for RPI so it cant count the error, It should be around 20 ms . How can I stretch pulse width of this 0 V pulse ?

Is the signal normally high and falls to 0 in 1.7ms?
Or, is it normally low, and a pulse is generated with a width of 1.7ms?
Does the input really rest at 0v or does it float?

#### eetech00

Joined Jun 8, 2013
3,820
Is the signal normally high and falls to 0 in 1.7ms?
Or, is it normally low, and a pulse is generated with a width of 1.7ms?
Does the input really rest at 0v or does it float?
You could use something like this:

"RC" should connect to GPIO pin.
Pull down is only needed if input signal floats.
Set input pin to analog and trigger at 1.8v or try digital.

#### Mehri01

Joined Nov 10, 2023
8
Is the signal normally high and falls to 0 in 1.7ms?
Or, is it normally low, and a pulse is generated with a width of 1.7ms?
Does the input really rest at 0v or does it float?
Yes. It is normally 3.3 V and just when error happens drop to 0 for 1.7 ms. RPI should read the 0 V to shut down the high voltage but it is to fast so RPI misses the trigger.

#### Mehri01

Joined Nov 10, 2023
8
You could use something like this:

View attachment 307170

"RC" should connect to GPIO pin.
Pull down is only needed if input signal floats.
Set input pin to analog and trigger at 1.8v or try digital.
I think I was not clear. Input voltage just becomes 0 for 1.7 ms, then return 3.3 V, Capacitor doesnt have enough time to discharge through the resistor.

#### eetech00

Joined Jun 8, 2013
3,820
I think I was not clear. Input voltage just becomes 0 for 1.7 ms, then return 3.3 V, Capacitor doesnt have enough time to discharge through the resistor.
Yes. Then post #7 won't work the way it is.

#### eetech00

Joined Jun 8, 2013
3,820
But this should work

Set GPIO input pin to analog and trigger at 1.8v or try digital.

Edit: corrected the output label

Last edited:

#### Mehri01

Joined Nov 10, 2023
8
Than you so much, in simulation I got the wanted result. I hope it works well in reality.
It is my first question in the forums and You are really awesome. Thanks again for sharing your knowledge.

#### Attachments

• 21.9 KB Views: 5
• 23 KB Views: 5

#### Mehri01

Joined Nov 10, 2023
8

#### BobTPH

Joined Jun 5, 2013
8,661
Programmer asked for stretching PW to do not miss errors. Now with 1.7 ms RPI misses many errors. Base on the written code , suggested PW is around 20 ms to make sure RPI could read it .
Fire the programmer. The RPi can easily detect a 1.7msec pulse. Your programmer doesn’t know what he is doing.

#### Mehri01

Joined Nov 10, 2023
8
Fire the programmer. The RPi can easily detect a 1.7msec pulse. Your programmer doesn’t know what he is doing.
Honestly, I think same as you. But I am the new guy in the company and programmer is old one.

#### eetech00

Joined Jun 8, 2013
3,820
Honestly, I think same as you. But I am the new guy in the company and programmer is old one.
Yes..just show programmer you can fulfill their request. But remind them it could have been handled in software. The programmer may respond with a good reason for not handling it in software.

#### AnalogKid

Joined Aug 1, 2013
10,944