Electronic – How to lengthen a short pulse

capacitormicrocontrollerpulse

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:
enter image description here
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.

Best Answer

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.

schematic

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.