Transistos as a switch but with variable sine wave voltage on the base

Thread Starter

Dariodario

Joined Apr 6, 2019
14
Hi to all.
I need to transform a sine wave to a square wave to be counted by a micro. The supply voltage can be 5V or 12V
The sine wave is variable from 0.5V peak-to-peak to 50V peak-to-peak, maximum frequency 50 kHz.

At the begin I started to play with a comparator LM311, after I made a circuit with a BC547 as switch and some resistors to work in the saturation zone, and all is OK: with low voltage sine wave from 0,65V p-p to 1,5V p-p, I read the 5V square wave on the BJT collector.

My problem is that the circuit should manage also voltage more than 1,5 V, up to 50 Volt p-p.
In fact now I calculated the base resistor with a reference of 1,5V at the input and the related base current. On the other hand if I would calculate the base resistor for 50 volt, then when the sine wave is 1 volt p-p maybe the base current is not enough to bring in saturation the transistor.

Until now I solved half problem clamping with two diodes (one to ground and one to +5) the base maximum voltage to -0.7 (on the lower sine) and +5.5 (on the upper sine) when the sine voltage is>5V.

Any idea?
Thanks a lot.
 

ian field

Joined Oct 27, 2012
6,536
Hi to all.
I need to transform a sine wave to a square wave to be counted by a micro. The supply voltage can be 5V or 12V
The sine wave is variable from 0.5V peak-to-peak to 50V peak-to-peak, maximum frequency 50 kHz.

At the begin I started to play with a comparator LM311, after I made a circuit with a BC547 as switch and some resistors to work in the saturation zone, and all is OK: with low voltage sine wave from 0,65V p-p to 1,5V p-p, I read the 5V square wave on the BJT collector.

My problem is that the circuit should manage also voltage more than 1,5 V, up to 50 Volt p-p.
In fact now I calculated the base resistor with a reference of 1,5V at the input and the related base current. On the other hand if I would calculate the base resistor for 50 volt, then when the sine wave is 1 volt p-p maybe the base current is not enough to bring in saturation the transistor.

Until now I solved half problem clamping with two diodes (one to ground and one to +5) the base maximum voltage to -0.7 (on the lower sine) and +5.5 (on the upper sine) when the sine voltage is>5V.

Any idea?
Thanks a lot.
A starting point is to clip the sinewave with an inverse parallel pair of diodes, but that is equal to the Vbe of the transistor that produces the pulse train. A comparator can switch as the input goes over and under a reference point. 2 pairs of diodes gives 2 Vf and enough voltage to put current into the base of a switching transistor.
 

crutschow

Joined Mar 14, 2008
34,464
Below is the LTspice simulation of an LM339 or LM393 circuit for inputs of 0.4vpp and 50vpp.
(The LM311 is not recommended for this, since it's input range does not extend all the way to the negative rail, which is ground in this circuit).
R5 provides a small amount of hysteresis to prevent oscillations at the transition point.
The diodes clamp the high voltage to prevent damage.
The diodes should be Schottky types since the LM339/393 inputs can be sensitive to voltages that go more than 0.3V below ground.

upload_2019-4-10_14-22-36.png
 

ian field

Joined Oct 27, 2012
6,536
Below is the LTspice simulation of an LM339 or LM393 circuit for inputs of 0.4vpp and 50vpp.
(The LM311 is not recommended for this, since it's input range does not extend all the way to the negative rail, which is ground in this circuit).
R5 provides a small amount of hysteresis to prevent oscillations at the transition point.
The diodes clamp the high voltage to prevent damage.
The diodes should be Schottky types since the LM339/393 inputs can be sensitive to voltages that go more than 0.3V below ground.

View attachment 174695
I'd go for a window comparator - there's a ready made one in the 555. its worth looking over zero crossing detector modifications to standard bridge rectifier setups for additional insights, but it depends on what the TS set out to do.
 

Thread Starter

Dariodario

Joined Apr 6, 2019
14
Thanks for your answers. Since I need to put this circuit along other stuff in a fabricated PCB, at the moment I would leave open both the solutions. My decision will be based on the circuit reliability with time (aging, temperature), cost, and so on.

1. The transistor as switch. I made and simulated this simply circuit with 6 volt pp input, filtered, with 10Hz input and it seems to work well with 0,35 mA as Ib. I don't know if 0,35 mA is too much for the transistor in terms of dissipation:

upload_2019-4-11_19-30-48.png

Here with 1V pp as input. The transistor just appen to switch due to Vbe and the low current Ib:
upload_2019-4-11_19-52-58.png

I can still lower the Voltage input a bit, not below the Vbe if I'm not wrong. The problem here is that I cannot deal with inputs below 0,8-0,9 V (and I don't know how to deal with some output spurious due to this borderline values) but I could add an offset by impose 5 volt to the input signal (but this is another circuit!). So what do you think about the resistors values and related currents?

2) comparator LM339/393. Crutschow thanks a lot for the simulations you done. Your Vref voltage is around 100mV so the circuit should work in the reality with my requirements. I cannot simulate the circuit with my Qucs simulator because I don't have the correct library (only op-amp). Maybe I can simulate it with TINA-TI but I have no knowledge about it. Thanks.
 

crutschow

Joined Mar 14, 2008
34,464
What do you think about the BJT base current in the circuit above between minimum and maximum input? Thanks.
You need to reduce the input resistance so that you get the desired output signal at your lowest desired input, but have enough resistance so that the maximum rated base input current (given in the data sheet of the actual transistor you will use) is not exceeded at the maximum voltage.
 

Thread Starter

Dariodario

Joined Apr 6, 2019
14
You need to reduce the input resistance so that you get the desired output signal at your lowest desired input, but have enough resistance so that the maximum rated base input current (given in the data sheet of the actual transistor you will use) is not exceeded at the maximum voltage.
I see, I can calculate the "right" switch current with the classical formula. What I don't know is the allowed range of current that the BJT can manage, the maximum allowed in this case. I consider the formula Ib result as the minimum.

About the comparator, I found that here https://e2e.ti.com/support/amplifiers/f/14/t/718309?LM393-replacement:
upload_2019-4-12_0-45-2.png

So it seems that LM393 is not a rail-to-rail comparator, this mean I cannot reach the supply voltage as in the circuit provided?
Regards.
 

crutschow

Joined Mar 14, 2008
34,464
What I don't know is the allowed range of current that the BJT can manage
As I stated in post #12, that is given in the data sheet for the actual transistor you will use.
If it's not explicitly given, I would use a value of no more than about 10% of the maximum rated collector current.
So it seems that LM393 is not a rail-to-rail comparator, this mean I cannot reach the supply voltage as in the circuit provided?
The input is not rail-rail but that only refers to both inputs together.
It works okay if just one input goes to the rail as long as the other input stays below about 1.5V from the upper rail (in this case I had it set at about 100mV above ground).
 

Thread Starter

Dariodario

Joined Apr 6, 2019
14
Close the loop on a TL431 and it makes a nice little amplifier - possibly too much gain, but it can be controlled,
Ian, are you referring to my circuit? Please can specify some detail?

CrutsChow: I realized the circuit with a breadboard and the LM393. This the situation when a rotate the generator by hand with a little lever connected to the crankshaft:

1. whithout hysteresis (feedback resistor on non inverting input) the circuit seems to work well with low frequency 0-70 Hz.
2. With the 1Mohm hysteresis resistor, I noticed sometimes that at the end of the mesures (with the generator in stop), my arduino routine continue to measure pulsation coming from the circuit, like an auto-oscillating phenomen. Unfortunately I don't have an oscilloscope. If I touch the feedback resistor with my finger the auto-oscillating diseappear, but I don't know why! Another problem that I noticed is that randomly, sometimes, appears a about 6.000 Hz measure inside the 0-70Hz train.

I only solved the first problem casually (auto-oscillating), changing the R2=1K with a R=10K, then adding a series 1.2K resistor to the arduino input+100nf ceramic to ground. The circuit was already provided with a 100nf at the comparator input.
It is possible to explain the problems I described so I can put the circuit on the PCB with more confidence? Avoiding to remake the PCB more times :-( From china supplier!

Thanks a lot.
 

crutschow

Joined Mar 14, 2008
34,464
Could be that there wasn't sufficient hysteresis for the noise in your system.
You could try just lowing the value of the 1 megohm resistor.
 

Thread Starter

Dariodario

Joined Apr 6, 2019
14
OK, I will try to lower the feedback resistor.
Frequency value on the Y axis. BJT circuit.
Generator launched by hand with a lever. As you can see only the velocities that produces V>Vbe can switch the transistor and produce the measures. No spike at all.
upload_2019-4-13_18-48-47.png

Frequency value on the Y axis. LM393 circuit.
Generator launched by hand with a lever. Now all the frequencies are captured (almost, Vin>100mv)


The random spike is at 6.000 Hz about (the Y range has auto scaled) and it seems only with the LM circuit.

upload_2019-4-13_19-6-51.png
 

Attachments

ian field

Joined Oct 27, 2012
6,536
Ian, are you referring to my circuit? Please can specify some detail?

The TL431 is a comparator with a built in 2.5V reference - but if you close the loop for negative feedback, it becomes a linear amplifier.

I think the open loop gain is something like 70dB. The nfb is arranged by a voltage divider from the k terminal to GND. The junction of the resistors needs to feed the control pin 2.5V when the k terminal is at the operating point you want.

Its 100% DC nfb, so you end up with a stable operating point - but its also 100% AC nfb, so the AC gain is barely noticeable. Split the top resistor in 2 and shunt the connection point to GND with a capacitor to kill the AC nfb. The gain will probably bee too fierce - just put some resistance in series with the AC shunt cap to tame it.

.
 

Thread Starter

Dariodario

Joined Apr 6, 2019
14
Just to understand a bit more. Another strange thing!

In the crutschow suggested circuit, if I add a series resistor to the out as in the figure (R36 from 330 to 1Khom) the circuit work well (despite the spike I didn't solve). But if I omit R36 and consider as out only the pull up R29 (from 1K suggested up to 10K) the measerument on my arduino is affected by a lot of not correct measures.
How it is possible to justify it? Unfortunately I don't have an oscilloscope.
Thanks.

upload_2019-4-20_18-13-24.png
 
Top