Can you help me understand this circuit? (PMOSFET and NMOSFET Switch. )

Thread Starter

ElectroEnthusiast

Joined Jun 22, 2024
4
I recently purchased a microcontroller board (Pimoroni's Automation 2040 W) and I would like to control Neopixel-like LED strips (WS2815) which work with 12V. Since I am using a 3.3V microcontroller (RP2040) I wanted to use this board's sourcing outputs to control the data pin of the LEDs. This is the board's circuit with the current-sourcing outputs (I added the tag to show where I want to connect the LED strip, the rest is part of the board):
1719039131989.png
Where V+ is 12V.
Could you help me understand this circuit? Above all, I'd like to understand how this circuit behaves to improve my electronics knowledge.

From my limited experience, I have made the following assumptions, if you can please comment on any or all of these assumptions and and tell me which ones are wrong so I can learn:
  1. When the microcontroller sends a logic 1, the Mosfet Q7 connects V+, R22 and R23 to GND, causing the LED strip to... receive a 0?
  2. When the microcontroller sends a logic 0, the current flows through R22 to the gate of Q4 and thus a 1 to the LED strip.
  3. This circuit is called current sourcing because it keeps a constant current.
  4. Such constant current depends on the value of V+, varying this volatge will increase or decrease the current on the LED strip. It's gonna be 12V so how does this affect the LEDs and how long the strip can be?
  5. The Schottky diode D14 is there in case I connect a motor instead of LED strips, the board is protected against reverse currents.
  6. R23 is there to prevent the transistor's inrush current spikes when there's switching. Under this logic, shouldn't there also be a resistor in series at the gain of Q7?
  7. The resistor in series with LED18 is a pull-down resistor. Shouldn't this value be higher?
  8. The zener diode D13 is there to... clamp the voltage?
  9. The resistor R22 connects the gate and the drain so the mosfet Q4 is always active unless Q7 is activated by the uC. It is a resistor and not just a wire perhaps to draw current?

I appreciate all the help you can give.

Additional info:
If I interpreted the LED datasheet correctly, it says that the LEDs need 70% of VDD to be a 1 and 30% of VDD to be a 0, so a logic 1 would need 8.4V and a logic 0 would be ok receiving 3.6V and it would still be a zero. Am I correct in this interpretation?
1719039105372.png
 

k1ng 1337

Joined Sep 11, 2020
1,038
Hi, I simulated your circuit with LTspice. I had to substitute most of components because the spice models are not available. It's not a complex circuit so this should give a good approximation of the operation. V2 is simulating the MCU switching from 0 to 3.3V.


When the microcontroller sends a logic 1, the Mosfet Q7 connects V+, R22 and R23 to GND, causing the LED strip to... receive a 0
When the microcontroller sends a logic 0, the current flows through R22 to the gate of Q4 and thus a 1 to the LED strip
False, the input and output waveforms are in phase (a "1" from the MCU switches the LEDS to a "1" at the same time).

This circuit is called current sourcing because it keeps a constant current.
False, there is no current regulation in the circuit. The output switches from 0V to 12V. It's up to the LED strip to regulate it's own current.

Such constant current depends on the value of V+, varying this volatge will increase or decrease the current on the LED strip. It's gonna be 12V so how does this affect the LEDs and how long the strip can be?
Partially true, the peak output current depends on V+ but the LED strip may regulate the current to a lower amount.

The Schottky diode D14 is there in case I connect a motor instead of LED strips, the board is protected against reverse currents.
True, this is called a flyback diode which provides a safe discharge in the event of inductive kickback caused by a motor or another inductive load.

R23 is there to prevent the transistor's inrush current spikes when there's switching. Under this logic, shouldn't there also be a resistor in series at the gain of Q7?
True, there should be a resistor here to limit the inrush current. A value of 1k-10k is fine. It takes very little charge to switch a MOSFET so many people omit these resistors but I don't.


The resistor in series with LED18 is a pull-down resistor. Shouldn't this value be higher?
Probably, according to my simulation, less than 1mA flows through LED which means it will be barely lite if at all.


The zener diode D13 is there to... clamp the voltage?
True, this clamps the voltage to around 15V to prevent the gate of the MOSFET from being destroyed.


The resistor R22 connects the gate and the drain so the mosfet Q4 is always active unless Q7 is activated by the uC. It is a resistor and not just a wire perhaps to draw current?
False, R22 is a pull-up resistor which forces the p-channel MOSFET to remain OFF when the input signal is "0".

If I interpreted the LED datasheet correctly, it says that the LEDs need 70% of VDD to be a 1 and 30% of VDD to be a 0, so a logic 1 would need 8.4V and a logic 0 would be ok receiving 3.6V and it would still be a zero. Am I correct in this interpretation?
See post #11.

There you have it. Hopefully someone else can confirm my assertions. Feel free to ask questions about anything that is unclear.

kv5.png

kv6.png
 
Last edited:

Frobone

Joined Jun 13, 2024
15
The basic operation depends on understanding that Q4 is a P-channel MOSFET and Q7 is an N-channel. It takes a voltage to turn Q4 off, which is what R22 does. When there is no input from the controller, R22 pulls the gate of Q4 up to V+. Applying a signal to the gate of Q7 turns it on and the gate of Q4 is connected to ground through R23, turning it on.

The thing to remember is that N-channel and P-channel are opposite. Logic 1 turns an N-channel on, but turns a P-channel off.
 

Irving

Joined Jan 30, 2016
4,088
It takes a voltage to turn Q4 off, which is what R22 does.
Not quite. Both N and P channel MOSFETs are Enhancement devices, ie a voltage from gate to source turns them ON. The difference is that N-channel requires a +ve voltage at gate and P-channel a -ve voltage.

So here Q7 is turned on by the MCU by raising its gate to +3v relative to source. This in turn pulls current from V+ through R22 and R23, which sets up a voltage across R22 which is V+ * R22/(R22+R23) or approx 90% of V+. The important fact now is to recognize that the source of Q4 is connected to V+ so the voltage at the junction of R22/R23 is -ve with respect to V+ and so turns Q4 ON because its a P-channel device. For this to work, 90% of V+ must be around 3v (from the datasheet of Q4), so V+ must be 3.5v approx or more - more is better because Q4 needs to be turned on hard if its not to overheat. At 5v on V+, Q4 will drop around 0.1v at 3A or will generate 0.3W of heat. This just about acceptable for that device.
 

Frobone

Joined Jun 13, 2024
15
Not quite. Both N and P channel MOSFETs are Enhancement devices, ie a voltage from gate to source turns them ON. The difference is that N-channel requires a +ve voltage at gate and P-channel a -ve voltage.

So here Q7 is turned on by the MCU by raising its gate to +3v relative to source. This in turn pulls current from V+ through R22 and R23, which sets up a voltage across R22 which is V+ * R22/(R22+R23) or approx 90% of V+. The important fact now is to recognize that the source of Q4 is connected to V+ so the voltage at the junction of R22/R23 is -ve with respect to V+ and so turns Q4 ON because its a P-channel device. For this to work, 90% of V+ must be around 3v (from the datasheet of Q4), so V+ must be 3.5v approx or more - more is better because Q4 needs to be turned on hard if its not to overheat. At 5v on V+, Q4 will drop around 0.1v at 3A or will generate 0.3W of heat. This just about acceptable for that device.
Yes, but that is needlessly complicated for the simple operation of the circuit. It is true, but for the lay person, it suffices to say that taking the P-channel gate to ground turns it on.
 

k1ng 1337

Joined Sep 11, 2020
1,038
@k1ng 1337 & @ElectroEnthusiast Read Bob's post very carefully.

While it is admirable to use circuit examples to help learn electronics, in this particular case I would use a proper logic level voltage level translator chip.
Then you should provide an effective circuit which supersedes mine. It's not very helpful to come at someone saying they are not helpful when you yourself brought almost nothing to the table. I'm not saying you wrong either, just that words are practically meaningless unless they can be mapped to a real solution.

Also, I try to make a point of answering every question a user has regardless of the scope. Often times pros will come in and answer maybe one or two questions but leave the rest open ended. I found this especially difficult to cope with when I started learning electronics and I still do. It's almost as if I'm dealing with bureaucrats who will attempt to circumvent the core questions in any way possible.
 

ElectricSpidey

Joined Dec 2, 2017
2,896
Then you should provide an effective circuit which supersedes mine. It's not very helpful to come at someone saying they are not helpful when you yourself brought almost nothing to the table. I'm not saying you wrong either, just that words are practically meaningless unless they can be mapped to a real solution.

Also, I try to make a point of answering every question a user has regardless of the scope. Often times pros will come in and answer maybe one or two questions but leave the rest open ended. I found this especially difficult to cope with when I started learning electronics and I still do. It's almost as if I'm dealing with bureaucrats who will attempt to circumvent the core questions in any way possible.
I never said you weren't being helpful, in fact I think you were very helpful, except for the part where you missed the maximum voltage allowed at the logic input of the LED strips.

The advice for using a dedicated logic level translator chip was directed at the OP and stands as good advice the way it is, no need to offer a "better" circuit as I would never choose to go that route anyway.
 

k1ng 1337

Joined Sep 11, 2020
1,038
I never said you weren't being helpful, in fact I think you were very helpful, except for the part where you missed the maximum voltage allowed at the logic input of the LED strips.

The advice for using a dedicated logic level translator chip was directed at the OP and stands as good advice the way it is, no need to offer a "better" circuit as I would never choose to go that route anyway.
Please explain exactly what logic voltage is needed and how it relates to the "0.7VDD" and "0.3 VDD" and the absolute maximum ratings.

1719039105372.png
 

Papabravo

Joined Feb 24, 2006
21,343
The datasheet limits the range of Vdd to a voltage between 4.5 and 5.5 Volts. In other words, +5 VDC ±10%. Let us take 5.2 VDC as an example. What the highlighted area is telling you is that in order for the chip to recognize a HIGH, or logic '1' level, the voltage must be:

\( V_{IH}\;\ge\;0.7\cdot VDD\approx 0.7\cdot5.2\;=\;3.64\text{ VDC} \)

Is that clear; The same reasoning applies to:

\( V_{IL}\;\le\;0.3\cdot VDD\;\approx\;0.3\cdot 5.2\;=\;1.56 \text{ VDC} \)
 

k1ng 1337

Joined Sep 11, 2020
1,038
The datasheet limits the range of Vdd to a voltage between 4.5 and 5.5 Volts. In other words, +5 VDC ±10%. Let us take 5.2 VDC as an example. What the highlighted area is telling you is that in order for the chip to recognize a HIGH, or logic '1' level, the voltage must be:

\( V_{IH}\;\ge\;0.7\cdot VDD\approx 0.7\cdot5.2\;=\;3.64\text{ VDC} \)

Is that clear; The same reasoning applies to:

\( V_{IL}\;\le\;0.3\cdot VDD\;\approx\;0.3\cdot 5.2\;=\;1.56 \text{ VDC} \)
Looks like there is some confusion with TS' intent. I figured he wanted to switch the 12V power to an array of LEDs. Assuming I'm wrong, then all he really needs is a 3.3V -> 5V level shifter. If this is the case, he can still use his original schematic with the exception of making V+ 5V not 12V. Obviously he doesn't need a high current driver board for this but it can still work.
 

ElectricSpidey

Joined Dec 2, 2017
2,896
Well, the OP clearly states that they wish to drive the data pin of the addressable LEDs.

VCC can be interpreted as VLED.

VDD is the chip supply

And the maximum input voltage on the data pin is 5.3 volts.
 

k1ng 1337

Joined Sep 11, 2020
1,038
Well, the OP clearly states that they wish to drive the data pin of the addressable LEDs.

VCC can be interpreted as VLED.

VDD is the chip supply

And the maximum input voltage on the data pin is 5.3 volts.
Yes, he did say that but he also said V+ is 12V and a few other things that suggest switching the power input not the logic.

"Such constant current depends on the value of V+, varying this volatge will increase or decrease the current on the LED strip. It's gonna be 12V so how does this affect the LEDs and how long the strip can be?"

and

"The Schottky diode D14 is there in case I connect a motor instead of LED strips, the board is protected against reverse currents."

:oops:
 

Irving

Joined Jan 30, 2016
4,088
Yes, but that is needlessly complicated for the simple operation of the circuit. It is true, but for the lay person, it suffices to say that taking the P-channel gate to ground turns it on.
I beg to differ; as a teacher of electronics at high-school/degree/masters level I find my students prefer to have a complete and correct answer, even if its more than they need right now. What they definitely don't want or need is a short answer that is technically wrong.
 

Irving

Joined Jan 30, 2016
4,088
That is a really confusing set of data sheets for the WS2815.

The WS2815 or WS2815B is a 12v device (VDD) with an internal regulator to 5v (VCC) which is brought out on pin 1 for decoupling purposes which is needed on longer strips. As pointed out in many blogs and how-tos, the logic input is relative to VCC NOT VDD though this is erroneously shown on many datasheets as >0.7VDD for logic 1 and <0.3VDD for logic 0 where VDD is quoted as 4.5-5.5v. To add to the confusion some earlier datasheets quoted logic high as VDD-0.5~VCC+0.5 which should have been logic input as VSS-0.5~VCC+0.5, or logic 0 as <0.3VCC without mentioning VCC elsewhere. VDD for WS2815 or 15B is always between 9.5 - 13.5V.

So for driving the data input from a 5v MCU no logic level shifting is needed, and, though it should work with a 3.3v MCU, there might be some issues, particularly at higher speeds. The simple solution is to add a pullup resistor to 5v (assuming 5v is available somewhere); a value of 5 -10k should work OK as the WS2815 data-in pin is high-impedance and only sinks/sources 1uA at either logic level - this will lift logic 1 to around 3.6v without detriment to most MCUs.
 

BobTPH

Joined Jun 5, 2013
9,335
So for driving the data input from a 5v MCU no logic level shifting is needed, and, though it should work with a 3.3v MCU, there might be some issues, particularly at higher speeds
I definitely had problems running it from a 3.3V micro. It worked most of the time, but several strips had problems. I solved it by using a CMOS buffer at 5V with a 3V logic high threshold.

Here is the thread.

Be careful choosing a level translator or buffer, it needs to be able to produce a clean 400 nsec pulse. I tried 2N3904s but they were too slow.
 

Thread Starter

ElectroEnthusiast

Joined Jun 22, 2024
4
Hi, I simulated your circuit with LTspice. I had to substitute most of components because the spice models are not available. It's not a complex circuit so this should give a good approximation of the operation. V2 is simulating the MCU switching from 0 to 3.3V.


When the microcontroller sends a logic 1, the Mosfet Q7 connects V+, R22 and R23 to GND, causing the LED strip to... receive a 0
When the microcontroller sends a logic 0, the current flows through R22 to the gate of Q4 and thus a 1 to the LED strip
False, the input and output waveforms are in phase (a "1" from the MCU switches the LEDS to a "1" at the same time).

This circuit is called current sourcing because it keeps a constant current.
False, there is no current regulation in the circuit. The output switches from 0V to 12V. It's up to the LED strip to regulate it's own current.

Such constant current depends on the value of V+, varying this volatge will increase or decrease the current on the LED strip. It's gonna be 12V so how does this affect the LEDs and how long the strip can be?
Partially true, the peak output current depends on V+ but the LED strip may regulate the current to a lower amount.

The Schottky diode D14 is there in case I connect a motor instead of LED strips, the board is protected against reverse currents.
True, this is called a flyback diode which provides a safe discharge in the event of inductive kickback caused by a motor or another inductive load.

R23 is there to prevent the transistor's inrush current spikes when there's switching. Under this logic, shouldn't there also be a resistor in series at the gain of Q7?
True, there should be a resistor here to limit the inrush current. A value of 1k-10k is fine. It takes very little charge to switch a MOSFET so many people omit these resistors but I don't.


The resistor in series with LED18 is a pull-down resistor. Shouldn't this value be higher?
Probably, according to my simulation, less than 1mA flows through LED which means it will be barely lite if at all.


The zener diode D13 is there to... clamp the voltage?
True, this clamps the voltage to around 15V to prevent the gate of the MOSFET from being destroyed.


The resistor R22 connects the gate and the drain so the mosfet Q4 is always active unless Q7 is activated by the uC. It is a resistor and not just a wire perhaps to draw current?
False, R22 is a pull-up resistor which forces the p-channel MOSFET to remain OFF when the input signal is "0".

If I interpreted the LED datasheet correctly, it says that the LEDs need 70% of VDD to be a 1 and 30% of VDD to be a 0, so a logic 1 would need 8.4V and a logic 0 would be ok receiving 3.6V and it would still be a zero. Am I correct in this interpretation?
See post #11.

There you have it. Hopefully someone else can confirm my assertions. Feel free to ask questions about anything that is unclear.

View attachment 325164

View attachment 325165
Thank you so much for taking the time to give such a detailed response and also for the simulation. I really appreciate it. It has been quite insightful.
 

Thread Starter

ElectroEnthusiast

Joined Jun 22, 2024
4
That is a really confusing set of data sheets for the WS2815.

The WS2815 or WS2815B is a 12v device (VDD) with an internal regulator to 5v (VCC) which is brought out on pin 1 for decoupling purposes which is needed on longer strips. As pointed out in many blogs and how-tos, the logic input is relative to VCC NOT VDD though this is erroneously shown on many datasheets as >0.7VDD for logic 1 and <0.3VDD for logic 0 where VDD is quoted as 4.5-5.5v. To add to the confusion some earlier datasheets quoted logic high as VDD-0.5~VCC+0.5 which should have been logic input as VSS-0.5~VCC+0.5, or logic 0 as <0.3VCC without mentioning VCC elsewhere. VDD for WS2815 or 15B is always between 9.5 - 13.5V.

So for driving the data input from a 5v MCU no logic level shifting is needed, and, though it should work with a 3.3v MCU, there might be some issues, particularly at higher speeds. The simple solution is to add a pullup resistor to 5v (assuming 5v is available somewhere); a value of 5 -10k should work OK as the WS2815 data-in pin is high-impedance and only sinks/sources 1uA at either logic level - this will lift logic 1 to around 3.6v without detriment to most MCUs.
Thank you, your comment was very useful.
 
Top