diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2025-12-27 12:14:19 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2025-12-27 12:19:38 +0800 |
| commit | c82f81bc913fc6ed948e3289d7adce839a539a5f (patch) | |
| tree | b8b22bc6ac061afac9e903d9468152097ef72e8a | |
| parent | d0d7a540b009433e4278f20def54b87edf3c712f (diff) | |
| download | www-c82f81bc913fc6ed948e3289d7adce839a539a5f.tar.gz | |
MOSFET post.
| -rw-r--r-- | _log/mosfet-switches.md | 124 | ||||
| -rw-r--r-- | _site/feed.xml | 2 | ||||
| -rw-r--r-- | _site/index.html | 2 | ||||
| -rw-r--r-- | _site/log/index.html | 2 | ||||
| -rw-r--r-- | _site/log/mosfet-switches/index.html | 134 | ||||
| -rw-r--r-- | _site/posts.xml | 2 |
6 files changed, 105 insertions, 161 deletions
diff --git a/_log/mosfet-switches.md b/_log/mosfet-switches.md index 5e17849..4fc1d31 100644 --- a/_log/mosfet-switches.md +++ b/_log/mosfet-switches.md @@ -1,108 +1,80 @@ --- -title: On the use of MOSFETs as electronic switches +title: High-side MOSFET switching date: 2025-06-22 layout: post --- -Recently, I needed a low-power circuit for one of my battery-operated projects. -Much of the system's power savings depended on its ability to electronically -switch off components, such as servos, that draw high levels of quiescent -currents. My search for a solution led me to MOSFETs, transistors capable of -controlling circuits operating at voltages far above their own. +Needed low-power switching for the [fingerprint door +lock](../fpm-door-lock-lp/). Servo and FPM draw high quiescent current--had to +cut power electronically during sleep. MOSFETs can do this. -## Acknowledgments - -This article is a summary of what I learnt about using MOSFETs as switches. -I'm not an electronics engineer, and this is not an authoritative guide. The -circuits in this post must be considered within the narrow context in which -I've used them. All credits for the schematics belong to <a +Schematics belong to <a href="https://electronics.stackexchange.com/users/292884/simon-fitch" class="external" target="_blank" rel="noopener noreferrer">Simon Fitch</a>. -## Preamble +## Problem with simple low-side switching -For a typical MOSFET-based switch, we can connect a GPIO pin of a -microcontroller to the gate of a logic-level N-channel MOSFET placed on the low -side of the load and tie the gate and the drain pins of the MOSFET with a -pull-down resistor. This would work as long as the power supplies of the -microcontroller and the load don't share a common ground. Things become more -complicated when they do (e.g., controlling power to a component driven by the -same microcontroller). +Typical approach: GPIO → gate of N-channel MOSFET on low side, pull-down +resistor between gate and drain. Works if MCU and load don't share common +ground. Doesn't work when they do (like controlling a component powered by the +same MCU). -In that scenario, the source potential visible to the load is the difference -between the gate and the threshold potentials of the MOSFET. For example, when -the gate and the threshold potentials are 3.3 V and 1.5 V, the potential the -load sees is 1.8 V. So, to use a low-side N-channel MOSFET, we need the gate -potential to be higher than the source potential, which may not always be -practical. The alternative would be a hide-side switch. +Issue: source potential = gate potential - threshold voltage. Example: 3.3V +gate - 1.5V threshold → 1.8V at load--not nearly enough for a servo. Raising +the gate potential above source is not always practical. Solution: high-side +switch. ## P-channel high-side switch -The following schematic shows how a high-side P-channel MOSFET (M1) could -switch power to a 6 V servo driven by a 3.3 V MCU. -  -When the microcontroller outputs low, the M2 N-channel MOSFET stops conducting. -The R1 resistor pulls the gate of the M1 P-channel MOSFET up to +6 V, switching -the servo off. When the microcontroller outputs high on the GPIO pin, M2's -source-drain connection starts conducting, causing M1's gate potential to drop -to 0 V, which switches on power to the servo. +M1 is P-channel (high-side), M2 is N-channel (level converter). MCU output low +→ M2 off → R1 pulls M1 gate to +6V → servo off. MCU output high → M2 conducts → +M1 gate drops to 0V → servo on. -## N-channel high-side switch +Note: IRF9540 in the schematic doesn't work. V<sub>GS</sub> (-10V) for +RDS<sub>on</sub> too much for 3.3V ATmega328P to drive. NDP6020P is the only +suitable through-hole MOSFET I could find. -The P-channel high-side switch would be the typical architecture for our use -case. However, if we have access to a potential high enough to safely raise the -gate potential above the threshold such that their difference outputs the source -potential required to drive the load, we can switch on the high side using an -N-channel MOSFET: +## N-channel high-side switch  -In the schematic, both M1 and M2 are N-channel MOSFETs. When the -microcontroller output is low, M2 stops conducting. This causes the M1's gate -potential to rise above the threshold, turning the servo on. Conversely, a high -output on the GPIO line switches M2 on, which lowers M1's gate potential. This -switches the servo off. The R2 pull-up resistor prevents the high impedance of -the output pins at power-up from switching the servo on. +Less common but works if you have voltage high enough to drive the gate. Both +M1 and M2 are N-channel. MCU low → M2 off → M1 gate rises above threshold → +servo on. MCU high → M2 on → M1 gate drops → servo off. R2 prevents +high-impedance power-up from switching servo on. -Both topologies require M2 to act as a level converter between circuits -containing the microcontroller and the servo, converting between 0 V and +6 V -or +9 V. M2 is a low-power signal converter carrying less than a milliamp of -current. The gate-source threshold voltage of M2 must be lower than the MCU's -supply voltage. 2N7000, 2N7002, and BSS138 are popular choices for M2. +M2 needed in both topologies for level conversion (0V ↔ +6V or +9V). Carries +<1mA. Gate-source threshold must be lower than MCU supply. Common choices: +2N7000, 2N7002, BSS138. -The D1 flyback diodes used in the two topologies safeguard the MOSFET from -voltage spikes caused by inductive loads such as servos. +Note: D1 flyback diodes protect MOSFETs from voltage spikes caused by inductive +loads (servos, relays). ## A BJT alternative -A Bipolar Junction Transistor (BJT) is a simpler, cheaper, and more widely -available type of transistor that can be used as a switch. -  -In the schematic, when the MCU outputs high, Q2 starts conducting. Q2 amplifies -Q1's base current. Unlike MOSFETs, which are voltage-driven, BJTs are driven by -base current. Resistors R3 and R4 must be chosen carefully to output the -desired base currents. <a +Simpler, cheaper, more available. Q2 conducts when MCU outputs high. Q2 +amplifies Q1's base current. Unlike MOSFETs (voltage-driven), BJTs are +current-driven. R3 and R4 must be calculated for desired base currents. <a href="https://teachmetomake.wordpress.com/how-to-use-a-transistor-as-a-switch/" -class="external" target="_blank" rel="noopener noreferrer">"How to choose a -transistor as a switch"</a> is an excellent guide on using BJTs as electronic -switches. +class="external" target="_blank" rel="noopener noreferrer">Guide on BJT +switches</a>. + +## Which topology? -## Which topology to choose? +MOSFETs preferred in professional work—more efficient when on. Harder to drive +at 3.3V due to V<sub>GS</sub> requirements for full saturation (low +R<sub>DS(on)</sub>). -The professional community appears to prefer MOSFETs over BJTs. MOSFETs are -more efficient when the switch is on. However, they are more challenging to -drive, especially with a 3.3 V MCU, due to the V<sub>GS</sub> potentials -required to achieve specified R<sub>DS(on)</sub> values (i.e., to turn them on -fully). +N-channel: Lower on-resistance, cheaper, more efficient than P-channel. Harder +to drive high-side (gate must be above source—requires extra circuitry like +MOSFET drivers). -N-channel MOSFETs have lower on-resistance values, making them more efficient -than P-channel ones. They are also cheaper. However, they are harder to drive -on the high side as their gate potential must be higher than the source -potential. This often requires extra circuitry such as MOSFET drivers. +Used P-channel high-side for the door lock redesign. Simpler to drive from 3.3V +MCU, no driver needed. ## Further reading @@ -112,12 +84,12 @@ potential. This often requires extra circuitry such as MOSFET drivers. - <a href="https://www.embeddedrelated.com/showarticle/809.php" class="external" target="_blank" rel="noopener noreferrer">How to read MOSFET datasheets</a> - - <a src="https://teachmetomake.wordpress.com/how-to-use-a-transistor-as-a-switch/" + - <a href="https://teachmetomake.wordpress.com/how-to-use-a-transistor-as-a-switch/" class="external" target="_blank" rel="noopener noreferrer">How to use a transistor as a switch</a> - - <a src="https://forum.digikey.com/t/guide-to-selecting-and-controlling-a-mosfet-for-3-3-vdc-logic-applications/42606" + - <a href="https://forum.digikey.com/t/guide-to-selecting-and-controlling-a-mosfet-for-3-3-vdc-logic-applications/42606" class="external" target="_blank" rel="noopener noreferrer">Guide to selecting and controlling a MOSFET for 3.3 VDC logic applications</a> - - <a src="https://forum.digikey.com/t/driving-a-large-relay-from-a-3-3-vdc-microcontroller-using-an-npn-darlington-transistor/41751" + - <a href="https://forum.digikey.com/t/driving-a-large-relay-from-a-3-3-vdc-microcontroller-using-an-npn-darlington-transistor/41751" class="external" target="_blank" rel="noopener noreferrer">Driving a large relay from a 3.3 VDC microcontroller using an NPN Darlington transistor</a> diff --git a/_site/feed.xml b/_site/feed.xml index 77029b1..1447d49 100644 --- a/_site/feed.xml +++ b/_site/feed.xml @@ -1 +1 @@ -<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="/feed.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2025-12-27T11:18:53+08:00</updated><id>/feed.xml</id><title type="html">ASCIIMX | Log</title><author><name>W. D. Sadeep Madurange</name></author><entry><title type="html">Matrix Rain: 2025 refactor</title><link href="/log/matrix-digital-rain/" rel="alternate" type="text/html" title="Matrix Rain: 2025 refactor" /><published>2025-12-21T00:00:00+08:00</published><updated>2025-12-21T00:00:00+08:00</updated><id>/log/matrix-digital-rain</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[The 2022 version worked but had some loose ends. Unicode support was inflexible–couldn’t mix ASCII with Katakana; Phosphor decay was stored in a separate array when it should’ve been packed with RGB; Code was harder to read than it needed to be.]]></summary></entry><entry><title type="html">Fingerprint door lock (LP)</title><link href="/log/fpm-door-lock-lp/" rel="alternate" type="text/html" title="Fingerprint door lock (LP)" /><published>2025-08-18T00:00:00+08:00</published><updated>2025-08-18T00:00:00+08:00</updated><id>/log/fpm-door-lock-lp</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Second iteration of the RF door lock. Old version worked but drew too much quiescent current. Sensor and servo pulled 13.8mA and 4.6mA idle. Linear regulators were a disaster. Battery didn’t last 24 hours.]]></summary></entry><entry><title type="html">On the use of MOSFETs as electronic switches</title><link href="/log/mosfet-switches/" rel="alternate" type="text/html" title="On the use of MOSFETs as electronic switches" /><published>2025-06-22T00:00:00+08:00</published><updated>2025-06-22T00:00:00+08:00</updated><id>/log/mosfet-switches</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Recently, I needed a low-power circuit for one of my battery-operated projects. Much of the system’s power savings depended on its ability to electronically switch off components, such as servos, that draw high levels of quiescent currents. My search for a solution led me to MOSFETs, transistors capable of controlling circuits operating at voltages far above their own.]]></summary></entry><entry><title type="html">How to configure ATmega328P microcontrollers to run at 3.3V and 5V</title><link href="/log/arduino-uno/" rel="alternate" type="text/html" title="How to configure ATmega328P microcontrollers to run at 3.3V and 5V" /><published>2025-06-10T00:00:00+08:00</published><updated>2025-06-10T00:00:00+08:00</updated><id>/log/arduino-uno</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[This is a quick reference for wiring up ATmega328P ICs to run at 5V and 3.3V. While the 5V configuration is common, the 3.3V configuration can be useful in low-power applications and when interfacing with parts that themselves run at 3.3V. In this guide, the 5V setup is configured with a 16MHz crystal oscillator, while the 3.3V configuration makes use of an 8MHz crystal oscillator.]]></summary></entry><entry><title type="html">Fingerprint door lock (RF)</title><link href="/log/fpm-door-lock-rf/" rel="alternate" type="text/html" title="Fingerprint door lock (RF)" /><published>2025-06-05T00:00:00+08:00</published><updated>2025-06-05T00:00:00+08:00</updated><id>/log/fpm-door-lock-rf</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Wanted to unlock door with fingerprint, wirelessly to avoid drilling.]]></summary></entry><entry><title type="html">Bumblebee: browser automation</title><link href="/log/bumblebee/" rel="alternate" type="text/html" title="Bumblebee: browser automation" /><published>2025-04-02T00:00:00+08:00</published><updated>2025-04-02T00:00:00+08:00</updated><id>/log/bumblebee</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Bumblebee is a tool I built for one of my employers to automate the generation of web scraping scripts.]]></summary></entry><entry><title type="html">How to set up ATSAM3X8E microcontrollers for bare-metal programming in C</title><link href="/log/arduino-due/" rel="alternate" type="text/html" title="How to set up ATSAM3X8E microcontrollers for bare-metal programming in C" /><published>2024-09-16T00:00:00+08:00</published><updated>2024-09-16T00:00:00+08:00</updated><id>/log/arduino-due</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[This article is a step-by-step guide for programming bare-metal ATSAM3X8E chips found on Arduino Due boards. It also includes notes on the chip’s memory layout relevant for writing linker scripts. The steps described in this article were tested on an OpenBSD workstation.]]></summary></entry><entry><title type="html">Etlas: e-paper dashboard</title><link href="/log/etlas/" rel="alternate" type="text/html" title="Etlas: e-paper dashboard" /><published>2024-09-05T00:00:00+08:00</published><updated>2024-09-05T00:00:00+08:00</updated><id>/log/etlas</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Etlas is a news, stock market, and weather tracker powered by an ESP32 NodeMCU D1, featuring a 7.5-inch Waveshare e-paper display and a DHT22 sensor module.]]></summary></entry><entry><title type="html">Experimental e-reader</title><link href="/log/e-reader/" rel="alternate" type="text/html" title="Experimental e-reader" /><published>2023-10-24T00:00:00+08:00</published><updated>2023-10-24T00:00:00+08:00</updated><id>/log/e-reader</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[This project features an experimental e-reader powered by an ESP-WROOM-32 development board and a 7.5-inch Waveshare e-paper display built with the intention of learning about e-paper displays.]]></summary></entry><entry><title type="html">Neo4J A* search</title><link href="/log/neo4j-a-star-search/" rel="alternate" type="text/html" title="Neo4J A* search" /><published>2018-03-06T00:00:00+08:00</published><updated>2018-03-06T00:00:00+08:00</updated><id>/log/neo4j-a-star-search</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Back in 2018, we used Neo4J graph database to track the movement of marine vessels. We were interested in the shortest path a ship could take through a network of about 13,000 route points. Graph theoretic algorithms provide optimal solutions to such problems, and the set of route points lends itself well to graph-based modelling.]]></summary></entry></feed>
\ No newline at end of file +<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="/feed.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2025-12-27T12:19:17+08:00</updated><id>/feed.xml</id><title type="html">ASCIIMX | Log</title><author><name>W. D. Sadeep Madurange</name></author><entry><title type="html">Matrix Rain: 2025 refactor</title><link href="/log/matrix-digital-rain/" rel="alternate" type="text/html" title="Matrix Rain: 2025 refactor" /><published>2025-12-21T00:00:00+08:00</published><updated>2025-12-21T00:00:00+08:00</updated><id>/log/matrix-digital-rain</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[The 2022 version worked but had some loose ends. Unicode support was inflexible–couldn’t mix ASCII with Katakana; Phosphor decay was stored in a separate array when it should’ve been packed with RGB; Code was harder to read than it needed to be.]]></summary></entry><entry><title type="html">Fingerprint door lock (LP)</title><link href="/log/fpm-door-lock-lp/" rel="alternate" type="text/html" title="Fingerprint door lock (LP)" /><published>2025-08-18T00:00:00+08:00</published><updated>2025-08-18T00:00:00+08:00</updated><id>/log/fpm-door-lock-lp</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Second iteration of the RF door lock. Old version worked but drew too much quiescent current. Sensor and servo pulled 13.8mA and 4.6mA idle. Linear regulators were a disaster. Battery didn’t last 24 hours.]]></summary></entry><entry><title type="html">High-side MOSFET switching</title><link href="/log/mosfet-switches/" rel="alternate" type="text/html" title="High-side MOSFET switching" /><published>2025-06-22T00:00:00+08:00</published><updated>2025-06-22T00:00:00+08:00</updated><id>/log/mosfet-switches</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Needed low-power switching for the fingerprint door lock. Servo and FPM draw high quiescent current–had to cut power electronically during sleep. MOSFETs can do this.]]></summary></entry><entry><title type="html">How to configure ATmega328P microcontrollers to run at 3.3V and 5V</title><link href="/log/arduino-uno/" rel="alternate" type="text/html" title="How to configure ATmega328P microcontrollers to run at 3.3V and 5V" /><published>2025-06-10T00:00:00+08:00</published><updated>2025-06-10T00:00:00+08:00</updated><id>/log/arduino-uno</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[This is a quick reference for wiring up ATmega328P ICs to run at 5V and 3.3V. While the 5V configuration is common, the 3.3V configuration can be useful in low-power applications and when interfacing with parts that themselves run at 3.3V. In this guide, the 5V setup is configured with a 16MHz crystal oscillator, while the 3.3V configuration makes use of an 8MHz crystal oscillator.]]></summary></entry><entry><title type="html">Fingerprint door lock (RF)</title><link href="/log/fpm-door-lock-rf/" rel="alternate" type="text/html" title="Fingerprint door lock (RF)" /><published>2025-06-05T00:00:00+08:00</published><updated>2025-06-05T00:00:00+08:00</updated><id>/log/fpm-door-lock-rf</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Wanted to unlock door with fingerprint, wirelessly to avoid drilling.]]></summary></entry><entry><title type="html">Bumblebee: browser automation</title><link href="/log/bumblebee/" rel="alternate" type="text/html" title="Bumblebee: browser automation" /><published>2025-04-02T00:00:00+08:00</published><updated>2025-04-02T00:00:00+08:00</updated><id>/log/bumblebee</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Bumblebee is a tool I built for one of my employers to automate the generation of web scraping scripts.]]></summary></entry><entry><title type="html">How to set up ATSAM3X8E microcontrollers for bare-metal programming in C</title><link href="/log/arduino-due/" rel="alternate" type="text/html" title="How to set up ATSAM3X8E microcontrollers for bare-metal programming in C" /><published>2024-09-16T00:00:00+08:00</published><updated>2024-09-16T00:00:00+08:00</updated><id>/log/arduino-due</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[This article is a step-by-step guide for programming bare-metal ATSAM3X8E chips found on Arduino Due boards. It also includes notes on the chip’s memory layout relevant for writing linker scripts. The steps described in this article were tested on an OpenBSD workstation.]]></summary></entry><entry><title type="html">Etlas: e-paper dashboard</title><link href="/log/etlas/" rel="alternate" type="text/html" title="Etlas: e-paper dashboard" /><published>2024-09-05T00:00:00+08:00</published><updated>2024-09-05T00:00:00+08:00</updated><id>/log/etlas</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Etlas is a news, stock market, and weather tracker powered by an ESP32 NodeMCU D1, featuring a 7.5-inch Waveshare e-paper display and a DHT22 sensor module.]]></summary></entry><entry><title type="html">Experimental e-reader</title><link href="/log/e-reader/" rel="alternate" type="text/html" title="Experimental e-reader" /><published>2023-10-24T00:00:00+08:00</published><updated>2023-10-24T00:00:00+08:00</updated><id>/log/e-reader</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[This project features an experimental e-reader powered by an ESP-WROOM-32 development board and a 7.5-inch Waveshare e-paper display built with the intention of learning about e-paper displays.]]></summary></entry><entry><title type="html">Neo4J A* search</title><link href="/log/neo4j-a-star-search/" rel="alternate" type="text/html" title="Neo4J A* search" /><published>2018-03-06T00:00:00+08:00</published><updated>2018-03-06T00:00:00+08:00</updated><id>/log/neo4j-a-star-search</id><author><name>W. D. Sadeep Madurange</name></author><summary type="html"><![CDATA[Back in 2018, we used Neo4J graph database to track the movement of marine vessels. We were interested in the shortest path a ship could take through a network of about 13,000 route points. Graph theoretic algorithms provide optimal solutions to such problems, and the set of route points lends itself well to graph-based modelling.]]></summary></entry></feed>
\ No newline at end of file diff --git a/_site/index.html b/_site/index.html index 2498bda..682339b 100644 --- a/_site/index.html +++ b/_site/index.html @@ -82,7 +82,7 @@ <tr> <td class="posts-td posts-td-link"> - <a href="/log/mosfet-switches/" class="link-decor-none">On the use of MOSFETs as electronic switches</a> + <a href="/log/mosfet-switches/" class="link-decor-none">High-side MOSFET switching</a> </td> <td class="posts-td posts-td-time"> <span class="post-meta"> diff --git a/_site/log/index.html b/_site/log/index.html index b7ebcc5..659609d 100644 --- a/_site/log/index.html +++ b/_site/log/index.html @@ -72,7 +72,7 @@ <tr> <td class="posts-td posts-td-link"> - <a href="/log/mosfet-switches/" class="link-decor-none">On the use of MOSFETs as electronic switches</a> + <a href="/log/mosfet-switches/" class="link-decor-none">High-side MOSFET switching</a> </td> <td class="posts-td posts-td-time"> <span class="post-meta"> diff --git a/_site/log/mosfet-switches/index.html b/_site/log/mosfet-switches/index.html index 3b8f83b..97bba07 100644 --- a/_site/log/mosfet-switches/index.html +++ b/_site/log/mosfet-switches/index.html @@ -2,12 +2,12 @@ <html> <head> <meta charset="utf-8"> - <title>On the use of MOSFETs as electronic switches</title> + <title>High-side MOSFET switching</title> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> - <title>On the use of MOSFETs as electronic switches</title> + <title>High-side MOSFET switching</title> <link rel="stylesheet" href="/assets/css/main.css"> <link rel="stylesheet" href="/assets/css/skeleton.css"> </head> @@ -41,104 +41,76 @@ <main> <div class="container"> <div class="container-2"> - <h2 class="center" id="title">ON THE USE OF MOSFETS AS ELECTRONIC SWITCHES</h2> + <h2 class="center" id="title">HIGH-SIDE MOSFET SWITCHING</h2> <h6 class="center">22 JUNE 2025</h5> <br> - <div class="twocol justify"><p>Recently, I needed a low-power circuit for one of my battery-operated projects. -Much of the system’s power savings depended on its ability to electronically -switch off components, such as servos, that draw high levels of quiescent -currents. My search for a solution led me to MOSFETs, transistors capable of -controlling circuits operating at voltages far above their own.</p> - -<h2 id="acknowledgments">Acknowledgments</h2> - -<p>This article is a summary of what I learnt about using MOSFETs as switches. -I’m not an electronics engineer, and this is not an authoritative guide. The -circuits in this post must be considered within the narrow context in which -I’ve used them. All credits for the schematics belong to <a href="https://electronics.stackexchange.com/users/292884/simon-fitch" class="external" target="_blank" rel="noopener noreferrer">Simon Fitch</a>.</p> - -<h2 id="preamble">Preamble</h2> - -<p>For a typical MOSFET-based switch, we can connect a GPIO pin of a -microcontroller to the gate of a logic-level N-channel MOSFET placed on the low -side of the load and tie the gate and the drain pins of the MOSFET with a -pull-down resistor. This would work as long as the power supplies of the -microcontroller and the load don’t share a common ground. Things become more -complicated when they do (e.g., controlling power to a component driven by the -same microcontroller).</p> - -<p>In that scenario, the source potential visible to the load is the difference -between the gate and the threshold potentials of the MOSFET. For example, when -the gate and the threshold potentials are 3.3 V and 1.5 V, the potential the -load sees is 1.8 V. So, to use a low-side N-channel MOSFET, we need the gate -potential to be higher than the source potential, which may not always be -practical. The alternative would be a hide-side switch.</p> + <div class="twocol justify"><p>Needed low-power switching for the <a href="../fpm-door-lock-lp/">fingerprint door +lock</a>. Servo and FPM draw high quiescent current–had to +cut power electronically during sleep. MOSFETs can do this.</p> -<h2 id="p-channel-high-side-switch">P-channel high-side switch</h2> +<p>Schematics belong to <a href="https://electronics.stackexchange.com/users/292884/simon-fitch" class="external" target="_blank" rel="noopener noreferrer">Simon Fitch</a>.</p> + +<h2 id="problem-with-simple-low-side-switching">Problem with simple low-side switching</h2> + +<p>Typical approach: GPIO → gate of N-channel MOSFET on low side, pull-down +resistor between gate and drain. Works if MCU and load don’t share common +ground. Doesn’t work when they do (like controlling a component powered by the +same MCU).</p> -<p>The following schematic shows how a high-side P-channel MOSFET (M1) could -switch power to a 6 V servo driven by a 3.3 V MCU.</p> +<p>Issue: source potential = gate potential - threshold voltage. Example: 3.3V +gate - 1.5V threshold → 1.8V at load–not nearly enough for a servo. Raising +the gate potential above source is not always practical. Solution: high-side +switch.</p> + +<h2 id="p-channel-high-side-switch">P-channel high-side switch</h2> <p><img src="p_high_side.png" alt="P-channel high-side switching circuit" /></p> -<p>When the microcontroller outputs low, the M2 N-channel MOSFET stops conducting. -The R1 resistor pulls the gate of the M1 P-channel MOSFET up to +6 V, switching -the servo off. When the microcontroller outputs high on the GPIO pin, M2’s -source-drain connection starts conducting, causing M1’s gate potential to drop -to 0 V, which switches on power to the servo.</p> +<p>M1 is P-channel (high-side), M2 is N-channel (level converter). MCU output low +→ M2 off → R1 pulls M1 gate to +6V → servo off. MCU output high → M2 conducts → +M1 gate drops to 0V → servo on.</p> -<h2 id="n-channel-high-side-switch">N-channel high-side switch</h2> +<p>Note: IRF9540 in the schematic doesn’t work. V<sub>GS</sub> (-10V) for +RDS<sub>on</sub> too much for 3.3V ATmega328P to drive. NDP6020P is the only +suitable through-hole MOSFET I could find.</p> -<p>The P-channel high-side switch would be the typical architecture for our use -case. However, if we have access to a potential high enough to safely raise the -gate potential above the threshold such that their difference outputs the source -potential required to drive the load, we can switch on the high side using an -N-channel MOSFET:</p> +<h2 id="n-channel-high-side-switch">N-channel high-side switch</h2> <p><img src="n_high_side.png" alt="N-channel high-side switching circuit" /></p> -<p>In the schematic, both M1 and M2 are N-channel MOSFETs. When the -microcontroller output is low, M2 stops conducting. This causes the M1’s gate -potential to rise above the threshold, turning the servo on. Conversely, a high -output on the GPIO line switches M2 on, which lowers M1’s gate potential. This -switches the servo off. The R2 pull-up resistor prevents the high impedance of -the output pins at power-up from switching the servo on.</p> +<p>Less common but works if you have voltage high enough to drive the gate. Both +M1 and M2 are N-channel. MCU low → M2 off → M1 gate rises above threshold → +servo on. MCU high → M2 on → M1 gate drops → servo off. R2 prevents +high-impedance power-up from switching servo on.</p> -<p>Both topologies require M2 to act as a level converter between circuits -containing the microcontroller and the servo, converting between 0 V and +6 V -or +9 V. M2 is a low-power signal converter carrying less than a milliamp of -current. The gate-source threshold voltage of M2 must be lower than the MCU’s -supply voltage. 2N7000, 2N7002, and BSS138 are popular choices for M2.</p> +<p>M2 needed in both topologies for level conversion (0V ↔ +6V or +9V). Carries +<1mA. Gate-source threshold must be lower than MCU supply. Common choices: +2N7000, 2N7002, BSS138.</p> -<p>The D1 flyback diodes used in the two topologies safeguard the MOSFET from -voltage spikes caused by inductive loads such as servos.</p> +<p>Note: D1 flyback diodes protect MOSFETs from voltage spikes caused by inductive +loads (servos, relays).</p> <h2 id="a-bjt-alternative">A BJT alternative</h2> -<p>A Bipolar Junction Transistor (BJT) is a simpler, cheaper, and more widely -available type of transistor that can be used as a switch.</p> - <p><img src="bjt.png" alt="BJT architecture" /></p> -<p>In the schematic, when the MCU outputs high, Q2 starts conducting. Q2 amplifies -Q1’s base current. Unlike MOSFETs, which are voltage-driven, BJTs are driven by -base current. Resistors R3 and R4 must be chosen carefully to output the -desired base currents. <a href="https://teachmetomake.wordpress.com/how-to-use-a-transistor-as-a-switch/" class="external" target="_blank" rel="noopener noreferrer">“How to choose a -transistor as a switch”</a> is an excellent guide on using BJTs as electronic -switches.</p> +<p>Simpler, cheaper, more available. Q2 conducts when MCU outputs high. Q2 +amplifies Q1’s base current. Unlike MOSFETs (voltage-driven), BJTs are +current-driven. R3 and R4 must be calculated for desired base currents. <a href="https://teachmetomake.wordpress.com/how-to-use-a-transistor-as-a-switch/" class="external" target="_blank" rel="noopener noreferrer">Guide on BJT +switches</a>.</p> + +<h2 id="which-topology">Which topology?</h2> -<h2 id="which-topology-to-choose">Which topology to choose?</h2> +<p>MOSFETs preferred in professional work—more efficient when on. Harder to drive +at 3.3V due to V<sub>GS</sub> requirements for full saturation (low +R<sub>DS(on)</sub>).</p> -<p>The professional community appears to prefer MOSFETs over BJTs. MOSFETs are -more efficient when the switch is on. However, they are more challenging to -drive, especially with a 3.3 V MCU, due to the V<sub>GS</sub> potentials -required to achieve specified R<sub>DS(on)</sub> values (i.e., to turn them on -fully).</p> +<p>N-channel: Lower on-resistance, cheaper, more efficient than P-channel. Harder +to drive high-side (gate must be above source—requires extra circuitry like +MOSFET drivers).</p> -<p>N-channel MOSFETs have lower on-resistance values, making them more efficient -than P-channel ones. They are also cheaper. However, they are harder to drive -on the high side as their gate potential must be higher than the source -potential. This often requires extra circuitry such as MOSFET drivers.</p> +<p>Used P-channel high-side for the door lock redesign. Simpler to drive from 3.3V +MCU, no driver needed.</p> <h2 id="further-reading">Further reading</h2> @@ -147,11 +119,11 @@ potential. This often requires extra circuitry such as MOSFET drivers.</p> topologies</a></li> <li><a href="https://www.embeddedrelated.com/showarticle/809.php" class="external" target="_blank" rel="noopener noreferrer">How to read MOSFET datasheets</a></li> - <li><a src="https://teachmetomake.wordpress.com/how-to-use-a-transistor-as-a-switch/" class="external" target="_blank" rel="noopener noreferrer">How to use a + <li><a href="https://teachmetomake.wordpress.com/how-to-use-a-transistor-as-a-switch/" class="external" target="_blank" rel="noopener noreferrer">How to use a transistor as a switch</a></li> - <li><a src="https://forum.digikey.com/t/guide-to-selecting-and-controlling-a-mosfet-for-3-3-vdc-logic-applications/42606" class="external" target="_blank" rel="noopener noreferrer">Guide to + <li><a href="https://forum.digikey.com/t/guide-to-selecting-and-controlling-a-mosfet-for-3-3-vdc-logic-applications/42606" class="external" target="_blank" rel="noopener noreferrer">Guide to selecting and controlling a MOSFET for 3.3 VDC logic applications</a></li> - <li><a src="https://forum.digikey.com/t/driving-a-large-relay-from-a-3-3-vdc-microcontroller-using-an-npn-darlington-transistor/41751" class="external" target="_blank" rel="noopener noreferrer">Driving a large + <li><a href="https://forum.digikey.com/t/driving-a-large-relay-from-a-3-3-vdc-microcontroller-using-an-npn-darlington-transistor/41751" class="external" target="_blank" rel="noopener noreferrer">Driving a large relay from a 3.3 VDC microcontroller using an NPN Darlington transistor</a></li> </ul> </div> diff --git a/_site/posts.xml b/_site/posts.xml index 03fec7a..05ccd8a 100644 --- a/_site/posts.xml +++ b/_site/posts.xml @@ -1 +1 @@ -<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="/posts.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2025-12-27T11:18:53+08:00</updated><id>/posts.xml</id><title type="html">ASCIIMX</title><author><name>W. D. Sadeep Madurange</name></author></feed>
\ No newline at end of file +<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="/posts.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2025-12-27T12:19:17+08:00</updated><id>/posts.xml</id><title type="html">ASCIIMX</title><author><name>W. D. Sadeep Madurange</name></author></feed>
\ No newline at end of file |
