I've simulated a circuit in spice depicted below. The Vin voltage source (on the right) outputs a 100mV pulse every 2 microseconds, and the other voltage source (on the left) is a square wave that alternates between 0V and +1V. The idea is that when the square wave goes high, the transistor should turn on and cause Vout to equal zero, and when the square wave goes low, the transistor should turn off and cause Vout to equal Vin.
Here are 3 traces I recorded, depicting Vin, the square wave, and Vout:
While the circuit is mostly behaving the way I expected, there is a large unwanted voltage spike at Vout that appears whenever the square wave has a rising edge or a falling edge (appearing at 0us, 4us, and 8us). My main question is, what phenomenon is causing these voltage spikes to appear at the output? Is there a name for this phenomenon? And more importantly, what can I do to get rid of it?
Would using a different type of bjt help? I have tried that but it didn't change much. I also tried using a mosfet instead of a bjt, but the voltage spikes were still appearing. Would a mosfet be more appropriate for this type of circuit?
I did notice that putting the square wave through a low-pass filter makes the voltage spikes smaller, but doesn't completely remove them. If I try it (by adding a 1nf cap at the BJT base), this is the result:
Does anybody know if there are other solutions that would work better?