# Detecting short pulse help please

#### HDAV

Joined Aug 21, 2011
43
Hi everyone my first post so please be gentle.

I have a system that generates an event from a trigger the trigger is the closing of a small switch.

The problem is the switch/sensor only closes for a short period of time. The electronics that detect the pulse detect it as part of existing device (the device has GPIO available). Which are used "sense" the event switch closing.

The issue is that the detection of the closure is unreliable, we believe that this unreliability comes from the "sampling of the GPIO" which occurs at about 120hz (this is done by software) the software was modified to to sample at 1Khz (polling the GPIO at 1khz) but we think the GPIO are locked in firmware of the device to 120Hz detection (does this make sense?)

The process does work but isnt reliable enough (worked 3 time out of 3 then 1 out of 4) What i need to do is extend the output of the switch pulse at the moment the time the switch is closed for is short <10ms if we can modify the output to be closer to 100ms then the "sense will be more reliable"

My first thought was an SR flip flop which will work or a 555 based timer or any sort of latching circuit. the issue is the size of the solution.

If possible we want to avoid any IC components and keep the components down to 2 or 3 legged items.

One idea is to use a small capacitor that is charged by the switch closing but discharges slowly through a resistor? but struggling with the design can anyone help?

Power is 12V DC
Sensor is a mechanical switch NO (push to make)
Devices has opto isolated inputs available
Current system has 12V->switch->Device input

Challenge for the analogue experts out there can this be done with maximum 3 additional components? Was thinking Capacitor and Diode in series where capacitor charges quickly when switch closed but discharges slowly when switch returns to open?

Thank you for taking the time to read this and I appreciate any advice offered. Many thanks.

#### praondevou

Joined Jul 9, 2011
2,942
Devices has opto isolated inputs available.
Does that mean the input signal HAS TO drive an optocoupler? If so, what's the current needed to drive it ON?

Can one side of the switch be connected to either positive voltage or GND?

#### HDAV

Joined Aug 21, 2011
43
Good question: The specs for the detection on the device input is:
Uin(high) = 3 V...24 V
Uin(low) = 0 V...1.5 V
I believe the Opto coupling is to prevent damage to the device and allow it to use a range of voltage and currents as an input, the actual functional input is to Schmitt trigger inside the device

Parameter Value
Uin (low) 0 V ... 1.5 V
Uin (high) 3 V ... 24 V
Current (constant current source
within the device) 8 mA
Flux voltage of the LED (@ 10 mA) 1.5 V

The device use a and LED to an op to sensor to transfer the trigger from external voltage to the internal logic (so yes it does need to drive the internal LED.

Last edited:

#### HDAV

Joined Aug 21, 2011
43
Can one side of the switch be connected to either positive voltage or GND?
Good thinking use a capacitor to charge the trigger which has a charging delay of Xms then if the switch grounds (discharge capacitor through resistor) then the input would stay low for Xms

Is this the sort of thing you were thinking? the "trigger signal would need to stay below 1.5V for 0.01 seconds but would need to discharge to 0V in 0.001 seconds so we are looking for a factor of 10 delay?

Can this be simply implemented?

#### HDAV

Joined Aug 21, 2011
43
Attached is the output of a similar sensor tested on a scope the actual sensor pulse I dont yet have

#### Attachments

• 28.8 KB Views: 32

#### SgtWookie

Joined Jul 17, 2007
22,210
Well, I had the attached simulation kicking around that might be useful for you...

Since your inputs are Schmitt triggers, you wouldn't need the 555; just the two resistors, the cap and the switch. The switch I used in the simulation works like a relay.

R1 is in there to keep the switch contacts from getting burned, along with avoiding putting a large transient on the power rails.

#### Attachments

• 115.7 KB Views: 48

#### HDAV

Joined Aug 21, 2011
43

In the simulation the switch which is S1? is used to trigger the 555? the R1 R2 C1 gives the purple trace (trigthrs) on the graph which drops down to 1.5V ish the steadily rises?

S1 is normally open? and when closed grounds the trigger input?

I have downloaded LTspice and tired to come up with a simulation, is there a way to put a switch in other than the volt controlled switch you used?

As for the schmitt levels they are i believe derived from the opto unit
Parameter Value
Uin (low) 0 V ... 1.5 V
Uin (high) 3 V ... 24 V

Triggers
All inputs configured as triggers are linked by AND. If several inputs are being
used as triggers, a high signal must be present on all inputs in order to generate
a trigger signal. Each signal can be inverted.

Last edited:

#### ErnieM

Joined Apr 24, 2011
8,034
You already have flip flops built into your device (assuming it is a PIC).

The first way is to use an Interrupt On Change (IOC) bit, which will fire when there is a change giving you an immediate check of the pin just after it changed.

Another way is to use the I/O pin to drive one of the timer registers as the clock; clear the timer, and check if it is not zero in your loop.

As far as it being a 10V pulse: not a huge problem. Just isolate with a 50K or so resistor after making sure the input you drive has the ESD suppression diodes. Then a 10V pulse will be current limited, but still input a 5V (or whatever Vdd is) pulse to the device.

#### SgtWookie

Joined Jul 17, 2007
22,210
Not dumb questions; just questions.

In the simulation the switch which is S1? is used to trigger the 555?
S1 represents your switch. It's normally open, and closes for just a short period of time; a couple of milliseconds.
the R1 R2 C1 gives the purple trace (trigthrs) on the graph which drops down to 1.5V ish the steadily rises?
Yes. The capacitor C1 charges relatively quickly, as R1 is a very low value compared to R2. If the switch stayed closed longer, the voltage on C1 would eventually reach nearly 1/48th of 12v, or 250mV.

S1 is normally open?
Yes.
and when closed grounds the trigger input?
Yes.

I have downloaded LTspice and tried to come up with a simulation, is there a way to put a switch in other than the volt controlled switch you used?
Not really. LTSpice is not interactive in that manner. Basically, you set up an analog simulation, then run it, and when it's done, you view the output. If you want parameters to change during the simulation run, you need to set them up beforehand.

There IS a somewhat limited simulation available online where you can see things occurring in (more or less) real time, or slowed-down real time, which is handy for demonstrating things - but its' accuracy is rather dubious.

That simulator is available here: http://www.falstad.com/circuit/
You will need to have Java installed to use it.

As for the schmitt levels they are i believe derived from the opto unit
Parameter Value
Uin (low) 0 V ... 1.5 V
Uin (high) 3 V ... 24 V

Triggers
All inputs configured as triggers are linked by AND. If several inputs are being
used as triggers, a high signal must be present on all inputs in order to generate
a trigger signal. Each signal can be inverted.
Hmm. Well, then the charge should be limited to around 4.5v in order to have a roughly 1/3-2/3 threshold swing. Not very difficult to implement with a Zener and resistor.

Last edited:

#### HDAV

Joined Aug 21, 2011
43
You already have flip flops built into your device (assuming it is a PIC).

The first way is to use an Interrupt On Change (IOC) bit, which will fire when there is a change giving you an immediate check of the pin just after it changed.

Another way is to use the I/O pin to drive one of the timer registers as the clock; clear the timer, and check if it is not zero in your loop.

As far as it being a 10V pulse: not a huge problem. Just isolate with a 50K or so resistor after making sure the input you drive has the ESD suppression diodes. Then a 10V pulse will be current limited, but still input a 5V (or whatever Vdd is) pulse to the device.
Thanks the Device is probably similar to a PIC (its a fairly high spec micro processor) but its a stand alone unit which offer I/O that are available in software, the software has been written to use the device triggers.

All we need to do is make the trigger reliable. We are sure the physical trigger works but the pulse is too short for the I/O to detect (proven by sporadic detection). It would be possible to modify the device but the cost and hassle of getting a major manufacturer to modify the firmware for one unit is likely to astronomical!

I am trying to run a spice simulation but struggling with how to simulate the short pulse?

This is a small part of a larger project and I am just struggling with the various constraints.

Thanks to everyone that has offered some input please keep it coming

#### HDAV

Joined Aug 21, 2011
43
Not dumb questions; just questions.
Thanks,

Not really. LTSpice is not interactive in that manner. Basically, you set up an analog simulation, then run it, and when it's done, you view the output. If you want parameters to change during the simulation run, you need to set them up beforehand.
Is their a good online guide on how to configure this?
There IS a somewhat limited simulation available online where you can see things occurring in (more or less) real time, or slowed-down real time, which is handy for demonstrating things - but its' accuracy is rather dubious.

Hmm. Well, then the charge should be limited to around 4.5v in order to have a roughly 1/3-2/3 threshold swing. Not very difficult to implement with a Zener and resistor.
The 12V is the device supply voltage it has an I/O port with 12V pin (i think this is just tapped off the incoming power lines) there are then 2 inputs and 2 outputs and a few grounds available.

At present the "sensor" (switch) is just connected between 12V and "Trigger 1" The advantage of this is its a very small solution not requiring a PCB.

There are several "mechanical" considerations and to keep the device reliable and robust the fewer connections the better really. Oh it also has to be as light and energy (power) efficient as possible as its battery powered......

#### SgtWookie

Joined Jul 17, 2007
22,210
re: switch and voltage source:
Is their a good online guide on how to configure this?
In the LTSpice program, press F1.
The voltage controlled switch parameters are covered under S.
The voltage source is described under V.

Re: Java simulator:

The 12V is the device supply voltage it has an I/O port with 12V pin (i think this is just tapped off the incoming power lines) there are then 2 inputs and 2 outputs and a few grounds available.

At present the "sensor" (switch) is just connected between 12V and "Trigger 1" The advantage of this is its a very small solution not requiring a PCB.

There are several "mechanical" considerations and to keep the device reliable and robust the fewer connections the better really. Oh it also has to be as light and energy (power) efficient as possible as its battery powered......
I see - so scratch the Zener/resistor idea.

I'm attaching a new version of the simulation; I've rigged the 555 timer so that it will have about the same thresholds as your Schmitt-trigger inputs.

Now, I don't know if your Schmitt inputs are inverting or non-inverting. As you can see, the output of the 555 is inverting from the trigger/threshold inputs. This circuit can be flipped upside-down if you need the opposite voltage level to trip your Schmitt triggers.

#### Attachments

• 122.5 KB Views: 28

#### HDAV

Joined Aug 21, 2011
43
I'm attaching a new version of the simulation; I've rigged the 555 timer so that it will have about the same thresholds as your Schmitt-trigger inputs.

Now, I don't know if your Schmitt inputs are inverting or non-inverting. As you can see, the output of the 555 is inverting from the trigger/threshold inputs. This circuit can be flipped upside-down if you need the opposite voltage level to trip your Schmitt triggers.
Thanks very much looks like I'll have to get the bread board out! can the simulation you have be exported?

I would like to run it for a longer time period as we will need the system to accept multiple triggers within 0.2s maximum i guess but normally within a second or so of the previous trigger.

#### SgtWookie

Joined Jul 17, 2007
22,210
Exported? Do you mean can it be sent overseas? This is a global forum....

Or did you mean export the netlist to something? It's not really that complex; just a switch, a couple resistors, and a capacitor with a simulated Schmitt trigger.

You can run it for as long as you like.

You might investigate some switch de-bouncing techniques.
Have a look at this pdf: http://www.eng.utah.edu/~cs5780/debouncing.pdf

#### HDAV

Joined Aug 21, 2011
43
When i try to run the simulation, i have voltage source "pulse" into the voltage controlled switch I get an error message Node 003 is floating? and something about SW (switch parameters?

Circuit: * C:\Program Files\LTC\LTspiceIV\Draft1.asc

Error on line 6 : s1 n001 n004 n002 n003 sw
Unable to find definition of model "sw"
WARNING: Node N003 is floating.

Direct Newton iteration for .op point succeeded.
Singular matrix: Check node n003
Iteration No. 1
Fatal Error: Singular matrix: check node n003
Iteration No. 1

This circuit has floating nodes.

By exported I meant can you send it to me please

Thanks for the Debounce link the device has built in debounce facility adjustable between 150us and 16ms

The
debounce time can be set for each available input separately.
Increment is 500 ns
Debounce time is set in Time x 500 ns
Minimum debounce time is 1.5 μs 3 x 500 ns
Maximum debounce time is ~16 ms (215-1) x 500 ns
Will this help? Or will using software debounce cause more issues due to the probably chaotic response of the switch?

Last edited:

#### SgtWookie

Joined Jul 17, 2007
22,210
I've attached the .asc file, which is the simulation.

#### Attachments

• 1.8 KB Views: 20

#### HDAV

Joined Aug 21, 2011
43
Thank you I think the issue i am having is modelling the the actual sensor output I need it to be 12V for short time period then 0V for long time period how does one model a Square wave like this?

Last edited:

#### SgtWookie

Joined Jul 17, 2007
22,210
Right-click on V2. A dialog will pop up.
You'll see that the PWL button is active on the upper left. PWL is short for Arbitrary Piece Wise Linear Source.

Down at the bottom, you'll see Time1, Value1, Time2, Value2, etc. At the very bottom you'll see a button labeled "Additional PWL points" - click that button.
Another dialog will open, and you'll see:
Rich (BB code):
Time  Value[V]
0        0
10m      0
11m      4.9
15m      4.9
16m      0
100m     0

Change the two 4.9's to 12, and the 100m to however long you want the simulation to run; if you specify time without qualifiers (like S, mS, uS, etc) the default time increment is seconds. If you want minutes instead, divide the number of minutes by 60 and enter that number instead.

You can add more times and voltages if you would like. You can change the shape of the waveform. You could create a very long list of times and voltage points in a text file, and use them for an input. You could even use a .wav file as an input if you have one. Using that feature is described in the HELP file. So is PWL, under V. Voltage.

#### HDAV

Joined Aug 21, 2011
43
Thankyou very much, I think I almost have it sorted just need an accurate model of the switch. Which we should be able to get.

Thanks Can you have alook at the attached for me and give me some feed back this simulation gives the desired effect but I'll have to put a more accurate model of the switch in when i get it. Could any of the components be removed? 3 isnt too bad but its 3 more than i would like.

#### Attachments

• 121.4 KB Views: 28
Last edited:

#### SgtWookie

Joined Jul 17, 2007
22,210
The .MODEL SW SW(etc.) is what contains the relevant switch parameters.
Ron is the ON resistance. Not knowing what your switch ON resistance is, I simply set it to 0.1 Ohms.
Roff is set to 99MEG, which I commonly use to indicate an open circuit; 99MEG is not a standard value of resistance, but it is a very high value nonetheless. You can't use infinity.

See the help file under "S. Voltage Controlled Switch" for all of the various options for the SW model.

You have the PWL statement kind of odd. Look at how I had it before. Now, you have it going to 12v @ time 0, then at 2mS down to 2mV, and then again at 2ms down to 0v. You should change one of the 2mS times to be slightly ahead or behind; it can't be two voltages at once. For example, change the 2m 2m to 2m 12v, and change the 2m 0 to 2.001m and 0.

You eliminated the 555, so you don't have a visual indication of the threshold trips anymore; and you don't have lines shown on the plot so it's difficult to judge just where the thresholds might be.

50nF is not a standard capacitor value. 47nF IS a standard value. I suggest that you stick with standard values in your simulations.

With the values you have, you will get about 30mS "1" output from the Schmitt trigger.

I re-drew your schematic in a more standard way.

If you want to eliminate components, go ahead - you'll wind up with what you have now; which is a system that is not reliable.

In my schematic, R1 protects the switch contacts. Apparently, your input is coming from an accelerometer. If you omit R1, then the accelerometer will see an instantaneous very high current draw as it charges the capacitor, which may damage it. With R1 being 10k Ohms, the peak current that your switch will see is 1.2mA, which will be very easy on the switch, prolonging it's life. If the switch is mechanical, without R1, the contacts will rapidly become pitted and as a result, have much higher resistance.

C1 can't be omitted, as that is what retains the charge.
R2 is what discharges the capacitor. Without R2, the cap might stay charged.

Now, I don't know what the input impedance is of your Schmitt-trigger; you will have to find that out, and you need to find out if the input tends to be pulled high, pulled low, or if it is floating.

You also need to make certain that the input from the accelerometer is either floating, or connected to 12v like I've modeled. If the input actually goes low instead, you will have to add a diode between the switch and the capacitor. Otherwise, the switch will discharge the cap just about as fast as it charges it.

#### Attachments

• 115.6 KB Views: 22