An optimal input circuit for an optical sensor?
Here's what I have:
The opto-coupler simulates (very roughly) the TCST2103 optical sensor.
My goal is to accurately measure the pulse frequency. The Q MOSFET's gate represents the MCU GPIO input. The 1M resistor represents the input resistance.
I wonder if 2k2 pull-up resistor isn't a bit too low. It makes a voltage divider with the input resistance, and the input resistance is AFAIK "undefined" / very high. Theoretically - it shouldn't matter. Practically - if we left the MOSFET input without a very weak pull-down, it could dwell in high state in case of the input pin floating. Also, I'm not sure if the higher this pull-down resistance is - the more the internal capacitance of the input matters, creating a low-pass filter. Finally, I'm not sure what really lives in the STM32 chip. Bare MOSFET's gate, or is there a high value resistor?
Guessing like 100k input resistance 2k2 pull-up provides negligible voltage drop. Are there any disadvantages of it beside the power consumption? I've seen similar input circuit with 10k pull-up, but 5V power supply. Also 10n blocking capacitor in parallel. In my simulation 10n introduces some ugly voltage spikes that would trigger spurious edge detection on MCU. In fact - I observe it really does it. With the capacitor I get spurious edge detection, when the capacitor is removed, it works properly.
However - I probably should have a blocking capacitor, but not of such high value. On the simulation 33p works great, also - in the real circuit I get correct readings. So - should I leave the 33p or maybe it's safe to remove it?
BTW, the measured signal is 20Hz to 200Hz dirty square with like 5% duty cycle, inverted, so it's low when the sensor is lit.
