Can I switch 2 transistors with the same MCU PWM signal?

Thread Starter

Ditch

Joined Feb 9, 2017
6
Hi There, I'm quickly running out of PWM pins on my PIC18F46K22 and want to add dimming to a clock which uses 4x 7-segment displays.
As a precaution, I want to power the hour segments via one transistor and the minute segments via another transistor but I'm not sure if this will work or is advisable.

I've added a schematic below. The PWM is fed from my PIC, my question is, can I switch the 2 transistors this way?


Untitled-12-transistors.png



Each segment of the display uses approx 3ma and I switch these directly with the PIC. Each 7-segment display uses approx 21ma so I'm well within the ratings of the transistors and PIC18F46K22.

Any advice or recommendations would be appreciated.


Ian
 

sarahMCML

Joined May 11, 2019
697
Hi Eric, Thanks for you fast reply.

I'd expect around 4.5v ish which will drive the 7-segment display nicely.

Ian
The voltage divider on the base means you'll have less than 2V on the emitter.
Are you driving each A to G segment with a separate output from the PIC, or is it multiplexed?
 

Thread Starter

Ditch

Joined Feb 9, 2017
6
Wow Eric, Thanks for your help with this.

I am driving each segment with separate PIC outputs and this is all working, I'm just wanting to add the dimming option to it now.

At the moment then, I'm using 2x 10K resistors at the base. If I was to say, use a 2K as R1 and 10K as R2 would this suffice?

Ian
 

ericgibbs

Joined Jan 29, 2010
21,439
hi D,
In any NPN Emitter circuit, the maximum Emitter voltage, will be less than the Base voltage by approx 0.7V.
Also, the Base voltage will also be less than 5V from the PWM due to the voltage dividers on the Base input.
E
 

BobTPH

Joined Jun 5, 2013
11,514
If you use the NPN transistors as in your schematic, both resistors should be removed. This is a voltage follower, which does not need current limiting.

Edited: change PNP to NPN
 
Last edited:

ronsimpson

Joined Oct 7, 2019
4,690
On the left is how you get more drive from your circuit. On the right is how it is normally done but it requires an inversion in software. Note the sex of the transistors is changed. PNP
1672146987426.png
 

Thread Starter

Ditch

Joined Feb 9, 2017
6
OK. Thanks Eric,

If I was to use a 1K as R1 and a 20K as R2 then this would give around 4v at the Emitter.
If I was to then place a 400ohm resistor between the segment (a-g) led and PIC pin, this should give approx 5ma to the segment led.

Would this seem about rightIan?
 

PaulEE

Joined Dec 23, 2011
474
Ditch, that PIC, which I actually have worked with...I have some here somewhere...can sink or source 25mA per pin.

If you have spare "not PWM capable" pins (aka GPIO), I believe you can (in your while(always) loop or whatever executes constantly) set any number of pins on a port to echo what the PWM pin is outputting, and drive the two sets of 7-segments directly, so long as you have resistors on each of the LEDs on the other side...which you should be doing anyway, since unequal current through LEDs will result in some being brighter than others. Or, if the PWM is adjusted during an interrupt, you can plop the "other pins output state update code" right in there.

If you use multiple PIC pins, I would use small (perhaps 10 ohm) resistors on each before you feed the LED arrays to allow each pin to output some average fraction of the total needed...or otherwise alleviate issues from mismatched transistor output impedances.

Just a thought!

Paul
KI5VNH
 

Thread Starter

Ditch

Joined Feb 9, 2017
6
That's great Eric. I can't thank you enough for your help with this.
I'm going to go with your circuit above and see how I get on.

Ian
 

Thread Starter

Ditch

Joined Feb 9, 2017
6
Ditch, that PIC, which I actually have worked with...I have some here somewhere...can sink or source 25mA per pin.

If you have spare "not PWM capable" pins (aka GPIO), I believe you can (in your while(always) loop or whatever executes constantly) set any number of pins on a port to echo what the PWM pin is outputting, and drive the two sets of 7-segments directly, so long as you have resistors on each of the LEDs on the other side...which you should be doing anyway, since unequal current through LEDs will result in some being brighter than others. Or, if the PWM is adjusted during an interrupt, you can plop the "other pins output state update code" right in there.

If you use multiple PIC pins, I would use small (perhaps 10 ohm) resistors on each before you feed the LED arrays to allow each pin to output some average fraction of the total needed...or otherwise alleviate issues from mismatched transistor output impedances.

Just a thought!

Paul
KI5VNH
Thanks Paul, I'm not aware that you can do that with the GPIO's. I'll look into this and thanks for the heads up.

Ian
 

BobTPH

Joined Jun 5, 2013
11,514
OK. Thanks Eric,

If I was to use a 1K as R1 and a 20K as R2 then this would give around 4v at the Emitter.
If I was to then place a 400ohm resistor between the segment (a-g) led and PIC pin, this should give approx 5ma to the segment led.

Would this seem about rightIan?
Why do you think you need those two resistors? Did you read m post #9? You can use the NPN voltage follower without any resistors. Then you will get something above 4V out.

Edited: change PNP to NPN
 
Last edited:

PaulEE

Joined Dec 23, 2011
474
I would also not connect the bases of two transistors directly together. At that point, the amount of current through each will depend on the ON resistance of the B-E junctions. You'll probably get away with it here, but generally not a good idea...just sayin'.

Regarding the multi-pin thought in my previous post, I promise you can do that if you wanted to try it. It is no different than reading a pin for a switch state and outputting the state on another pin, except your "switch" is the output on the PWM pin, and your output of the pin(s) goes to your LEDs (with the resistors I'd mentioned, to spread current from each pin evenly).

EDIT: You will have to update the state of the other pins every loop go-around, not just when the duty-cycle changes in the interrupt; that wouldn't do what you want. I didn't want to change the original post. Basically, echoing the PWM pin state to other pins is the idea, and I have done that, and it does work. It isn't as sexy as playing with transistors, I admit, but it does preserve your voltage at the output...although the PNPs may also do you just fine!

Paul
KI5VNH
 
Last edited:
Top