A flaw in Photodetector circuit?

Thread Starter

dettol

Joined Jun 30, 2021
9
Situation:
I've designed a photodetector circuit for my high speed chronograph.
The basic idea is two infrared gates connected to a dual analog comparator (LM393) with outputs connected directly to ESP8266 microcontroller (GATE_1, GATE_2). The Microcontroller measures time difference to get velocity of projectile. Simple stuff right?
Turns out not so much, I'm just an electronics hobbyist, most circuit diagrams and datasheets are way over my head.

The problem:

I've built the following circuit and got a PCB fabricated. Upon assembly I noticed that that one of my gate (GATE_1) outputs gets activated rapidly itself. I accidently pressed my thumb against the microcontroller and noticed that the pin stopped flickering and settled down but still worked when I shot a projectile. Then I narrowed it down to an unrelated pin on the microcontroller, a pin that isn't even connected to anything. I'm very puzzled.

Alas, I post here in hopes of wiser folk can spot errors in my design. Thank you.


PS: I should probably mention, there is a DC DC step booster on my PCB that is switched off to help narrow down the problem.
 

Attachments

MrChips

Joined Oct 2, 2009
30,708
Did you remember to put 100nF ceramic capacitors from 3V3 to GND across each IC and one 10μF electrolytic capacitor on the board?
 

Thread Starter

dettol

Joined Jun 30, 2021
9
Yes. Im powering the board with a LiIon, regulated with AMS1117. I've put 10uF ceramic SMD on the v inputs and v outputs. I've not put a 100nF, why would I put such a little capacitor if I have a 10uF and 100uF?1625131494006.png
 

Alec_t

Joined Sep 17, 2013
14,280
Welcome to AAC!
Then I narrowed it down to an unrelated pin on the microcontroller, a pin that isn't even connected to anything.
If you have any pins configured as inputs they should never be left floating. They need pull-up or pull-down connections/resistors (which might be internal to the MCU and would require enabling). Floating inputs can pick up EM interference, resulting in weird effects.
 

MrChips

Joined Oct 2, 2009
30,708
One would think that 0.1μF in parallel with 10μF would give 10.1μF?
Not so fast.

The tolerance of the larger capacitance exceeds the smaller value to make the latter insignificant.

The two capacitors have very different frequency responses. They suppress noise over different frequency ranges.
 

Thread Starter

dettol

Joined Jun 30, 2021
9
That's interesting, I'll give that a go when Im at home. I would appreciate any resource that explains frequency response for different capacitors, that's new to me. But conceptually, is the photodetector circuit correct fine or does it also need some capacitor filtering? Thank you all for contributing.
 

Thread Starter

dettol

Joined Jun 30, 2021
9
So I added the capacitors and I didn't see any changes. Still flickers. I started adding 100nF caps to R7 and R8 and that actually helped a little bit. Then I adjusted the potentiometer and the flickering continued. Could it be that my potentiometer (soldered smd) is jittering and causing the comparator to flip states?
 

BobTPH

Joined Jun 5, 2013
8,809
Did you set all unused inputs to be outputs? A floating input can definitely cause problems in a microcontroller. It might or might not be causing this problem.

Bob
 

Thread Starter

dettol

Joined Jun 30, 2021
9
Did you set all unused inputs to be outputs? A floating input can definitely cause problems in a microcontroller. It might or might not be causing this problem.

Bob
I have, I set every unused pin to OUTPUT including Serial pins. In fact, PIN 3 (used for UART RX) that I push with my thumb stops the flickering behaviour on a dime. So I experimented and set that pin to all combinations of pull ups, downs, open drain to make sure it stays low. None of them worked. I placed a piece of wire shorting the pin to ground (in input mode ofc) and that does seem to fix. What does any of this mean?

Have you tried putting a smoothing capacitor from VOLTAGE_COMP to GND?
I placed a 4.7uF and a 100nF ceramic on VOLTAGE_COMP to GND. Didn't make a difference unfortunately.
 

Thread Starter

dettol

Joined Jun 30, 2021
9
I soldered a tiny ceramic cap between GPIO3 and GND and that seems to fix the issue. I have no idea why, I guess this is where the limit of my electronics knowledge comes in. I'm still able to use the GPIO3 pin (and RX1) to program the ESP.
 

Thread Starter

dettol

Joined Jun 30, 2021
9
It is is set to output, I see no way that touching it will have any effect.

Bob
Hmm, I'm starting to think this might have something to do with the rest of my circuit. I have a dc-dc boost converter that generates a voltage of ~15V. I followed the datasheet application diagram. The Vout voltage is used for led illumination and is activated when the projectile passes between the gates.

1625153607559.png
 

Thread Starter

dettol

Joined Jun 30, 2021
9
Hi guys, I figured it out. The problem turned out to be WiFi. I'm guessing there is a lot of rf interference because when I switched the wifi off the flickering stopped altogether. I dont know much on the subject but small voltage may be induced into one of the traces causing the analog comparator to detect a change. This caused the gate to trigger. I might need to redesign the pcb with rf in mind, any good starting points for me?
 

Thread Starter

dettol

Joined Jun 30, 2021
9
I thought it'd help the next person if I screencapped my pcb traces. The big empty square in the middle is where the wifi antenna lies. The gate_1 trace is the one running from D13 along the left side of the board. It's situated right next to a 3V3 trace and wifi antenna. I soldered a wire from my LM393 comparator to D13. Presently it appears to have fixed my issue with WiFi running. For any other hobbyists also running WiFi in a compact pcb, be mindful of where you put your traces!


1625217477618.png

A quick thanks to the people in this thread, certainly learned new things!
 
Top