Building a flip flop with MOSFETs

Started by marcelomd, April 02, 2024, 02:23:39 PM

Previous topic - Next topic

marcelomd

Hi,

I'm trying to build a flip flop using MOSFETs.

This is what I've got:

Green is the input signal. Blue is left side drain. Red is right side drain.

This is to actuate an optical channel switcher I'm designing with solid state switches like TLP222, TLP240.

Reason I want to use MOSFETs, 2N7000 specifically, is because The other parts of the project use a bunch of them, so less inventory to deal with.

Is there a better way to do it? Driving the LEDs directly would be ideal.

If not, I guess I can use NPNs or a 555, but I really don't want to use a microcontroller.


Edit: Plot description

PRR

> Driving the LEDs directly would be ideal.

Does this work?


  • SUPPORTER

Rob Strand

Change your pulse to something like an actually switch instead of a square wave and you will find the flip flip isn't actually latching.  The MOSFETs are just switching.  eg.

PULSE(0 2 0 0.0001 0.0001 0.1 0.5 100)

You should be able to tweak your circuit and get it to work.  An alternative circuit would be something like a 2N7002 version of the circuit used by DOD - which has a floating switch and CD4007's.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

marcelomd

Quote from: PRR on April 02, 2024, 04:55:24 PM> Driving the LEDs directly would be ideal.

Does this work?




Works with one LED but I don't get the current I need. I need to turn 3 LEDs (2 optos + indicator) with a total voltage of +-4V and +-10mA.


Quote from: Rob Strand on April 02, 2024, 08:07:44 PMChange your pulse to something like an actually switch instead of a square wave and you will find the flip flip isn't actually latching.  The MOSFETs are just switching.  eg.

PULSE(0 2 0 0.0001 0.0001 0.1 0.5 100)

You should be able to tweak your circuit and get it to work.  An alternative circuit would be something like a 2N7002 version of the circuit used by DOD - which has a floating switch and CD4007's.

How do I do an actual switch in LTSPICE? With your PULSE command the MOSFETs really do act strange.

Yeah. I can do it with a 555 or a CD40xx type of thing. Just thought it would be trivial with a couple of transistors. Maybe not. Single transistors also take a ot of real state compared to an IC.

PRR

> I don't get the current I need.

How much current do you need? You can reduce the 10K resistors a lot. But multiple 2V-4V LEDs on 4V power is going to need something else.
  • SUPPORTER

marcelomd

TLP222's LED is 1.0-1.3V and needs 7.5mV+ to fully open the switch. That and a LED indicator. I need two per channel. I'm designing for 9V.


So, being conservative, in the worst case, I need 1.3 + 1.3 + 2 = 4.6 Volts at 7.5mA to fully actuate the channel selector. I couldn't get it directly with that specific configuration.

Rob Strand

#6
Quote from: marcelomd on April 02, 2024, 10:32:18 PMHow do I do an actual switch in LTSPICE? With your PULSE command the MOSFETs really do act strange.
What I've written is reasonable.  The main thing the new pulse command does is provide a short on time and a long off time.  That's more like what you do when you use a pedal.  It also lets you see the flip-flip isn't latching, which I had a suspicion was the case.  The square-wave gives a false impression things are working.  If the flip flop is working the output should toggle each time the switch is pressed and pretty much independent of the time the switch is held down.

Holding the switch down less than 20ms is going to be too fast.    I've got the switch down for about 100ms which should work and avoids overly long simulation times.  You can obviously set change the settings so the switch was down longer provided you make the period long enough but I think 100ms should show up the main problems.

The Boss circuit has a cap across the switch to remove some degree of switch bounce.

The behaviour of the MOSFET circuit should be fairly independent of load current.  However driving an LED directly, ie. without a drain resistor, could change the behaviour of the circuit due to the extra voltage drop.   You might need to keep a resistor from the drain to +V in parallel with an LED + current limit resistor.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

Baran Ismen

Out of my curiousity and illiteracy.

What's the use or advantage of flip-flop switching system compared to true bypass?

amptramp

Quote from: Baran Ismen on April 03, 2024, 03:01:57 AMOut of my curiousity and illiteracy.

What's the use or advantage of flip-flop switching system compared to true bypass?

The usual 3PDT switch is expensive and unreliable whereas a simple normally-open momentary pushbutton is cheap enough that the difference in price pays for the extra electronics and allows an extended warranty.

But there is another factor: the switchover in a 3 pole switch may occur at different times for each pole and the difference would be a pulse in the audio frequency range.  If you have an input connection that disconnects before the output connection, you may get an output glitch that you cannot control or mitigate by pulldown resistors.  If you get an output that connects before the input, you get a similar pulse unless the input is grounded when the unit is bypassed.  This can cause a qualification test problem.  If you build up a sample device and it works, a subtle change in switch manufacture may take a pedal that does not glitch and turn it into one that does.  And you generally have no control over this unless you commission the design of a switch with a guaranteed switching order.

With electronics, you can slow down the switching to the extent that the pop is not noticeable.  The output slides smoothly from the bypass signal to the effect output with no sudden change.

With an electronic system, you can initialize the switch so it starts reliably in the ON or BYPASS position whereas a mechanical switch remains in its last position.

True bypass can be a problem if you want to add remote switching.  Electronic switching is usually OK for that.

Delay or reverb functions present a particular problem.  If the pedal input is not connected to the incoming signal continuously, you will get a "gulp" where there is no output for a delay or a reverb output from the signal that was previously there for a reverb.

If you want to compare true bypass and electronic switching, here are the points in favour of true bypassing:

True bypass has some advantages and disadvantages as listed below:

Advantages

1.    Negligible signal distortion in bypassed mode
2.    Exact unity gain in bypassed mode
3.    Negligible frequency response deterioration, connected or bypassed
4.    Minimal noise addition
5.    Minimal interaction with effect circuit
6.    No power required for switch function
7.    No other circuitry required except switch pop reduction resistors

Disadvantages

1.    Expensive 3PDT alternate-action switch required
2.    Introduction of switch pops unless circuit modified
3.    Different behaviour depending on order of contact transfer
4.    Low reliability and life of switch
5.    Difficulty in adding remote switching capability
6.    Cannot be initialized on turn-on
7.    Advantages not necessarily applicable to delay functions
8.    Gritty feel to switch function unless you buy a big $$$ switch

duck_arse

" I will say no more "

R.G.

The cross-coupled 'flop circuit has tricky requirements about the voltage and current supplied to the bases of the transistors in the BJT version; in this version the gate voltage will have the trickiness involved.
The gates are driven from a resistor divider; the drain resistor, the drain-to-opposing-gate resistor, and the pulldown resistor. In your case, it's 1M+1M, so the gates both get only half of the voltage on the opposing drain, which is pulled up by a 10K.
For latching, you have to ensure that the opposing drain voltage gets high enough so the 1M+1M divider gives the driven gate more than its threshold voltage plus any enhancement for the worst-case current needs. The 2N7000 can have a gate threshold of as much as 3V, even though it's typically only 1.8-2.2V. That means you might have a limit of drain voltage needing to be no less than 6V to get 3V on the driven gate. Putting an LED in series with a drain needs a parallel resistor to pull the LED-side drain up when it's off.

Since the 2N7000 will be fine with higher voltages on its gate, you could increase your 1M-to-ground resistor up to something like 4.7M. That really reduces the voltage-divider effect on the gate drive, and should make for more reliable action with varying power supply voltages and loads.

One alternate solution to driving an LED that sidesteps some of the gate-voltage drive issues is to parallel a third 2N7000's gate and source to one of the 'flop's MOSFETs. This does not materially load down the flop, which should still work, but the added MOSFET now has an uncommitted drain that can pull down heavier loads and not interfere with the flop.

If you're using lots of switches as I think you are, you might consider using a CMOS hex inverter instead. A reliable toggle flop can be made from two sections of CMOS inverter, two resistors and a cap. There are circuits for this at geofex. This gets you three flops in a 16 pin package. If you can stand a floating switch (and I think your circuit can) then the two-inverter CMOS flop is as reliable as death and taxes, and can drive up to 25ma for most hex inverters, more for the CD4049.

Another side note; for evaluating circuit complexity on PCBs, count pins. Resistors and caps have two pins, transistors have three, and ICs have two more pins than the strict function. Add up the number of pins to evaluate which of two approaches will probably have the most/least PCB real estate and routing difficulty. Note that a hex inverter has two pins per inverter, plus 1/3 of a pin per inverter for its part of the power and ground pins. A two-transistor flop has six pins just on the transistors,  two pins on the drain resistors, then more pins for the Rs and Cs.
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

marcelomd

Some context about this project.

This bypass thing is part of my dual channel preamp.

The two channels are two completely separate circuits and don't share components. We've discussed switching options for it here

The idea I've got from those discussions is that I want to:
- select between outputs
- select between inputs
- ground the unused input
I can do that with a 3PDT, but there's no switch left for indicator LEDs.

So after sketching a few iterations I wanted to try full electronic switching. Plus I get a more reliable switch element. Plus I can waste time have fun designing it =)

This is the last version, with a CD4069 hex inverter:


Not sure what to do with the 3 spare inverters and that's why I thought about the discrete version. 2N7000s all around and one less different part to source.

Note that I added input and output buffers to deal with the impedance issues pointed in that second thread.

R.G.

Something kept nagging at me about the MOSFET flop so I fired up the simulator, and it came to me as I entered parts: pulse steering.
The original circuit has no way to steer the switch pulse to cause it to flip. I put in steering diodes and messed a bit, and it got very functional. Here's where I stopped:

These things work better if you steer the input pulse to turn on the currently-off device; it uses the gain of the currently-off device to help it flip. Diodes D1 and D2 do this. I rearranged the switch/pulse circuit to give a positive pulse to turn on instead of a negative pulse to turn off a device. It worked better with C3 increased. V2 and D3 fake a switch to +.
This worked down to trigger pulses of very short duration. An actual physical switch would need that capacitor to keep it from bounce-triggering.

On the hex inverter implementation - should work. You might consider changing to the CD4049 hex inverter, as I think the spare sections can replace those two discrete MOSFETs. The 4049 can sink up to 48ma of current on its output.
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

Rob Strand

I gave it a shot as well.

There's a number of variants of these circuits which appeared in old books and magazines.

The Boss circuit form doesn't seem to translate to MOSFETs so easily.  I might have a look at it another day.

One variant which does seem to work OK with MOSFETs is the following:

https://electronics.stackexchange.com/questions/563511/how-do-i-make-an-edge-triggered-t-flip-flop-using-integrated-injection-logic-i2



While it works in spice I can't stress enough you need to test these circuits on the breadboard.   The Boss circuit is has been used for years and has not shown any issues.

Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

R.G.

Yep, that looks good too. Steering diodes, and working from a pull-to-ground switch. Switches are best done by switching to ground, and I gave that up on my variant. I was a bit focused on not needing a second trigger capacitor.
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

Rob Strand

#15
Quote from: R.G. on April 03, 2024, 04:09:20 PMYep, that looks good too. Steering diodes, and working from a pull-to-ground switch. Switches are best done by switching to ground, and I gave that up on my variant. I was a bit focused on not needing a second trigger capacitor.
I couldn't get the Boss circuit to trigger with the MOSFETs.  The best I could do was get it to change state once.  That's when I went to the circuit which switches the pull-up resistors on the trigger caps as it forcefully steers the trigger pulse to the right MOSFET.  It seems quite robust. I found it doesn't need the resistors from the gate to ground and it works down to low voltages.  (I can't claim anything for that circuit since it's was just another common variant from the old days.)

I'm interested to see if the Boss flip-flop variant can be made to work.   Your circuit is a little closer but the puzzling thing is the diodes are flipped from the normal way it works.   On the Boss circuit the negative pulse on the bases turns a transistor *off* and that allows the other transistor to turn on.  For some reason that mechanism isn't working on the MOSFET version.   

I was suspicious it has got something to do with the lower switching threshold of the BJT.  I was going to set-up a MOSFET with a low threshold and see if that was the cause and take it from there to work back to the higher threshold.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

Rob Strand

#16
Quote from: Rob Strand on April 03, 2024, 06:24:19 PM
Quote from: R.G. on April 03, 2024, 04:09:20 PMYep, that looks good too. Steering diodes, and working from a pull-to-ground switch. Switches are best done by switching to ground, and I gave that up on my variant. I was a bit focused on not needing a second trigger capacitor.
I couldn't get the Boss circuit to trigger with the MOSFETs.  The best I could do was get it to change state once.  That's when I went to the circuit which switches the pull-up resistors on the trigger caps as it forcefully steers the trigger pulse to the right MOSFET.  It seems quite robust. I found it doesn't need the resistors from the gate to ground and it works down to low voltages.  (I can't claim anything for that circuit since it's was just another common variant from the old days.)

I'm interested to see if the Boss flip-flop variant can be made to work.   Your circuit is a little closer but the puzzling thing is the diodes are flipped from the normal way it works.   On the Boss circuit the negative pulse on the bases turns a transistor *off* and that allows the other transistor to turn on.  For some reason that mechanism isn't working on the MOSFET version.   

I was suspicious it has got something to do with the lower switching threshold of the BJT.  I was going to set-up a MOSFET with a low threshold and see if that was the cause and take it from there to work back to the higher threshold.

On the BJT version the trigger circuit (caps to bases) needs the CB junction diode needs to forward bias and clamp the cap trigger cap on the transistor that was on prior to the trigger pulse.  Without the CB diode clamp the transistor that was on will turn back on after the trigger pulse and the toggle mechanism is lost.

For the MOSFET version we can add gate drain diodes to emulate the BJT CB junction diodes.  However, that alone isn't the fix.  The MOSFET threshold needs to be low also.

If we step back at those fixes: both those changes are basically making the MOSFET do things the transistor does.  I don't see it as a solution.  It just shows there's things going on with the BJT version that aren't happening with the MOSFET version.

So the challenge is still out to work around those issues and get a nice clean Boss type circuit to work with MOSFETs.

[As a side note: despite all this the falling edge of this circuit isn't nice and clean and extends past the time where the /Q output rises.
 careful juggling of values helps but there's still some undesirable quirks.]
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

R.G.

Good intuitions there.

The whole "funnel the pulse to the one you're turning on" came from a circuits professor in about 1970. He was a veteran of designing transistor logic flipflops for the then state of the art discrete transistor computers. His viewpoint was that if you were trying to make it change state, turning off the "on" transistor required sucking down all of the base current from it. Feeding current to the currently "off" device let its current gain multiply the current being removed from the drive to the "on" transistor. He was a great believer in this.

With MOSFETs, gate current doesn't exist, so it's all about where you can pull the gate voltages, of course.  I wonder if the triggering would be easier if you made R1,5, 9 and 10 be ~1M.

The resistor-divider nature of the gate drives here also exposes a weakness of the cross-coupled flipflop; it is load sensitive. Put a load that is too low on one of the drains and it mucks up the voltage and current needed to latch up the other transistor. In the computer circuits of the day, you either had to hang additional buffers on the outputs or worry a lot about fan-in and fan-out limits.
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

Rob Strand

#18
Quote from: R.G. on April 03, 2024, 07:26:59 PMThe whole "funnel the pulse to the one you're turning on" came from a circuits professor in about 1970. He was a veteran of designing transistor logic flipflops for the then state of the art discrete transistor computers. His viewpoint was that if you were trying to make it change state, turning off the "on" transistor required sucking down all of the base current from it. Feeding current to the currently "off" device let its current gain multiply the current being removed from the drive to the "on" transistor. He was a great believer in this.
Perhaps the motivation [for off pulses] is to speed-up the switching process.  If the trigger removes base charge then the storage time is reduced naturally from the trigger pulse.

Quote from: R.G. on April 03, 2024, 07:26:59 PMWith MOSFETs, gate current doesn't exist, so it's all about where you can pull the gate voltages, of course.  I wonder if the triggering would be easier if you made R1,5, 9 and 10 be ~1M.
I didn't try every combination but in general there's a lot of scope to change the values provided you tweak other values to compensate.   At some point the resistors can get too high because then the MOSFET capacitances start to interact with the circuit more.

QuoteThe resistor-divider nature of the gate drives here also exposes a weakness of the cross-coupled flipflop; it is load sensitive. Put a load that is too low on one of the drains and it mucks up the voltage and current needed to latch up the other transistor. In the computer circuits of the day, you either had to hang additional buffers on the outputs or worry a lot about fan-in and fan-out limits.
Yes, you had to work hard in the bad old days!

Overall the circuit I posted earlier is far more robust and doesn't have any quirks.  Everything is forced to a good state.   I didn't spend much time adding speed-up caps across the drain to gate resistors.   I noticed the Boss style circuit has weird glitches on the falling edges.   They seem hard to fix.  Juggling the values helps remove glitches but the waveforms aren't entirely clean.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

PRR

Quote from: R.G. on April 03, 2024, 07:26:59 PM...The whole "funnel the pulse to the one you're turning on" came from a circuits professor in about 1970. He was a veteran of designing transistor logic flipflops for the then state of the art discrete transistor computers. ... ... ... In the computer circuits of the day, you either had to hang additional buffers on the outputs or worry a lot about fan-in and fan-out limits.

Economics usually/universally prohibited "additional buffers", so it was "worry a lot", do your sums, figure fanouts/ins. (My dad was there and I caught some of the angst.) The 2N404 and 2N396 were favorites because high and uniform beta.

As a general overlook of early triggering, see GE Transistor Manual such as here (15MB PDF!), section 7, print page 196 (PDF pg 208) (in 1964 edition). Also print pages 201-205 is a spreadsheet for desk-checking flip-flop performance against design specs (we don't do enuff of this today).
  • SUPPORTER