Electrical – D Flip-Flop as pulse detector

flipflopphototransistor

Background

For a while now I've been trying to come up with a simple module to handle modulated light detection for part of a laser trip sensor. Initial attempts I wanted to use a dual op-amp as an RC Oscillator and a comparator but could never get the circuit to work. Now while reading up on logic gates and flip flops I thought I could use those to accomplish the same this. Initially I thought it would use two JK flip flops and several logic gates but ended up finding something far more simple.

Question

Can I use nothing more than a D flip-flop to detect if the pulse I'm receiving is that same as the one emitted? Here is the circuit simulated in CircuitJS. A little bit of hand waving is required do to simplification and shortcomings in the sim but assume that clk is the PWM being fed into a MOSFET powering the laser diode and the switch represents a phototransitor either receiving the laser light while closed or the beam being broken when opened. The inverter is to trigger an interrupt on break.

Falstad circuit simulation

Best Answer

If I understand the question, take the "clk" to one input of an XOR and the phototransistor - suitably biased - to the other XOR input. When "in sync" the output will be zero most of the time, except for delay between the "clk" and the sensor. A low-pass, perhaps an RC, followed by a schmitt trigger will tell if the signals are "in-sync" most of the time or not. If the delay is a large fraction of the "clk" period, then other circuitry would be required.