How to switch a transistor between gnd and floating?

Ron H

Joined Apr 14, 2005
7,063
Here is a major redesign. it seems to work well, and I think is more "solid" than the discrete design we were working on, especially the current sense circuit.. The timing on the input current source and the pushbutton switch are just for simulation purposes.
Your TL431 circuit was only putting 2.5V on the comparator. I changed it to 5V. You don't need that NPN with the TL431.
I also simplified the switch that turns on the battery charger.

The current sense amp has a gain of 20V/V, so with 15mA and 26mA, the sense amp output levels are 15mA*8.2Ω*20=2.46V, and 26mA*8.2Ω*20=4.26V. The sense resistor was chosen to keep the output below 4.8V, which is the AD8211's maximum output voltage. U1b slices the sense amp's output ≈halfway between the 15mA level and the 26mA level to drive the relay and set the FF. U1c slices ≈halfway between 15mA and 0mA to reset the FF when the pushbutton is pressed.
Note that all the comparators have power pins. This is only for simulation. The actual IC is a quad comparator, LM339, and only has one set of power pins.
The CD4001 power pins don't show, but it is a quad NAND gate, and only has one set of power pins (Vcc and GND).

LTspice is free, and is not castrated like student or demo versions of commercially available simulators. It is very powerful, and when you get good at using it, you can add models from IC mfrs, create new symbols, etc. The learning curve is pretty steep.
A simulator should NOT be used to "design" a circuit. If you don't understand circuit design, a simulator will probably lead you astray. I use it to verify my designs, and to help me discover subtle "gotchas" which I might have missed.
 

Attachments

Thread Starter

tpny

Joined May 6, 2012
220
thanks Ron for the redesign! I'll be sure to spend some time poring over it. Just some quick observations:

1. Why did you use a fet at the switch on the left?
2. Notice that cmos components don't need resistors around them like bjt ones.. I like that..
3. Your voltage divider off of the 5V reference uses large resistors so current on the path is about 10uA. Is that a good current size for voltage references?

Thank you!!!
 

Ron H

Joined Apr 14, 2005
7,063
thanks Ron for the redesign! I'll be sure to spend some time poring over it. Just some quick observations:

1. Why did you use a fet at the switch on the left?
On further reflection, the FET doesn't help, but the NPN circuit that you had needs some tweaking.
Does your switch contact closure have to be to ground, i.e., are you planning on replacing it with a logic signal in the future?
The PNP (Q2 in my latest schematic) ideally would have Ib≈2.6mA, to ensure saturation. This is a big waste of current. Q2 would ideally be a p-channel MOSFET, which has no gate current. Are you interested in pursuing that?
2. Notice that cmos components don't need resistors around them like bjt ones.. I like that..
3. Your voltage divider off of the 5V reference uses large resistors so current on the path is about 10uA. Is that a good current size for voltage references?

Thank you!!!
You can't generalize about a "good current size for voltage references". It depends on the bias current of the comparators, and how much precision is required. LM339 bias currents are less than 0.25uA, and in this case, little precision is required, so 10uA through the divider is fine.
 

Ron H

Joined Apr 14, 2005
7,063
I just realized that AD8211 requires almost 1mA into each input, which is probably too much at the low currents you are running. I'm looking into a better solution.
 

Thread Starter

tpny

Joined May 6, 2012
220
On further reflection, the FET doesn't help, but the NPN circuit that you had needs some tweaking.
Does your switch contact closure have to be to ground, i.e., are you planning on replacing it with a logic signal in the future?
no it doesn't have to be, the switch is to cutoff pnp so as to open circuit the current loop (as a 0mA signal back to sender). I changed the switch circuit to something simply in the attached schematic.. I've already soldered 3 boards using this design (I know it's shakier than your redesign but must turn something in..). I'm just worried when the user depress the pb, will the momentary current drop to 0mA reach back to the sender which is connected by the 2-wire current loop 500 meters away or 1km round trip.. Should I put a time delay on the switch so that a short depress and release translates to a second of 0mA? ...

The PNP (Q2 in my latest schematic) ideally would have Ib≈2.6mA, to ensure saturation. This is a big waste of current. Q2 would ideally be a p-channel MOSFET, which has no gate current. Are you interested in pursuing that?
ya, fet sounds like an improvement since current is fixed at 15mA and needs as much of that as possible to flow to the battery for charging.
 

Thread Starter

tpny

Joined May 6, 2012
220
I just realized that AD8211 requires almost 1mA into each input, which is probably too much at the low currents you are running. I'm looking into a better solution.
How did you figure it needs that much.. I don't see it in the datasheet? What should I be looking for? Input bias current?

By the way, can it work with a vanilla op amp instead of a specialized one for current sensing? I would think taking the voltages from 2 ends of the current sense resistor and amplifying difference might give us just that?...
 

Thread Starter

tpny

Joined May 6, 2012
220
coil draws 50mA, load on the relay draws 0.5A. I'm not too confident about the flip flop transistor section, I have to test it out more extensively but I might have noticed the led goes on/off without trigger sometimes..
 

Ron H

Joined Apr 14, 2005
7,063
How did you figure it needs that much.. I don't see it in the datasheet? What should I be looking for? Input bias current?
I saw it in a simulation. It might be a flaw in the spice model.

By the way, can it work with a vanilla op amp instead of a specialized one for current sensing? I would think taking the voltages from 2 ends of the current sense resistor and amplifying difference might give us just that?...
The problem with that is, you need precision resistors.

Have a look at the attached snippet of your schematic.
 

Attachments

Thread Starter

tpny

Joined May 6, 2012
220
yes, the 5v reference is taken at the npn emitter, my bad on the schematic, again.. (i've been swamped with workload lately...).

I put a 1k there because when the battery is not charging (comparator toggles out..), I thought I needed to direct the 15mA on the loop thru some load to use it up... otherwise, the voltage on the loop might drop to below 12V... That was the logic, I don't know if it is substantiated...
 

Thread Starter

tpny

Joined May 6, 2012
220
sorry, was away for a while.. attached is schematic for sender of current loop.

By the way, why can't I just put a bigger resistor for current sense (at the receiver circuit) instead of using an amplifier to boost the voltage difference?..
 

Attachments

Ron H

Joined Apr 14, 2005
7,063
sorry, was away for a while.. attached is schematic for sender of current loop.

By the way, why can't I just put a bigger resistor for current sense (at the receiver circuit) instead of using an amplifier to boost the voltage difference?..
You can do that. How do you get from the larger sense voltage to switching the flip-flop and the relay?
I came up with a good current sense circuit, but it requires a special op amp that costs several bucks, so I haven't posted it. Plus, I thought maybe you were finished.
 

Thread Starter

tpny

Joined May 6, 2012
220
Same way as we had with the pnp collector sourcing out the current to the flip flop and relay transistors... How would the amplifier improve things? Thanks!

Yes, I've turned this project in but am still interested in making improvements. Would love to see your current sense circuit rework!
 

Ron H

Joined Apr 14, 2005
7,063
Same way as we had with the pnp collector sourcing out the current to the flip flop and relay transistors... How would the amplifier improve things? Thanks!

Yes, I've turned this project in but am still interested in making improvements. Would love to see your current sense circuit rework!
If you use the PNP current sense circuit with a bigger resistor, the PNP will only be off when the current is zero. You won't be able to detect the 26mA pulses.

Here's my redesign. The LT1637 is an over-the-top op amp, meaning its will work when the input voltages are above the supply voltage. Other op amps do not have that capability. Neither do most current sense amps, although some do.
Keep in mind that the waveform of the current source on the left side is only for simulation purposes.
 

Attachments

Thread Starter

tpny

Joined May 6, 2012
220
Q1. How does the pnp sense circuit compare to the op amp sense circuit?
Q2. What's the function of c3? Why 470p?
Q3. Why use pnp Q2? Why can't it just drive from the output from op amp directly?
 

Ron H

Joined Apr 14, 2005
7,063
Q1. How does the pnp sense circuit compare to the op amp sense circuit?
The simple PNP circuit does not have much gain, so separating 15mA from 26mA is tricky, and is temperature sensitive (Vbe decreases by ≈2mv/°C).
Q2. What's the function of c3? Why 470p?
There is a current spike that couples from gate to drain on M1 when it switches. This caused a voltage spike at the collector of Q2, which is filtered by the 470pF cap. Less than 470pF does not adequately filter the spike. More will slow the rise and fall times, which could be OK.
The spike may go away if you slow down the rise and fall times on the gate. I have them pretty fast, for simulation purposes.
Q3. Why use pnp Q2? Why can't it just drive from the output from op amp directly?
You have to understand that negative feedback around an op amp forces the -input to follow the + input (+in minus -in ≈ 0V). This feedback makes the voltage across R10 equal the voltage across R13. Thus, the current through R10 is proportional to the sensed current, only much lower. In a BJT (Q2, in this case), Ic≈Ie. Therefore, the voltage at the collector of Q2 will be
Vc2≈Isense*(R13/R10)*R21=Isense*(8.2/10k)*200k=Isense*164.
When Isense=0, Vc2=0.
When Isense=15mA, Vc2=2.46v.
When Isense=26mA, Vc2=4.26v.

There is no way to use the op amp output directly, unless you make a true difference amplifier, with four ≈0.1% tolerance resistors.

Here is an app note you might like.
 
Last edited:

Thread Starter

tpny

Joined May 6, 2012
220
The simple PNP circuit does not have much gain, so separating 15mA from 26mA is tricky, and is temperature sensitive (Vbe decreases by ≈2mv/°C).
Assuming temperature sensitivity is not an issue, is an appropriately sized sense resistor (e.g. 22ohm from your 1st redesign) good enough for this purpose?

You have to understand that negative feedback around an op amp forces the -input to follow the + input (+in minus -in ≈ 0V). This feedback makes the voltage across R10 equal the voltage across R13.
I'm not seeing this.. If voltages at +input and -input are the same, how is voltage across R10 = voltage across R13? What about R20 which sits on the same path in front the +input?..

Thus, the current through R10 is proportional to the sensed current, only much lower. In a BJT (Q2, in this case), Ic≈Ie. Therefore, the voltage at the collector of Q2 will be
Vc2≈Isense*(R13/R10)*R21=Isense*(8.2/10k)*200k=Isense*164.
I'm sorry I don't understand how (R13/R10)*R21 comes about? Could you elaborate on that a little? Thank you so much!!
 

Ron H

Joined Apr 14, 2005
7,063
Assuming temperature sensitivity is not an issue, is an appropriately sized sense resistor (e.g. 22ohm from your 1st redesign) good enough for this purpose?
I've got yet another design that you might like. The low current through the sense PNP is not a problem, because it doesn't have to drive 5.5mA into the base of the relay switching NPN. This also eliminates a lot of resistors, and the MOSFETs are available from Jameco for CHEAP! See attachment.


I'm not seeing this.. If voltages at +input and -input are the same, how is voltage across R10 = voltage across R13? What about R20 which sits on the same path in front the +input?..
The input currents to an op amp are generally very low, and virtually identical, so the voltages developed by those currents are low, and they cancel each other out, because R10=R20. Having said that, this is a poor design. I was so enamored of the over-the-top capability (+in and -in both>vcc) that I failed to notice that the input bias current goes WAY up in this mode, and the input offset current is of the same order as the current into the output resistor, making the output error potentially large. Let's forget that design. It would work well if your sense current was MUCH higher.

I'm sorry I don't understand how (R13/R10)*R21 comes about? Could you elaborate on that a little? Thank you so much!!
I hope I explained this in the previous paragraph.
 

Attachments

Thread Starter

tpny

Joined May 6, 2012
220
I've got yet another design that you might like. The low current through the sense PNP is not a problem, because it doesn't have to drive 5.5mA into the base of the relay switching NPN. This also eliminates a lot of resistors, and the MOSFETs are available from Jameco for CHEAP! See attachment.
But your previous design (with positive feedback to the pnp) is also ok right? Since you did assign 5mA going into the base of the relay npn to turn it ON..

I like the fet design, less resistors and no current is wasted on switching the transistors ON.. Which leads me to think: if I'm using the transistor strickly as a switch, choose fet over bjt
 
Top