# How to lengthen a short pulse?

i'm building a shot counter circuit for my airsoft gun controlled by an ATtiny26L MCU, where the shots are detected by an infrared diode + phototransistor couple. The PT outputs positive signal when it's triggered by the IR LED, which goes into a PNP transistor to invert the signal and then I have an electrolytic 1uF cap to lengthen the pulse, a 100k pull down resistor (initially there was a 1k), and a 1k resistor to regulate the output current to lenthen the cap's output: The circuit works flawlessly when I block the IR diody by hand or drop a BB through the detector. However if I shoot a BB through it doesn't detect it.

The shot BBs trigger the detector for around 70 microseconds and if i'm correct there shouldn't be any trouble with a such big cap as 1uF lengthening the pulse, but maybe i'm doing something wrong? Or perhaps the phototransistor won't get triggered in such small time?

Also my MCU runs at 1MHz.

I'm glad to hear any tips.

• Why do you need a longer pulse? Are you polling the pin to see when it changes state? If so you could use an edge-triggered interrupt instead. In fact I'd be surprised if you couldn't configure your MCU to use the pulse to clock one of its internal hardware counters directly... – brhans Apr 7 '16 at 20:57
• @brhans I'm still new to MCUs, i didn't know you can set up an interrupt based on an input pin. – DELTA12 Apr 7 '16 at 22:08

Your positive-going signal from the opto-sensor will turn off Q allowing C to discharge through R. With 100k/1u you have a time constant of 0.1s so the voltage will hardly budge in 70 us.

simulate this circuit – Schematic created using CircuitLab

Figure 1. Quick discharge of capacitor.

The circuit of Figure 1 may behave better.

• When the photo-transistor pulse goes high it will turn on Q1 which will discharge C1 instantly.
• When PT turns off, Q1 will turn off and C1 will charge up via R2. The time constant $\tau = RC = 10^5 \cdot 10^{-7} = 10^{-2} = 10~ms$ should do the trick if your micro is polling at a reasonable rate.
• I still don't quite understand how this would work, the PT has a positive output when the signal is negative. When Q1 turns off (the signal is positive), for 70μs it produces a short pulse, charges the cap but then it goes back to open and flushes the whole system without lengthening anything – DELTA12 Apr 7 '16 at 21:16
• Both of us may be confused. I read your question as saying that the opto pulse is a positive pulse for 70 μs and then goes back to 0 V. Note that I've changed the transistor to NPN. The capacitor is normally charged to +3 V. The opto pulse discharges it quickly and it slowly charges back up via R2. This does invert the logic but this should be easily sorted in the MCU code. Let me know if I've misunderstood something. – Transistor Apr 7 '16 at 21:22
• @DELTA12 The key point is that 70 microseconds is a short period of time, and you have a pretty big capacitor. I don't understand why you need to stretch the pulse at all, though. – Adam Haun Apr 7 '16 at 21:46

I would use mono-stable multi-vibrator for that.

simulate this circuit – Schematic created using CircuitLab

The time it will stay in "triggered" position is: $$t = ln(2) R_3C_1$$ You can find more on this topic here

• ... or spend the \$0.65US on buying the chip. – Scott Seidman Apr 7 '16 at 20:54

As others have said, you probably don't need to actually stretch the pulse, but if you want to, here is a very easy method- use a 74HC123 retriggerable multivibrator:

You can pick Cx and Rx to get whatever pulse width you want, on whichever edge you like and pick either Q or /Q for regular or inverted output.

They in duals in various packages (DIP if you like), for less than 50 cents ea.

Edit: If you needed to stretch an extremely brief pulse, there are variants such as the 74VHC123A which are much faster, but it's not necessary here.

• @tcrosley Sure, I'll delete my comments. No sense leaving junk out there. – Spehro Pefhany Apr 8 '16 at 0:32