# Square Wave with Variable Voltage

Discussion in 'The Projects Forum' started by dan07, Nov 29, 2013.

1. ### dan07 Thread Starter New Member

Nov 29, 2013
16
0
Hello,

I am quite new to electronics and I am facing a problem with my circuit. The aim of this project is to have a PIC generating a square wave (100 us ON; 100 us OFF) that will drive a BC548. Since the output voltage of PIC is 5 V, the BC548 is used to have the same square wave but with higher voltage. To achieve that the "Variable DC Source" feeds the circuit with 24 V. I was expecting to have a square wave with variable voltage as I change the "Variable DC Source". However, everything goes well until 8.6 V. Then, the square wave shifts up (as I increase the voltage) instead of reaching a higher voltage. There is a offset of the whole square wave.

Find attached 3 figures:

- The circuit;
- One photo of the oscilloscope when the "Variable DC Source" was feeding the circuit with 8.6 V;
- One photo of the oscilloscope when the "Variable DC Source" was feeding the circuit with 14 V (the square wave is shifted up).

How can I change my circuit in order to have what I need: a Square Wave paced by the PIC with a variable voltage?

Thanks.

Dan07.

File size:
235 KB
Views:
58
File size:
118.1 KB
Views:
31
• ###### Variable Square Wave_photo 2.jpg
File size:
114.1 KB
Views:
32
Last edited by a moderator: Nov 29, 2013

Apr 5, 2008
15,806
2,389
Hello,

There are some problems with the LM317 circuit.
The 560 Ohms resitor has a to high value.
Reduce it to 120 Ohms and reduce the 1600 Ohms resistor to 345 Ohms.
Also there is no decoupling capacitor on the output of the regulator.
Add an 0.1 μF capacitor from the output to ground.

You also have no current limiting resistor at the base of the transistor.
Add a 470 Ohms resistor in series with the base to the output of the microcontroller.

Bertus

3. ### dan07 Thread Starter New Member

Nov 29, 2013
16
0
bertus,

I followed all your instructions and I am still getting the same behavior: square wave shifts up with voltages higher than 8.6V. I dropped all the resistors values for the LM317 and I am still getting around 5 V to feed the PIC, great!

Do you have any suggestion on how can I solve this issue regarding the square wave shift?

Thanks.

Dan07.

Apr 5, 2008
15,806
2,389
Hello,

Taking a closer look at your image, I see that the transistor is turned around.

Bertus

File size:
25.8 KB
Views:
102
5. ### dan07 Thread Starter New Member

Nov 29, 2013
16
0
bertus,

You are great! How could I missed that? The BC548 was turned around. Now I can adjust the voltage and the Square Wave changes accordingly. However,
I am getting a kind of overshoot peaks on the raise phase of the square wave and a long fall time. I removed the capacitors from circuit and nothing changed. Then, I add a 1K resistor across the +V and the collector of the BC548 (in other words, across the leads of the oscilloscope) and the square wave turned into a perfect shape (see pictures attached). Is there a way to have the square wave as clean as I get following adding the 1K resistor?

Another question, the 4.3K resistor across collector and V+ is well sized?

Thanks a lot.

Dan07.

File size:
110.7 KB
Views:
37
File size:
97.5 KB
Views:
32
6. ### iimagine Active Member

Dec 20, 2010
129
9
You really should be probing from the collector of the transistor and ground, this way, even 'if' your supply could not provide enough current to the circuit, you would still see a full swing.

7. ### iimagine Active Member

Dec 20, 2010
129
9
It would all depends on what you are planning to do with this output

8. ### dan07 Thread Starter New Member

Nov 29, 2013
16
0
I am probing from the collector of the transistor and ground. Is there a way to "clean" the square wave from the peaks?

This output will be used to stimulate a biological tissue with a resistance ranging from 1k to 15k (each tissue has a different resistance). How do I check if 4.3K is okay for that resistor?

Thanks a lot for your help.

Dan07.

9. ### MrChips Moderator

Oct 2, 2009
12,652
3,460
Are you using a 10x oscilloscope probe?

10. ### iimagine Active Member

Dec 20, 2010
129
9
I noticed that you do not have a 'pull down' resistor, this could be why you see that peak, because that bjt is floating. Try connecting a 1k resistor from the base of the transistor to ground, this would make sure that it would not floats.

11. ### dan07 Thread Starter New Member

Nov 29, 2013
16
0
I tried 1x and 10x probes and got the same result.

I added a 1K resistor between the base of the transistor and ground and the peaks are still there.

I am almost there, if I get rid of these peaks the circuit will be great. I followed all the suggestions until now and the circuit is better.

Thanks.

Dan07.

12. ### MrChips Moderator

Oct 2, 2009
12,652
3,460
There is something strange in your setup.
Your power supply and scope do not share a common ground.
Hence one or both of them must be floating.

13. ### iimagine Active Member

Dec 20, 2010
129
9
In other word, you are paralleling the 4.3k and the 1k?

14. ### dan07 Thread Starter New Member

Nov 29, 2013
16
0
I have to get the ground from a "different" source to the scope since I am using the BC548 transistor to have a square wave (paced by the PIC) but with a variable voltage. Then, I have to get the ground from the collector pin of the transistor.

Yes, but was just a test. I really don't know what value to use for this resistor. The circuit is working like I expect. The only problem are the peaks on the square wave. How should I size this resistor?

Find attached the updated version of the circuit.

Thanks all.

File size:
168.7 KB
Views:
27
15. ### iimagine Active Member

Dec 20, 2010
129
9
You have to probe from the collector of the transistor and it's emitter, which is grounded, since that would be your output if you were gonna do anything with it

16. ### dan07 Thread Starter New Member

Nov 29, 2013
16
0
Now I am probing from the collector and the emitter and it is perfect!

Take a look at the attached photo and see how square is the square wave!

And how about the 4.3K, is it okay? What is the main purpose of this resistor?

Thanks.

File size:
274.4 KB
Views:
24
17. ### iimagine Active Member

Dec 20, 2010
129
9
Read, learn Ohm law and how a bjt works. In your case, there is a shortcut, google 'transistor as a switch'

18. ### dan07 Thread Starter New Member

Nov 29, 2013
16
0
I did a review of the concepts involved in my project and some calculation to better know my circuit.
The Ohm's Law was named after the German scientist Georg Ohm. It states that the current through a resistance (e.g. resistor) between two points is proportional to the potential difference across the two points. The formula for that is: I=V/R.

For example: if I have a 1.5 V battery and I put a 1.5Kohm resistor across the positive and negative poles of the battery, I will have a current of 1 mA flowing through the resistor.

I = 1.5/1500
I = 0.001 A or I = 1 mA

If I want a higher current, 2 mA for example, I have to use a 3 V battery.

I = 3/1500
I = 0.002 A or I = 2 mA

I reviewed the datasheet of my transistor (BC548B) and I found that the hFE value goes from 200 to 450. I measured with the multimeter the transistor that I am using and I got a value of 257. From some reading I learned that this value should be remembered later for further calculation of base, collector and emitter current. In my project I am using my bipolar junction transistor (bjt) as a switch. This transistor has 3 pins: base, collector and emitter. Current at base (Ib) will control the flow from the collector to the emitter. Lets calculate the current at base (Ib), at collector (Ic) and at emitter (Ie) for the current project.

I believe that the Ib is the simplest to be calculated. Since my PIC outputs 5 V:

Ib = 5/470
Ib = 0.010 A or 10 mA

The Ic should be:

Ic = Beta * Ib
Ic = 257 * 0.010 A
Ic = 2.57 A (this value seems too high for me)

The Ie should be:

Ie = (Beta + 1) * Ib
Ie = 258 * 0.010 A
Ie = 2.58 A (this value seems too high for me)

I believe that I made some mistakes doing the current calculation but I didn't know which one to calculate first since the formulas need always one of the currents.

Now I need your feedback. Am I going in the right direction? I am asking that because with the current project I can vary the height of the square wave by changing my Variable DC Source, but if I continue to probe the square wave with the oscilloscope and make the signal goes through a 1 K resistor (just put the resistor between the probes), I saw a huge drop in square wave height (voltage). Because of that I believe that the circuit still needs some improvements.

Thanks.

Dan07.

19. ### iimagine Active Member

Dec 20, 2010
129
9
Your calculations are correct, that is why you needed that load resistor 4.3k to limits the current to your application specific need. For example, If you want to drive a bulb, then you would check to see how much current that bulb can handle/need; at what voltages is acceptable, then you would use Ohm's law to calculate the load resistor for it.
Another thing to look for in the datasheet is the limitation of Ic current for a transistor, otherwise you would see smoke everywhere.

PS: If Ib and Ie are know, Ic can be obtained by this formula Ic = Ie - Ib

Last edited: Nov 30, 2013
20. ### dan07 Thread Starter New Member

Nov 29, 2013
16
0
I will use this to stimulate a biological tissue that has a resistance around 5 kΩ. If I set my Dc Variable Source to 5 V the current will be 1 mA. However, when I put a 5 KΩ resistor simulating the tissue, the height of the square wave dropped a lot. If I reduce the 4.3KΩ resistor it will allow more current to flow and then I will not see a drop into the height of the square wave?

The calculation is:

I = 5/4300 ??

The question is: the resistor (that actually is 4.3K) should be always lower than the resistance of my biological tissue that will be stimulated, in order to make sure that no drop will occur on the square wave voltage?

If Ic = Ie - Ib

Ic = 2.58 - 0.001
Ic = 2.579

Why I am facing a huge drop into square wave voltage?

Please, help me with this issue. I've been a good student!

Thanks

Dan07.