PWM and Transistor Circuit Help

Thread Starter

mdylanmst20

Joined Jun 5, 2017
19
Attached below is my circuit I just quickly drew up. I don't know how to add the picture with my text without it being way to small or way to big. Anyways The goal of this circuit is to have the NPN transistor be driven by my raspberry pi at some frequency and then have the NPN drive the PNP. I want to be able to vary the voltage on R4 by changing the duty cycle through the Pi. The goal is to be able to control the current being drawn through the circuit by making a program that changes the duty cycle over time on the pi while having the constant 5.3V input voltage. Later I want to add a Low Pass filter to get an analog rather than digital output but i'm back peddling and trying to make sure I know what I'm doing on this part. The max current I want to achieve is 400 mA. I'm currently trying to learn circuits so much of the concepts are foreign to me so bear with me. Someone more experienced than me originally drew me up this circuit so my question is, what purpose would R1 have in this instance? If i'm varying the current running through the PNP transitor, do I calculate the base resistor based on the worst case current running from the emitter to collector? How would I go about calculating the base resistor R3? With this set up could I get a relatively smooth control of the current through the circuit by adjusting the PWM duty cycle with a program?
 

Attachments

Dodgydave

Joined Jun 22, 2012
11,303
R1 just turns off the Pnp, R2 will depend on the hfe of the Pnp transistor, to give maximum Collector current saturation, so if the hfe is 100, and you need 400mA, thats 4mA base current, with a 1.2K base resistor.

However your transistor is rated at maximum IC of 50mA, best to go with a PN2222 transistor @600mA, or a BC327@800mA.
 
Last edited:

dl324

Joined Mar 30, 2015
16,922
Wow! Over 200 words in one paragraph. Why don't you make it easier on us and use paragraphs to organize your thoughts and proper grammar to make it easier to read??
Attached below is my circuit I just quickly drew up. I don't know how to add the picture with my text without it being way to small or way to big.
upload_2017-6-14_9-49-29.png

Anyways The goal of this circuit is to have the NPN transistor be driven by my raspberry pi at some frequency and then have the NPN drive the PNP. I want to be able to vary the voltage on R4 by changing the duty cycle through the Pi.
This is just two inverters. The voltage on R4 will be either 0V or 5.3V.

The goal is to be able to control the current being drawn through the circuit by making a program that changes the duty cycle over time on the pi while having the constant 5.3V input voltage.
This would let you control average current, but not absolute current.

Later I want to add a Low Pass filter to get an analog rather than digital output but i'm back peddling and trying to make sure I know what I'm doing on this part. The max current I want to achieve is 400 mA. I'm currently trying to learn circuits so much of the concepts are foreign to me so bear with me.
2N3906 can't handle 400mA.

Someone more experienced than me originally drew me up this circuit so my question is, what purpose would R1 have in this instance? If i'm varying the current running through the PNP transitor, do I calculate the base resistor based on the worst case current running from the emitter to collector?
R1 and R2 turn off the PNP transistor when the NPN is off.

How would I go about calculating the base resistor R3? With this set up could I get a relatively smooth control of the current through the circuit by adjusting the PWM duty cycle with a program?
The NPN needs to provide 10% of the collector current in the PNP. The base current of the NPN needs to be 10% of its collector current.

It's easier to talk about circuits if you assign component designators.
 

crutschow

Joined Mar 14, 2008
34,452
R1 is to improve the turn-off time and shunt off any leakage current.

The 2n3906 has a max current rating of 200mA, so won't work to deliver 400mA.
You could use a 2N2905 or 2N2907, which are rated at 600mA.

For good switching you want the base current to be about 1/10th of the maximum collector current.

This means the PNP base current should be 40mA.
This means R2 should be (5.3-0.7)V/40mA = 115Ω
(We can arbitrarily make R1 = 10kΩ).

Now with 40mA through the NPN we need 4mA at its base.
Thus R3 = (3.3-0.7)V/4mA = 650Ω

That should give you a good switching waveform for PWM.

Why do you need 400mA?

Here's an LTspice simulation of the circuit operating at 1kHz:

upload_2017-6-14_10-11-16.png
 

Attachments

crutschow

Joined Mar 14, 2008
34,452
R2 will depend on the hfe of the Pnp transistor, to give maximum Collector current saturation, so if the hfe is 100, and you need 400mA, thats 4mA base current, with a 1.2K base resistor.
That's not good practice for a switching circuit.
The hfe is used for small signal circuits and is specified at a couple volts or so Vce, not when the transistor is saturated.
For good saturated switching you should used a forced beta of about 10-20 [a value of 10 is typically used in the data sheets where the Vce(sat) is specified].
 

Thread Starter

mdylanmst20

Joined Jun 5, 2017
19
Thanks for all the responses. Sorry dl324 about the format of the post, I'll try to be more diligent in the future.

I have replaced the original PNP with the 2N2907. I have the exact set up that crutschow shows in his LT spice simulation give or take a few ohms on some resistors because of what I have one hand. When at a 100% duty cycle, the voltage across the 13 ohm resistor R4 is something like 3.7 V instead of the near 5.3V that I would expect.

Where am I losing that voltage at? Could it be the fault of the raspberry pi that's driving the PWM?

To answer your question crutschow, the reason I want the max 400 mA output is so I can represent the current draw of a DC motor. It's initial current spike is 400 mA. I want to be able to emulate the current draw of a motor so I can hook it in place of a real motor from a food pump. The pump has a circuit that monitors the current of the motor so I want to be able to fool the pump into thinking there is an active motor for testing purposes. I've sort of talked about this in other threads you've commented on.
 

dl324

Joined Mar 30, 2015
16,922
When at a 100% duty cycle, the voltage across the 13 ohm resistor R4 is something like 3.7 V instead of the near 5.3V that I would expect.

Where am I losing that voltage at?
What is the voltage on the collector of the NPN transistor? What is the value of R2?
 

Thread Starter

mdylanmst20

Joined Jun 5, 2017
19
The voltage on the collector of the NPN transistor is 2.68 V and R2 is 110 ohms. Should it be that much? I'm putting the positive probe of my multi meter on the collector terminal and the other to ground.

If I'm measuring this correctly it seems like Pi is outputting 3.16 V from the pin that is giving the PWM signal. I would have expected it to be 3.3 V so i'm not sure what's up with that.
 

crutschow

Joined Mar 14, 2008
34,452
The voltage on the collector of the NPN transistor is 2.68 V and R2 is 110 ohms.
Its collector voltage should be no more than about 0.2V.
Check the value of R3.
If its value is ≅650Ω then check that the NPN isn't connected upside down.
If I'm measuring this correctly it seems like Pi is outputting 3.16 V from the pin that is giving the PWM signal. I would have expected it to be 3.3 V so i'm not sure what's up with that.
That drop is due to the R3 current causing a small voltage drop in the PI output transistor.
 

Thread Starter

mdylanmst20

Joined Jun 5, 2017
19
I made R3 649 ohms and I measured the output of the Pi to be 3.16 V, although I thought the pins were supposed to be outputting 3.3 V.
 

dl324

Joined Mar 30, 2015
16,922
I made R1 10K ohms and I measured the output of the Pi to be 3.16 V, although I thought the pins were supposed to be outputting 3.3 V.
I meant R3; corrected my post above...

Output voltages have a range. For 3.3V devices, 3V is generally high enough to be considered logic HIGH.
 

Thread Starter

mdylanmst20

Joined Jun 5, 2017
19
I corrected my post above as well to show R3.

Regarding that the transistor may be backwards: If i'm correct in that the input of the NPN should be the collector and the output be the emitter then it seems to be in the circuit the right way.
 

Thread Starter

mdylanmst20

Joined Jun 5, 2017
19
Ok so I may have erred when I told you guys the voltage on the collector. It seems to vary with duty cycle.

When the NPN is off (at 0% duty cycle) the voltage is 5.3 volts on the collector. as the the duty cycle goes to 100% it goes all the way down to 0.07 V. When I measured it originally the duty cycle I was testing it at was 50% and the voltage I measured was 2.68 V which is around half of 5.3 V. Should it do this?
 

crutschow

Joined Mar 14, 2008
34,452
I was testing it at was 50% and the voltage I measured was 2.68 V which is around half of 5.3 V. Should it do this?
Yes.
A typical meter will measure the average value of a varying signal on the DC scale, so 2.68V is close to what you would expect with a 50% duty-cycle.
 

Thread Starter

mdylanmst20

Joined Jun 5, 2017
19
So I checked the data sheet for the 2N2907 Transistor and with the current I was running it at the voltage drop on it was about 1.6V according to the data sheet. (5.3 - 1.6) = 3.7 so that would explain why my output was what it was. I would just need to change my PNP transistor to get a better output. Thanks for your guys help.
 

crutschow

Joined Mar 14, 2008
34,452
According to the graph below from this data sheet, the nominal saturation voltage for the 2N2907 should be <0.3V@400mA, (I measure 0.28V in the simulation) so you should be measuring well less than 1.6V.
(Was that at 100% duty-cycle?)


upload_2017-6-14_15-27-6.png
 

crutschow

Joined Mar 14, 2008
34,452
After some further thought, the high saturation voltage could be due to the self-heating of the 2N2907 from the high current.
The saturation voltage is quite sensitive to that although, according to the curves, it still shouldn't be higher than about 0.8V.

A 2N2905 is the same transistor with a larger case, so it will dissipate the heat better and thus have a lower saturation voltage under load.

You could also use the common (and typically cheap) TIP32, 3A transistor,
That will have a very low saturation voltage (<0.2V) @ 400mA.
 

Thread Starter

mdylanmst20

Joined Jun 5, 2017
19
That voltage drop was measured at 100% duty cycle. I've also attached what I thought accounted for the drop from the data sheet. I put a star next to the collector emitter saturation voltage that I think is responsible.

I have another question if any one is willing to answer. So as I decrease the duty cycle from 100 to 0 percent the average voltage begins to decreases linearly but as it goes below 50%, the average voltage is no longer linear. Even at 1 percent duty cycle the average voltage is around 1 V. Is this my transistors or due to my original PWM signal from the Pi?
 

Attachments

Top