Re: Cant figure this out. Edge triggered signals..need help
BlackHelicopter said:
1. Good question. I would program the delay counter to be less the time signal in is high, so signal out would always go low before signal in does.
2. I would like to have signal out high as soon as signal in goes high.
If you want maximum precision on your pulse timing, you should arrange things so that time can be measured using either rising or falling clock edges. I would expect that this could most easily be dealt with if you could use !signal_in as an asynchronous reset, which would mean that if signal_in went low before the timer expired the timing event would be canceled.
If you're not using a logic family which allows double-edge flip flops, , I would suggest having a couple of flip flops which are asynchronously reset by !signal_in, fed a continuously-high data signal, and triggered by rising edge and the other by falling edge. The outputs of these should drive active-low R and S inputs of an RS flip flop (initially, when signal_in is high, both R and S should be active; one will be inactivated, then the other). The input clock should be XOR'ed with the output of this flip flop, and the output of that XOR should be ANDed with the outputs of the two initial latches, and that used to drive the counter.
Thus, if signal_in rises when clock is high, the sequence of events would be:
Initially both flip flops are clear, the RS output is don't-care, and the clock to the counter would be low.
Next the clock would fall, the falling-edge flip flop would be set, the RS output would be clear, and the counter clock would be low (because of the AND gate).
Next the clock would rise, both flip flops would be set, the RS output would still be clear, the XOR output would rise, and the counter clock would rise (since both flip flops and the XOR output would be set).
From thence forth, every clock edge would generate a clock edge to the counter.
If signal_in falls rises clock is low, the sequence of events would be:
Initially both flip flops are clear, the RS output is don't-care, and the clock to the counter would be low.
Next the clock would rise, the rising-edge flip flop would be set, the RS output would be set, and the counter clock would be low (because of the AND gate).
Next the clock would fall, both flip flops would be set, the RS output would still be set, the XOR output would rise, and the counter clock would rise (since both flip flops and the XOR output would be set).
From thence forth, every clock edge would generate a clock edge to the counter.
The clock fed to the counter would be completely clean; the only potential race condition or setup/hold violation would be the rising edge of signal_in relative to a clock edge. In that scenario, one of the flip flops might go into a metastable state. Since the clock output can't start until both a rising and a falling clock edge have been seen, there would be no problem provided the metastable state resolves itself before the next clock edge. If the metastable flip flop resolves high, the counter would start cleanly half a cycle sooner than if it resolves low.
One thing to watch out for is to ensure that the RS inputs are chosen correctly, so that the output of the XOR has its rising edge when the second clock edge arrives. If the output of the XOR has its falling edge then, a runt clock pulse could be generated since one input to the AND would be rising while the other was falling.