# D Flip-Flop as pulse detector

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.

• You just want to capture high going pulse when Photo-transistor stroked by light?, can you please tell me simple behaviour what you want? – Prakash Darji Mar 29 '16 at 8:14
• No, I want to capture if they are in phase together. When just detecting if it's high vs. low other light causes interference. – Morgan ARR Allen Mar 29 '16 at 8:18
• means posedge of PWM clock and ON SWITCH perform at same time, you want to capture that condition. right? – Prakash Darji Mar 29 '16 at 8:25
• "I've been trying to come up with a simple module to handle PWM detector for part of a laser trip detector." Your introduction is unclear. What do you mean by "PWM detector" and "laser trip detector"? "... detect if the pulse I'm receiving is that same as the one emitted". Why wouldn't it be? What is the context of your question? i.e. What are you making? – Transistor Mar 29 '16 at 12:29
• Two problems. Firstly the input appears to be floating when the "transistor" is off, which may cause you to get weird results. Secondly and more critically, you are highly likely to violate the setup/hold times of the register which can make the output go metastable (be in both states at once, or oscillate between the two). – Tom Carpenter Mar 31 '16 at 7:13