213 NMOS Low-Side Driver
213-nmos-low-side-driver.mc describes a simple low-side switch.
PWR creates the V5V and GND rails. R_LOAD represents a small load from V5V to the drain of Q_SWITCH. The NMOS source is tied to GND, so the load can conduct when the gate is driven high. GPIO_LOAD reaches the gate through R_GATE, and R_PULL keeps the gate low when the control signal is not driven.
Parse 213-nmos-low-side-driver.mc:
bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 21-digital-io-recipes/213-nmos-low-side-driver.mc --lib mcode --pass1 --pass2Generate HTML for 213-nmos-low-side-driver.mc:
bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 21-digital-io-recipes/213-nmos-low-side-driver.mc --lib mcode --viz -o 21-digital-io-recipes/213-nmos-low-side-driver.htmlSource
text
// Example: NMOS Low-Side Driver
// Goal: Switch a load with an NMOS transistor.
// Library focus: FET.MOSFET.N, RES, GPIO, DC.
module main
{
io GND
io GPIO_LOAD
io V5V
DC.SRC PWR(5V, 200mA)
RES R_LOAD(100R, 50V)
RES R_GATE(100R, 50V)
RES R_PULL(100000R, 50V)
FET.MOSFET.N Q_SWITCH
PWR.1 -> V5V
PWR.2 -> GND
V5V -> R_LOAD -> Q_SWITCH.DRAIN
Q_SWITCH.SOURCE -> GND
GPIO_LOAD -> R_GATE -> Q_SWITCH.GATE
Q_SWITCH.GATE -> R_PULL -> GND
}