← About PHYS 351

PHYS 351 · Advanced Instrumentation

Lecture 04 · Motor control & field-effect transistors

1 Where Lab 4 Sits

In Lab 3 a GPIO pin drove an LED directly. A few milliamps, no moving parts, and the pin was the entire power supply. This week the load is a DC motor that wants hundreds of milliamps, stores energy in its windings, and generates its own voltage when it spins. The pin can no longer be the power supply; it can only give the command.

That separation is the central idea of this lab and of most real embedded hardware:

The one idea to carry out of this lecture

Separate the signal path from the power path. A GPIO pin decides when; a transistor and its own supply decide how much. The two paths meet only at the transistor's gate and at a shared ground.

You already have every idea you need. PWM (§8 of the Lecture 03 notes) sets the average power. The photodiode detector from Lab 1 becomes a tachometer in Task 4. What is new is the MOSFET in between, and the discipline of a shared ground.

1.1 Task map

Lab 4 taskWhat you buildConcept & section
1Generate a range of PWM signals on BCM 12; find the range over which the output is valid; capture scope screenshotsSoftware-PWM limits at extreme frequency and duty (§11)
2Read the IRL510 datasheet, document the pinout, build the motor circuit on a +5 V bench supply, not the PiMOSFET as a switch; flyback diode; grounding (§7–10)
3Move the gate drive from the bench supply to BCM 12 and vary the speedLogic-level gate drive (§5.10)
4Build a rotation-rate detector; tabulate duty vs RPM (≥ 10 points); plot; derive a formula; analyze accuracyOptical tachometry, the RPM–duty relation (§12–13)

2 From Silicon to a Transistor

Lab 4 hands you an IRL510 and expects you to know why it is the right part. That answer starts two steps back, with what a semiconductor is and what the older kind of transistor costs you.

2.1 Doping: making carriers on purpose

Silicon has four valence electrons and shares all four with its neighbors in the crystal. In a perfect crystal nothing is free to move, so pure (intrinsic) silicon is a poor conductor and a poor insulator at the same time. Thermal energy frees the occasional electron and leaves a hole where it used to be, and those two are the only carriers available.

Useful devices begin by spoiling that crystal deliberately:

DopantValence electronsWhat it leaves behindResult
Phosphorusfiveone spare electron per atomn-type: majority carriers are electrons
Boronthreeone missing bond per atomp-type: majority carriers are holes

Both materials are still electrically neutral overall. What has changed is how many carriers are free to move, and of which sign. Everything else in this lecture is built by putting n-type and p-type regions next to each other in different arrangements.

2.2 The PN junction

Join a p region to an n region and electrons from the n side cross over and fill holes on the p side. That leaves a region with no free carriers at all, called the depletion layer, with a built-in potential barrier across it.

A PN junction: P-type silicon with mobile holes on the left, N-type with mobile electrons on the right, and between them a depletion region holding only fixed negative and positive ions. The built-in field points from N to P; the barrier is about 0.7 V in silicon.
Figure 1. A PN junction builds its own barrier. Boron leaves holes on the P side, phosphorus leaves free electrons on the N side. Where they meet, carriers recombine and leave behind only fixed ions (negative on the P side, positive on the N side), whose built-in field, pointing from N to P, stops further flow. The barrier is about 0.7 V in silicon.

Forward bias pushes carriers toward the junction and collapses the barrier at roughly 0.7 V for silicon; current flows. Reverse bias pulls carriers away, so the depletion layer widens and essentially nothing flows. That is a diode, and you already used one as the photodiode in Lab 1.

Forward bias (P to the battery's positive terminal) thins the depletion region and current flows; reverse bias widens it and only leakage flows. The diode I–V curve stays near zero in reverse and rises steeply near 0.7 V forward.
Figure 2. A diode conducts one way. Forward bias (P to the battery’s positive terminal) pushes carriers into the barrier and thins the depletion region until it collapses near 0.7 V, and current flows. Reverse bias pulls carriers out: the depletion region widens and only leakage flows. The I–V curve stays near zero in reverse and rises steeply near 0.7 V forward.
Hold on to one detail.

The width of a depletion layer is set by the voltage across the junction. The JFET in §3.2 exists entirely to exploit that, and the flyback diode in §9.4 is the same device used as a one-way valve.

2.3 The BJT: two junctions, three regions

Stack the doping as n–p–n and you have a bipolar junction transistor: an emitter that is heavily doped, a base that is more lightly doped and physically thin, and a collector that is the most lightly doped of the three (and the largest, because it has to absorb the carriers and the heat). There are two junctions, and in normal operation the base–emitter junction is forward biased while the base–collector junction is reverse biased.

Carriers injected from the emitter into the thin base mostly fail to recombine there, and are swept onward into the collector. A small base current therefore permits a much larger collector current. “Bipolar” is literal: both electrons and holes take part. Counting the currents at the three terminals, IE = IC + IB.

NPN transistor: electrons injected from the heavily doped N+ emitter cross the thin P base to the N collector, a few leaving as base current. The symbol shows I_C = beta I_B and I_E = I_C + I_B; a 1 A load at beta 100 needs 10 mA of base current continuously.
Figure 3. An NPN transistor: electrons injected from the heavily doped N+ emitter cross the thin P base to the N collector, and a few leave as base current. Base–emitter is forward biased, base–collector reverse biased. The symbol shows IC = βIB and IE = IC + IB; a 1 A load at β = 100 needs 10 mA of base current, continuously, for as long as the transistor is on.

2.4 What the BJT costs you

IC = β IB(1)

Equation (1) looks like a bargain until you notice what it demands. The base current is not a one-off charge; it flows for the entire time the device is on. And β is not a constant you can design around confidently: it varies between parts of the same type, and with temperature and collector current.

Worked example: could a GPIO pin do it?

Suppose you wanted a BJT to carry 1 A to a motor, and the part offers β = 50 at that current. The base needs

IB = IC / β = 1 A / 50 = 20 mA

continuously, from whatever drives it. A Raspberry Pi pin is rated at 16 mA, and about 50 mA across the whole header. One motor would consume more than the pin can give, and the pin would be supplying it for as long as the motor ran.

Practice 2

(a) A transistor has β = 120 at 200 mA and β = 40 at 2 A. What base current does each case need, and what does the change tell you about designing for a worst case?

(b) Why does the base of a BJT have to be physically thin? Answer in terms of what happens to carriers that linger there.

(c) Name the two junctions in an NPN transistor and state how each is biased in normal operation.

3 The Field Effect

The field-effect transistor takes a different route to the same goal. Rather than injecting carriers into a region, it uses the electric field from a nearby electrode to change how many carriers an existing path already has. Establishing a field takes charge; holding it takes none. That single fact is why a 3.3 V pin with a 16 mA budget can command amperes.

3.1 The family, and where the IRL510 sits

Every FET has the same three terminals. The channel is the path from drain to source; the gate sets how much of it conducts. Current flows drain to source, and the gate only ever sets the valve position.

TypeGate isModes availableUsed for
JFETa reverse-biased PN junctiondepletion onlyamplifiers, mixers, voltage-controlled resistors
MOSFETmetal over an insulating oxidedepletion or enhancementswitching, logic, power control

Each of those is available as N-channel or P-channel. The IRL510 is an N-channel enhancement-mode MOSFET, and every word of that matters for how you wire it.

FET family tree: JFETs are depletion mode, N- or P-channel; MOSFETs are depletion mode (N-channel) or enhancement mode (N- or P-channel). Each leaf shows its circuit symbol. The enhancement N-channel MOSFET, the IRL510, is highlighted.
Figure 4. The FET family. Drain and source are the two ends of the channel; the gate voltage VGS sets how well it conducts. JFETs are depletion mode, N- or P-channel; MOSFETs are depletion mode (N-channel) or enhancement mode (N- or P-channel). Each leaf shows its circuit symbol, and the one Lab 4 uses, the enhancement N-channel MOSFET (the IRL510), is highlighted.

3.2 The JFET: normally on, squeezed shut

In a JFET the channel is physically present from the start, so the device conducts when the gate is at the same potential as the source. Reverse biasing the gate widens its depletion layer (§2.2) into the channel, narrowing the path until it pinches off entirely.

N-channel JFET cross-sections. At V_GS = 0 the depletion regions around the P gates are thin and the channel is wide; at V_GS = -2 V they are wider and the channel narrow. The transfer curve shows maximum current I_DSS at 0 V falling to zero at pinch-off.
Figure 5. N-channel JFET cross-sections. At VGS = 0 the depletion regions around the P gates are thin and the channel is wide; at VGS = −2 V they are wider and the channel narrow. The transfer curve shows the maximum current IDSS at 0 V, falling to zero at pinch-off. The gate is a PN junction that must stay reverse biased.
Never forward bias a JFET gate.

That gate is one side of a PN junction. Forward biasing it turns the control terminal into a conducting diode, and the device stops behaving like an amplifier at all.

3.3 The MOSFET: put an insulator under the gate

The MOSFET replaces that junction with a thin layer of silicon dioxide. The gate is now a metal plate over an insulator, which makes it one plate of a capacitor rather than one side of a diode. No DC path to the channel exists at all.

Left: MOSFET cross-section showing the metal gate on an oxide layer over p-type silicon between two n+ regions; the insulated gate draws no DC current. Right: drain current against V_GS for a depletion-mode device, which conducts at 0 V, and an enhancement-mode device, which is off until V_th.
Figure 6. Left: an n-channel enhancement MOSFET in cross-section, drawn with the gate at 0 V. The gate never touches the silicon. Raising its voltage repels holes from the surface of the p-type substrate and attracts electrons to it, until the surface has effectively become n-type and joins the two n+ islands into one conducting path (§5.2–5.4 draw it state by state). The gate sits on glass: the thin oxide insulates it, so it is a capacitor, not a diode, and draws no DC current. Right: drain current against VGS for the two kinds of MOSFET (§3.4).

3.4 Enhancement and depletion

The channel in Figure 6 did not exist until the gate created it. A device that works that way is called enhancement mode: it is off with the gate at zero, and the gate voltage that just brings it on is the threshold voltage VGS(th). A depletion mode device is built with a channel already in place, and the gate is used to take it away. The right half of Figure 6 plots both, as shapes rather than datasheet values. What matters is where each curve leaves the horizontal axis: the enhancement device is off until the threshold, and the depletion device is already conducting with its gate at zero.

VGS < 0VGS = 0VGS > 0
Depletion mode, n-channelchannel offchannel onchannel on
Enhancement mode, n-channelchannel offchannel offchannel on
Why a switch wants enhancement mode.

An enhancement device is normally off. If the gate wire falls out, or the Pi has not finished booting, the motor stays stopped. A depletion device would do the opposite, and a loose wire would start the motor. That is the whole argument, and it is also why §9.3 insists on a pull-down resistor: it guarantees the normally-off state even when nothing is driving the gate.

4 FET Against BJT

Both devices let a small signal control a large current. They charge very different prices for it, and the difference is exactly why Lab 4 specifies a MOSFET.

BJTFET
Controlled bybase currentgate voltage
Control terminal drawscurrent, continuouslynothing, once the switching edge is over
Input impedancemoderateextremely high: the gate sits on an insulator
Carriers involvedelectrons and holesone kind only, hence unipolar
Fully on looks likea residual VCE(sat) ≈ 0.2 Va resistance RDS(on)
Conduction loss at 1 A≈ 0.2 W, fixed by that voltageI²RDS(on), and RDS(on) keeps falling with each part generation
Driving it from logica base resistor, and current for the whole on-timeconnect the pin through a gate resistor
Typically destroyed byheat and overcurrentstatic discharge and gate over-voltage

4.1 Why the comparison settles Lab 4

Line them up against the numbers from §8. A BJT carrying the motor current would want tens of milliamps of base current for as long as the motor ran, against a per-pin budget of 16 mA and a header budget of about 50 mA. A MOSFET wants a brief pulse of current to charge its gate capacitance at each switching edge, and nothing at all in between. The pin can afford the second and cannot afford the first.

The loss row matters too. A saturated BJT drops a roughly fixed voltage, so its dissipation rises in proportion to current and you cannot design it away. A MOSFET's loss is I²RDS(on), and RDS(on) is a number you can buy down by choosing a better part.

4.2 What you give up

The oxide that makes the gate free to hold is extremely thin, and it is the part that fails. Static discharge from a fingertip can puncture it, and so can exceeding the actual part's VGS(max). The Vishay IRL510 specifies ±10 V, so a generic ±20 V assumption is inappropriate. A MOSFET that has died usually died at the gate rather than the drain.

Practically: handle the part by its package rather than its leads, do not leave the gate floating (§9.3), and check VGS(max) before connecting anything other than a logic output to it.

Practice 4

(a) A BJT saturates at VCE(sat) = 0.25 V and a MOSFET has RDS(on) = 0.15 Ω. Compute the power each dissipates at 0.3 A and at 3 A. At which current does the MOSFET overtake the BJT, and why does that crossover exist at all?

(b) State two independent reasons a 16 mA GPIO pin cannot drive a BJT that is carrying 1 A.

(c) The gate draws no steady current, yet a gate resistor is still specified. What is it limiting, and when?

5 Inside an Enhancement N-Channel MOSFET

§3 placed the IRL510 in its family. This section opens it up and follows the gate voltage from zero to fully on, one state at a time, then reads the same story off the IRL510 datasheet.

5.1 The structure

Start from a slab of p-type silicon and diffuse two heavily doped n+ islands into its surface: one is the source, the other the drain. Between them, on top of the silicon, grow a thin layer of silicon dioxide and put the gate metal on it. The body, which is the p-type substrate, is wired to the source inside the package.

(A real power MOSFET such as the IRL510 is built vertically, with the drain on the back of the die, which is why the metal tab is the drain. The physics is the same, so these notes use the simpler flat picture.)

Nothing yet connects the islands. There is p-type silicon between them, and its mobile carriers are holes, which cannot carry current from one n+ island to the other.

Enhancement N-channel MOSFET cross-section: n+ source and drain islands in a p-type substrate with mobile holes, a metal gate on SiO2 oxide between them, and the body wired to the source.
Figure 7. An enhancement N-channel MOSFET in cross-section: n+ source and drain islands in a p-type substrate full of mobile holes, a metal gate on SiO₂ between them, and the body wired to the source. P-type silicon is drawn rose and N-type slate throughout the course; holes are circled +, electrons filled dots, fixed ions boxed ±.

5.2 Gate at 0 V: two diodes back to back

With the gate at 0 V, each n+ island forms a PN junction with the p substrate, so between drain and source there are two diodes back to back. Whatever the sign of VDS, one of them is reverse biased and blocks. The device is normally off.

The MOSFET at V_GS = 0: the p substrate forms a PN junction with each n+ island, drawn as two diodes back to back, so one is always reverse biased and no current can flow from drain to source.
Figure 8. The MOSFET at VGS = 0. The substrate makes a PN junction with each island, drawn as two diodes back to back, so no current flows from drain to source.

One refinement for a discrete part like the IRL510. Because the body is tied to the source, the source junction is shorted out and only the drain–body junction is left. It blocks whenever the drain is positive, which is always the case in a low-side switch. If the drain were pulled below the source it would conduct. That is the body diode drawn inside the IRL510 symbol (§5.9), and it is why §9.4 notes that the body diode cannot absorb a positive drain spike.

5.3 A small gate voltage pushes the holes away

Put a small positive voltage on the gate. The gate and the silicon beneath the oxide form a capacitor, so positive charge on the gate metal must be matched by negative charge in the silicon. At first the silicon supplies that charge by losing holes: the gate field pushes them away from the surface and leaves behind the fixed, negatively charged boron ions they were neutralizing. This is a depletion layer, like the one in a PN junction, and like that one it contains no free carriers. The islands are still isolated.

The MOSFET with a gate voltage below threshold: positive charge on the gate pushes holes away from the surface, leaving a depletion layer of fixed negative ions under the gate. There are still no free carriers between source and drain.
Figure 9. Gate voltage below threshold. The positive gate repels holes from the surface and leaves a layer of fixed negative boron ions; there are still no free carriers between source and drain.

5.4 Above threshold, an electron channel forms

Raise the gate further and the depletion layer stops growing. Instead, the gate starts to pull electrons (minority carriers in p-type silicon, but plentiful in the n+ islands next door) into a thin layer right at the surface under the oxide. Once there are more electrons than holes at the surface, that layer behaves as n-type silicon: the surface has been inverted. The inversion layer is an n-type channel joining source to drain, and electrons flow from source to drain along it. The gate voltage at which this happens is the threshold, VGS(th); for the IRL510 it is 1.0–2.0 V.

The MOSFET above threshold: the gate's positive charge draws a thin layer of electrons to the surface under the oxide, forming an n-type channel that joins source and drain; electrons flow from source to drain.
Figure 10. Above threshold. The gate’s positive charge draws a thin layer of electrons to the surface under the oxide, forming an n-type channel that joins source and drain.

5.5 The gate is a capacitor

The whole mechanism runs on capacitor charge. The positive charge on the gate is balanced by an equal negative charge below the oxide, and above threshold that negative charge is channel electrons. More VGS means more gate charge, more electrons in the channel, and a lower channel resistance.

The MOS gate as a capacitor: positive charge on the gate metal, the oxide as dielectric, and an equal negative charge of channel electrons below. Seen from the pin it is a capacitance C_iss of about 250 pF from gate to source; steady gate leakage is at most 100 nA.
Figure 11. The MOS gate as a capacitor: positive charge on the gate metal, the oxide as dielectric, and an equal negative charge of channel electrons below. Seen from the pin it is a capacitance Ciss ≈ 250 pF from gate to source, with a steady leakage of at most 100 nA (IRL510 datasheet).

Holding a voltage costs no current; changing it does. Once the gate is charged, only the ≤ 100 nA leakage flows. Each switching edge moves a charge of at least CissV = 250 pF × 3.3 V ≈ 0.8 nC. The datasheet’s total gate charge, Qg ≤ 6.1 nC to 5 V, is larger, because it is measured while the drain voltage swings and the gate–drain capacitance has to be charged as well. Even the larger figure averages to only Qgf = 6.1 nC × 1 kHz ≈ 6 µA at 1 kHz PWM. The peak current at each edge is a different matter (§9.3).

5.6 Threshold is where it starts, not where it is fully on

The datasheet defines VGS(th) = 1.0–2.0 V at a drain current of only 250 µA. That is the gate voltage at which conduction becomes measurable, not the voltage at which the device is a good switch. Above threshold the current rises steeply. The typical transfer curve (datasheet Fig. 3) gives about 2 A at 3.3 V of gate drive, at 25 °C with short pulses.

IRL510 datasheet Figure 3, typical transfer characteristics: drain current on a logarithmic scale against V_GS from 2 to 5 V at V_DS = 50 V, 20 microsecond pulses, for 25 and 175 degrees C. Near 3.3 V the drain current is about 2 A.
Figure 12. IRL510 typical transfer characteristics: drain current, on a logarithmic scale, against VGS from 2 to 5 V, at VDS = 50 V with 20 µs pulses, for 25 °C and 175 °C. Near 3.3 V the drain current is about 2 A. Source: Vishay IRL510 datasheet, Fig. 3.

Two cautions. The curve is typical, not guaranteed, and a part at the high end of the threshold range delivers less. It was also measured with 50 V across the device, so it shows the most the channel can pass at that gate voltage (saturation, §5.8), not how small the voltage drop is when it switches a motor. About 2 A is enough for a small motor, but it is not a guarantee.

5.7 More gate voltage, lower resistance

In a switch the number that matters is the on-resistance, and the datasheet guarantees it at two gate voltages only: RDS(on) ≤ 0.76 Ω at 4 V and ≤ 0.54 Ω at 5 V. Nothing is specified at 3.3 V.

A simple model shows the trend. In the ohmic region the channel conductance grows in proportion to the gate overdrive, so

RDS(on) ≈ 1k (VGS − Vt)(2)

Fitting it through the two datasheet maxima gives Vt ≈ 1.54 V and k ≈ 0.54 A/V². (Divide the two conditions: 0.54/0.76 = (4 − Vt)/(5 − Vt).) Here Vt is the model’s own threshold. It falls inside the datasheet’s 1.0–2.0 V range for VGS(th), but it is a fitted number, not a measured one. At the Pi’s 3.3 V the model then gives

RDS(on) ≈ 10.54 × (3.3 − 1.54) ≈ 1.1 Ω

This is roughly twice the 5 V value. It is a model extrapolation, not a datasheet number, so measure VDS and ID on the bench and compute the real value. At 0.5 A the model predicts (0.5 A)² × 1.1 Ω ≈ 0.27 W in the transistor. That warms the package by roughly 17 °C with no heatsink (§5.9), which you can feel but which does no harm.

Sketch of IRL510 on-resistance against gate voltage, R = 1/[k(V_GS - V_t)], passing through the datasheet maxima of 0.76 ohm at 4 V and 0.54 ohm at 5 V. The threshold band is 1 to 2 V. At the Pi's 3.3 V the model gives about 1.1 ohm, a value the datasheet does not specify.
Figure 13. A sketch of IRL510 on-resistance against gate voltage, R = 1/[k(VGS − Vt)], drawn through the datasheet maxima of 0.76 Ω at 4 V and 0.54 Ω at 5 V, with the 1–2 V threshold band shaded. At the Pi’s 3.3 V the model gives about 1.1 Ω, a value the datasheet does not specify.

5.8 Raise the drain voltage: ohmic and saturation regions

So far the drain voltage has been small. Raise it and the channel changes shape. The gate-to-channel voltage is VGS at the source end but only VGS − VDS at the drain end, so the channel is thinner there. When VGS − VDS falls to Vth, the channel pinches off at the drain. Raising VDS further moves the pinch point toward the source, and the current stops increasing.

Three MOSFET cross-sections as V_DS increases: at small V_DS the channel is even and acts as a resistor; at V_DS = V_GS - V_th it tapers to nothing at the drain end; at larger V_DS the pinch point moves toward the source and the current saturates.
Figure 14. Three cross-sections as VDS increases. At small VDS the channel is even and acts as a resistor. At VDS = VGS − Vth it tapers to nothing at the drain end. At larger VDS the pinch point moves toward the source and the current saturates.

With the device on, its behavior still depends on the drain-source voltage. At very low VDS the channel behaves as a resistor, and drain current rises in proportion: this is the ohmic or linear region, and the slope is the on resistance RDS(on). As VDS rises the channel pinches near the drain and the current flattens out, set almost entirely by VGS: the saturation region.

In the square-law model, with the overdrive Vov = VGS − Vth (Vth here is the same model threshold as Vt in Equation (2)), the two regions are

ID ≈ k Vov VDS   (ohmic, VDS ≪ Vov)       ID = k2 Vov²   (saturation, VDS ≥ Vov)(3)

The boundary between them is the pinch-off condition VDS = Vov. The ohmic slope, ID/VDS = kVov, is the conductance whose inverse is Equation (2).

Do not push this model too far. With the k and Vt fitted in §5.7, it predicts a saturation current of only about 0.8 A at 3.3 V, well below the roughly 2 A of the typical curve in Figure 12. The square law is a rough description of a power MOSFET, and the fit used worst-case resistances, so treat both numbers as estimates and trust your bench measurement.

Square-law sketch of drain current against V_DS for gate voltages of 2.5, 3.3, 4 and 5 V, with the ohmic region shaded left of the pinch-off boundary. A load line for a 5 V supply and 1.25 ohm load crosses the 5 V curve in the ohmic region (ON) and the 3.3 V curve in saturation, where V_DS is large and the device heats. OFF is at 5 V and zero current.
Figure 15. Drain current against drain–source voltage for gate voltages of 2.5, 3.3, 4 and 5 V: a square-law sketch showing illustrative shapes, not IRL510 data. Left of the pinch-off boundary (shaded) each curve is almost straight: the ohmic region, where the channel acts as the resistance RDS(on) and a switch should operate. Further out the curves flatten into saturation, where the gate voltage sets the current. A load line for a 5 V supply and a 1.25 Ω load crosses the 5 V curve in the ohmic region (ON, small VDS), but crosses the 3.3 V curve in saturation, where VDS is large and the device heats. OFF is at 5 V and zero current. A higher gate level both raises the saturation current and steepens the ohmic slope, which is why RDS(on) is always quoted at a stated VGS.

Whether a given gate voltage is “enough” therefore depends on the load: the channel must be able to carry more current than the load will draw, or the operating point slides into saturation. §9.6 works this check with numbers.

Which region you want depends on the job.

A switch lives hard in the ohmic region, where the device is a small resistance and dissipates little. An amplifier or mixer lives in saturation, where drain current depends on the gate voltage and barely on the load. Lab 4 is a switch, so every calculation in §7 assumes the ohmic region, and §9.6 shows how to check that the assumption holds.

Practice 5

(a) A MOSFET has VGS(th) = 2.0 V. Is it conducting with its gate tied to its source? What mode is it?

(b) Explain, in terms of carriers at the surface of the substrate, why the channel in Figure 10 is called an inversion layer.

(c) You measure 0.18 V across a switched-on MOSFET carrying 0.40 A. What is RDS(on), and which region is the device in?

(d) Why does a JFET have no enhancement mode?

5.9 The IRL510: pinout and the datasheet numbers that matter

The IRL510 comes in a TO-220 package. Hold it with the printed face towards you and the legs down: from left to right the legs are G, D, S (gate, drain, source). The metal tab is connected to the drain, so keep it clear of other conductors. The pinout is not self-explanatory, so mark the legs before you wire it.

IRL510 in a TO-220 package seen from the printed face with legs down: pin 1 gate, pin 2 drain, pin 3 source; the metal tab is the drain. Beside it the N-channel MOSFET symbol with its body diode, labeled with the same pins.
Figure 16. The IRL510 in its TO-220 package, seen from the printed face with the legs down: pin 1 gate, pin 2 drain, pin 3 source, and the metal tab is the drain. Beside it, the N-channel MOSFET symbol with its body diode, labeled with the same pins.
IRL510 datasheet page 1: the TO-220AB package with leads G, D, S and the N-channel MOSFET symbol with its body diode.
Figure 17. The TO-220AB package with leads G, D, S, and the N-channel MOSFET symbol with its body diode. Source: Vishay IRL510 datasheet, page 1.

These are the numbers from the Vishay datasheet that the rest of this lecture uses:

QuantityIRL510Why it matters here
VDS max100 VFar above the 5 V supply, but an unclamped inductive spike can exceed it (§9.4)
VGS max±10 VNot the ±20 V of many parts (§4.2)
VGS(th)1.0–2.0 VDefined at ID = 250 µA only (§5.6)
RDS(on)≤ 0.54 Ω at 5 V, ≤ 0.76 Ω at 4 VUnspecified at 3.3 V (§5.7)
ID continuous5.6 A (case at 25 °C)A case held at 25 °C needs a large heatsink; the bench limit is heat, not this
Ciss, IGSS250 pF, ≤ 100 nAThe gate is a small capacitor with negligible leakage (§5.5)
Gate charge Qg≤ 6.1 nC to 5 VCharge moved at each edge (§5.5)
Rise, fall time47 ns, 18 ns (typical)Negligible against a PWM period of milliseconds
RθJA, no heatsink62 °C per wattTemperature rise = dissipated power × 62 °C/W

5.10 “Logic-level” gates, and why the IRL510 was chosen

The single most important datasheet number for this lab

The Raspberry Pi can only put 3.3 V on a gate. Many power MOSFETs need 10 V to turn on properly; driven at 3.3 V they only partly conduct, sit in a high-resistance state, dissipate serious power and get hot. A logic-level MOSFET is specified to be fully on at 4–5 V of gate drive, and the “L” in IRL510 signals exactly that (compare the IRF510, which is not logic level).

Task 2 asks you to review the datasheet. When you do, find and record: the pin assignment, VGS(th), the RDS(on) and the gate voltage it is quoted at, the continuous drain-current rating, and the maximum VDS. Then state explicitly whether 3.3 V of gate drive is enough, and what the consequence is if it is marginal.

The 3.3 V check

The Vishay IRL510 specifies on-resistance at 4 V and 5 V gate drive. Threshold marks the onset of conduction at a small test current. Neither threshold nor the label “logic-level” guarantees low resistance at 3.3 V. Measure the on-state drain voltage and current under the actual load, then use P = IDVDS to estimate conduction loss. If the drive is inadequate, consult the instructor about a suitable driver or device.

6 CMOS, and the Pin You Have Been Using

This section is a short detour, and it is worth it twice over: it explains the logic family every processor you will ever use is built from, and it explains what is physically behind the GPIO pin you have been driving since Lab 3.

6.1 The complementary pair

Put a p-channel MOSFET above an n-channel MOSFET, tie both gates to the same input and take the output from the join. The two devices have opposite polarities, so any input turns exactly one of them on.

V(DD)Q1Q2p-channeln-channelV(in)V(out)
Figure 18. A CMOS inverter. A low input turns the upper device on and the lower one off, so the output is pulled up to the supply; a high input does the reverse and pulls the output to ground. Every other logic gate is built from the same complementary idea.

6.2 Why static power is nearly zero

In either steady state one of the two devices is off, so there is no conducting path from the supply to ground. A CMOS gate that is sitting still draws almost nothing; it burns power only while it is changing state, charging and discharging the capacitance it drives.

Pstatic ≈ 0       Pdynamic ≈ C V² f(4)

Equation (4) is worth more than it looks. It says a processor's power scales with its clock frequency and with the square of its supply voltage, which is why chips have spent thirty years moving to lower supply voltages, why raising a clock costs power linearly, and why your laptop throttles rather than melting.

6.3 Your GPIO output driver is one of these

Lecture 03 described a GPIO output as “a pair of transistors acting as a two-way switch” and called it push-pull. That pair is a CMOS pair on the chip that drives the pin (the RP1 I/O chip on the Pi 5), drawn exactly as Figure 18. Writing a 1 turns on the upper device and connects the pin to 3.3 V; writing a 0 turns on the lower device and connects it to ground.

So the 16 mA limit is not arbitrary.

It is roughly what those two small on-chip transistors can carry while still holding the pin close to 3.3 V or 0 V, and without damage. Ask for more and the output voltage sags out of its logic range, and the chip heats. The IRL510 you are about to wire up is the same device physics with a far larger die, which is why it can do what the pin cannot.

7 The MOSFET as a Switch

7.1 What the device does

An n-channel MOSFET has three terminals: gate, drain and source. The voltage from gate to source, VGS, controls how freely current flows from drain to source. Used as a switch it has just two states:

  • Off: VGS below the threshold VGS(th). Essentially no drain current.
  • On: VGS well above threshold. The device behaves as a small resistance RDS(on) between drain and source.

The gate is insulated from the channel by a thin oxide layer, so in the steady state it draws essentially no current, only the small transient needed to charge its capacitance at each switching edge. That is exactly what makes it a good match for a GPIO pin: the pin supplies almost nothing, yet it controls amperes.

Three models of a low-side MOSFET under a load on 5 V. OFF at V_GS = 0: an open switch, no current, no power. ON at V_GS = 5 V: a resistor of at most 0.54 ohm, 0.14 W at 0.5 A. Half on near threshold: a current limiter dropping 2.5 V at 0.5 A, 1.25 W.
Figure 19. Three models of a low-side MOSFET under a load on 5 V. OFF at VGS = 0: an open switch, with no current and no power. ON at VGS = 5 V: a resistor of at most 0.54 Ω, 0.14 W at 0.5 A. Half on, near threshold: a current limiter dropping 2.5 V at 0.5 A, 1.25 W.

7.2 Why the power dissipation is small

In the on state the MOSFET dissipates

P = ID² RDS(on)(5)

and in the off state essentially nothing, because ID ≈ 0. A switch that is only ever fully on or fully off wastes very little power in either state. It is the same efficiency argument that made PWM dimming attractive in Lab 3, now with real current.

Worked example

A MOSFET with RDS(on) = 0.54 Ω carries 500 mA:

P = (0.5 A)² × 0.54 Ω = 0.135 W

This is the conduction loss for the assumed resistance. Temperature rise depends on the package and cooling, and PWM transitions add switching loss. Compare this with a linear approach: dropping the same 500 mA across a resistor to halve the motor voltage would burn 0.5 A × 2.5 V = 1.25 W, roughly ten times as much, as heat. Measure your IRL510's actual RDS(on) (§5.7) and repeat this calculation with your measured current.

The transistor itself is where the half-on case hurts. Without a heatsink the IRL510 rises RθJA = 62 °C for every watt it dissipates. Fully on at 0.5 A, 0.135 W × 62 °C/W ≈ 8 °C: barely warm. Half on at the same current, 1.25 W × 62 °C/W ≈ 78 °C above room temperature: too hot to touch, and on its way to failure. Fully on or fully off, it wastes almost nothing; half on, it burns the difference. That is why a switch must be driven hard into the ohmic region and why the gate voltage in §5.7 matters.

8 Why a GPIO Pin Cannot Drive a Motor

Three independent reasons, any one of which is sufficient.

8.1 Current

A GPIO pin is rated at 16 mA, with about 50 mA total across the whole header. A small brushed DC motor typically draws hundreds of milliamps while running freely, and several times that at stall, the moment of starting or any time the shaft is held. Stall current is the number that destroys things, and it is the one to look up.

Istall = VsupplyRwinding(6)

With no rotation there is no back-EMF (§8.3), so the only thing limiting the current is the winding's DC resistance, often only an ohm or two. Measure Rwinding with the DMM and compute Istall before you connect anything. It is a striking number, and it is worth putting in your report.

Currents on a logarithmic scale: IRL510 steady gate leakage 100 nA, GPIO pin rating 16 mA, all GPIO pins together 50 mA, a small DC motor running about 400 mA, a 5 V, 2.5 ohm motor at stall 2 A, and the IRL510 continuous rating 5.6 A. A line marks what a pin may supply.
Figure 20. The currents in Lab 4 on one logarithmic scale: the IRL510’s steady gate leakage (100 nA), a GPIO pin’s rating (16 mA), all GPIO pins together (50 mA), a small DC motor running (about 400 mA), a 5 V, 2.5 Ω motor at stall (2 A), and the IRL510’s continuous rating (5.6 A). The line marks what a pin may supply. The gate needs almost nothing; the motor needs far more than a pin can give. Measure your own motor’s winding resistance.
Worked example: stall current

A motor on a 5 V supply has a winding resistance of 2.5 Ω. At rest, Equation (6) gives

Istall = 5 V2.5 Ω = 2 A

That is 125 times the 16 mA a GPIO pin is rated for. As the motor accelerates, back-EMF (§8.3) opposes the supply and the current falls toward its running value. But the switch sees the start-up peak every time the motor starts or stalls. The GPIO pin can only supply the control signal to a power switch.

8.2 Inductance

A motor winding is an inductor. Current through an inductor cannot change instantaneously, and interrupting it produces a voltage spike

VL = −L dIdt(7)

Switching at PWM rates means interrupting that current hundreds or thousands of times a second. With a fast switch, dI/dt is enormous and the spike can reach tens or hundreds of volts. That is far beyond anything a 3.3 V pin can survive, and it can exceed even the IRL510’s 100 V rating. §9.4 deals with this.

8.3 Back-EMF

A spinning motor is also a generator. The rotating windings cut flux and produce a voltage opposing the supply, proportional to angular velocity:

Vback = ke ω(8)

This is useful. It is why a motor draws far less current at speed than at stall, and it is the reason the speed settles rather than running away. But it also means a coasting motor feeds voltage back into your circuit after you switch off, which is another reason the power path must be isolated from the Pi.

9 Wiring the Switch

9.1 The Pi sends the signal; the supply sends the power

The circuit has two paths, and it helps to trace them separately. The power path carries amperes at 5 V: from the bench supply through the motor, into the drain, out of the source, and back to the supply. The signal path carries milliamps at 3.3 V, mostly at the switching edges: from BCM 12 through the gate resistor into the gate capacitance.

The two paths meet in only two places: at the gate, and at one shared ground. Without that shared ground, VGS is undefined, because it is measured from the source, and the source sits on the supply’s ground (§10).

Low-side motor drive: a +5 V bench supply feeds the motor, with a flyback diode across it, into the MOSFET drain; the source goes to a common ground bus shared with the Pi. BCM 12 drives the gate through 470 ohm, with a 10 kilohm pull-down. The power path (amps, 5 V) and signal path (milliamps only at edges, 3.3 V) are highlighted separately.
Figure 21. The low-side motor drive with its two paths highlighted. Power path: the +5 V bench supply feeds the motor, which has a flyback diode across it, into the MOSFET drain; the source returns to a common ground bus shared with the Pi. Signal path: BCM 12 drives the gate through 470 Ω, with a 10 kΩ pull-down.

9.2 Low-side switching

Put the MOSFET between the load and ground: supply, then motor, then drain, with source to ground. This is low-side switching, and it is the arrangement to use here.

The reason is physics, not style: the gate voltage is measured with respect to the source. With the source bolted to ground, VGS is simply the GPIO pin's voltage, and the switch behaves predictably. If you instead put the MOSFET above the load (high-side), the source sits at the motor terminal and rises as the device turns on. VGS shrinks until the transistor is barely conducting, so it never turns fully on and runs hot. That is why high-side switching needs a P-channel device or a dedicated gate driver.

Low side: motor between +5 V and the drain, source grounded, so V_GS equals the full 3.3 V. High side: MOSFET between +5 V and the motor; as it turns on the source rises until V_GS is about V_th, so the gate drive collapses and it needs a P-channel device or a gate driver.
Figure 22. Low side (left): the motor between +5 V and the drain, the source grounded, so VGS is the pin’s full 3.3 V. High side (right): the MOSFET between +5 V and the motor. As it turns on, the source rises until VGS is about Vth, so the gate drive collapses; that arrangement needs a P-channel device or a gate driver.

9.3 The gate resistor and the pull-down

Two small components make the circuit behave:

  • A series gate resistor of a few hundred ohms limits the current the GPIO pin must supply while charging the gate capacitance at each edge. Without it, the momentary current at a switching edge can exceed the pin rating even though the steady-state gate current is zero.
  • A pull-down resistor of around 10 kΩ from gate to source holds the gate at 0 V whenever the pin is not actively driving it: while the Pi boots, after GPIO.cleanup(), or if a wire falls out. Without it the gate floats, and a floating gate on a high-impedance input can drift up and switch the motor on by itself.

The numbers for the lab values, 470 Ω and 10 kΩ, with the IRL510’s Ciss ≈ 250 pF (§5.5):

  • Peak gate current. At the instant the pin goes high the gate is still at 0 V, so the whole 3.3 V is across the resistor: 3.3 V/470 Ω ≈ 7 mA, inside the pin’s 16 mA rating.
  • Edge time. The gate charges with time constant RGCiss = 470 Ω × 250 pF ≈ 118 ns, so the gate current has decayed within about half a microsecond. With the motor connected, the gate must also supply the gate–drain charge while the drain swings (up to 3.3 nC, the “Miller plateau”), and only about a milliamp is left to do it, so the real switching edge stretches to a few microseconds. That is still negligible against a PWM period of milliseconds.
  • Steady state. The two resistors form a divider, so the gate settles at 3.3 V × 10 kΩ/10.47 kΩ ≈ 3.15 V rather than the full 3.3 V, and the pin supplies a steady 3.3 V/10.47 kΩ ≈ 0.3 mA while it is high. Both are small prices for a gate that can never float.
Gate network: GPIO through a 470 ohm gate resistor to the gate capacitance, with a 10 kilohm pull-down to ground that holds the gate at 0 V when the pin is undriven. Plots: V_GS rises to 3.3 V with time constant R_G C_iss of about 118 ns; the gate current peaks at 7 mA and decays within half a microsecond.
Figure 23. The gate network: the GPIO pin drives the gate capacitance through a 470 Ω gate resistor, and a 10 kΩ pull-down holds the gate at 0 V whenever the pin is undriven, for example while the Pi boots. VGS rises with time constant RGCiss ≈ 118 ns; the gate current peaks at 7 mA and decays within half a microsecond.

9.4 The flyback diode

This is the component most often left out, and leaving it out destroys MOSFETs.

When the MOSFET switches off, the motor's winding current has nowhere to go. By Equation (7) the inductor develops whatever voltage it takes to keep that current flowing. With the switch open, that voltage appears across the MOSFET's drain and can far exceed its VDS rating.

The fix, and the rule for connecting it

Connect a diode across the motor terminals, oriented so that it is reverse-biased by the normal supply voltage: cathode (the banded end) to the positive supply, anode to the drain.

In normal operation it does nothing. At switch-off, the inductor's reversed voltage forward-biases it, giving the winding current a path to circulate and decay gently instead of spiking. The spike is clamped to roughly one diode drop above the supply.

Fit it backwards and it short-circuits your supply through a forward-biased diode, so check the band before powering up. Take this one seriously: it is the one orientation error in this lab that produces smoke rather than a wrong reading.

Keep the flyback diode fitted at all times. To see it working, put a suitably rated scope probe on the drain, with its ground clip on the common ground, and check that the voltage at switch-off is clamped near the supply. If you want to see what happens without the diode, do that in a simulation, not on the bench. And do not count on the MOSFET’s body diode instead: it points from source to drain, so it offers no path for a positive spike on the drain in this low-side circuit.

Three circuits of a motor coil, switch and +5 V: ON, current flows through coil and switch; OFF without a diode, the interrupted coil current produces a drain spike; OFF with a flyback diode across the coil, the current circulates through the diode. Below, the drain voltage spikes (illustrative height) without the diode and is clamped near 5.7 V with it.
Figure 24. A motor is an inductor. ON: current flows through the coil and the switch. OFF without a diode: the interrupted coil current produces a spike at the drain (its height here is illustrative). OFF with a flyback diode across the coil: the current circulates through the diode and decays. Below, the drain voltage spikes without the diode and is clamped with it near 5.7 V, the supply plus one diode drop. Band (cathode) to +5 V, anode to the drain.

9.5 Example: an IRL510 LED driver

The same low-side switch works for any load too big for a pin. In this example from the lecture, an LED and a 100 Ω resistor sit between a 5 V supply and the drain, the source is grounded, the gate receives a 0–5 V square wave at 2 Hz, and a 20 kΩ pull-down holds the gate low when nothing drives it.

I ≈ 5 V − 2 V100 Ω = 30 mA

That is nearly twice a GPIO pin’s 16 mA rating, but trivial for the FET. (It is also at or above the rating of many LEDs, which is often 20 mA; check yours, and use 150 Ω if it is.) At 5 V of gate drive its RDS(on) ≤ 0.54 Ω drops at most 30 mA × 0.54 Ω ≈ 16 mV and dissipates under half a milliwatt. The 2 Hz drive makes the switching visible by eye; at PWM rates the same circuit dims the LED.

Simulated IRL510 low-side LED driver: a supply feeds a resistor and LED into the drain; the source is grounded, the gate receives a pulse waveform, and a gate pull-down holds it off when undriven.
Figure 25. A simulated IRL510 low-side LED driver: the supply feeds a resistor and LED into the drain, the source is grounded, the gate receives a pulse waveform, and a gate pull-down holds it off when undriven.

9.6 Example: how much current reaches the motor?

A second worked example from the lecture uses a different power MOSFET, the MTP4N80E. A 30 Ω motor sits on a 30 V supply, and the gate is driven from 0 to 10 V. At VGS = 10 V this part has RDS(on) = 1.95 Ω, and it can carry ID(on) = 2 A before its channel saturates.

Which region is it in? The most current the load itself would allow, with the transistor a perfect short, is

ID(max) = 30 V30 Ω = 1 A < ID(on) = 2 A

The load limits the current before the channel can, so the transistor is in the ohmic region and behaves as a small resistor in series with the motor:

ID = 30 V30 Ω + 1.95 Ω = 0.939 A      P = (0.939 A)² × 1.95 Ω = 1.7 W

This is the method for any switch: check that the load, not the transistor, sets the current, and then treat the transistor as RDS(on). Here 1.7 W is a real amount of heat. In a TO-220 package with no heatsink, at about 62 °C/W, it would mean a rise of roughly 100 °C, so this driver needs a heatsink.

Illustrative power-MOSFET motor driver: a motor connects between a 30 V supply and the drain, source is grounded, and a diode lies across the motor. The gate waveform is labeled 0 to 10 V.
Figure 26. An illustrative power-MOSFET motor driver: the motor connects between a 30 V supply and the drain, the source is grounded, a diode lies across the motor, and the gate is driven from 0 to 10 V.

10 The Complete Motor-Drive Circuit

Low-side motor driver: the motor lies between positive supply and MOSFET drain, source connects to ground, and the GPIO drives the gate through a resistor with a pull-down to ground. A flyback diode across the motor is reverse-biased during normal operation.
Figure 27. Low-side drive. The motor runs from its own +5 V bench supply; the Pi contributes only a PWM signal into the gate. The two systems share one ground, which is what makes the gate voltage meaningful. The gate is driven from BCM 12 through a resistor, with a pull-down to ground, and the flyback diode across the motor is reverse-biased in normal operation.
The common ground is not optional

The Pi's ground and the bench supply's negative terminal must be connected together. VGS is a voltage difference between the gate and the source, and the source sits on the bench supply's ground. If the two grounds are not tied, that difference is undefined: the circuit will behave erratically, work intermittently, or not at all. Worse, the fault is invisible in a schematic that draws two separate ground symbols.

This is the single most common wiring error in Lab 4. If the motor does nothing when you switch to Pi control in Task 3, check the ground connection first.

Bring-up order, matching Tasks 2 and 3
  1. Task 2, with a bench supply on the gate. Build the circuit and drive the gate from a fixed +5 V, so the motor either runs or does not. This isolates the power path: if it works here, the power circuit is sound.

  2. Have an instructor or TA check the circuit before powering the motor; Task 2 requires this.

  3. Task 3. Disconnect the +5 V gate supply, connect BCM 12 (physical pin 32) to the gate resistor, and confirm the common ground: header pin 34 (GND) to the supply’s negative terminal. Now the signal path is under test, and only one thing has changed.

  4. PWM the gate and vary the speed (§11–13).

Changing one thing at a time is why Lab 4 is structured this way. Resist the temptation to build it all at once.

11 PWM Revisited: the Range of Validity

A quick rewind from Lecture 03. A PWM signal is HIGH for ton of every period T. With the duty fraction d = ton/T, the average voltage is ⟨V⟩ = dVhigh. In RPi.GPIO:

  • p = GPIO.PWM(12, f) creates a PWM generator on BCM 12 at f hertz;
  • p.start(D) starts it, with the duty D in percent;
  • p.ChangeDutyCycle(D) changes the duty while it runs.

It is software PWM, so check what it actually produces on the scope.

Three 3.3 V PWM waveforms with equal period and duty cycles of 20, 50, and 80 percent. Their ideal average voltages are 0.66, 1.65, and 2.64 V.
Figure 28. Three 3.3 V PWM waveforms with equal period and duty cycles of 20%, 50% and 80%. Their ideal average voltages are 0.66, 1.65 and 2.64 V.

On the gate, PWM sets the motor’s average voltage. The MOSFET switches the motor between 0 and the full 5 V, and the motor averages the pulses twice over: the coil’s inductance smooths the current (when the PWM period is short compared with the coil’s L/R time), and the rotor’s inertia smooths the speed.

Illustration at 60 percent duty: the gate switches between 0 and 3.3 V, the motor voltage between 0 and 5 V with an average of 3 V, and the motor current rises and falls in small ramps around a steady average because the coil smooths it.
Figure 29. PWM on the gate at 60% duty (an illustration). The gate switches between 0 and 3.3 V; the motor voltage switches between 0 and 5 V, averaging 0.60 × 5 V = 3 V; and the motor current rises and falls in small ramps around a steady average, because the coil smooths it.

Task 1 asks for something more searching than “make a PWM signal”: it asks for which frequency and duty-cycle values it functions as expected. That is a characterization task, and the answer is a region on a two-dimensional map, not a single number.

11.1 What “as expected” means

Define the criterion before you measure, and state it in your report. A reasonable set:

  • The measured frequency is within a stated tolerance of the commanded frequency (say 5%).
  • The measured duty cycle is within a stated tolerance of the commanded duty cycle.
  • The waveform still has clean, full-amplitude transitions between 0 V and 3.3 V.
  • The jitter is small compared with the period.

11.2 Where it breaks down, and why

Recall from Lecture 03 that GPIO.PWM() is software PWM: a background thread toggles the pin, so every edge is placed by the CPU under a non-real-time operating system. Four distinct failure modes follow, and you should look for all four:

RegionWhat you will see, and the reason
Very low frequency
below a few Hz
Works fine electrically. The motor will not run smoothly, though: it receives discrete kicks rather than a steady average, because the PWM period is longer than the motor's mechanical time constant (§13.3).
Useful mid-bandFrequency and duty both track the commands. This is the region you will use for the motor.
High frequencyThe commanded period approaches the time the CPU needs to service an edge. The measured frequency falls below the command, the duty cycle drifts from its setting, and jitter grows as a fraction of the period. Find this ceiling and record it.
Extreme duty cycles
near 0% and near 100%
The on-time (or off-time) becomes shorter than the software can reliably produce, so the narrow pulses become erratic, get stretched, or disappear entirely. This failure depends on frequency, because ton = d/f: 1% duty is 10 ms at 1 Hz and 10 µs at 1 kHz. Note the distinction; it makes a good observation for the report.
How to organize Task 1

Sweep a grid rather than a line: pick five or six frequencies spanning several decades, and at each one measure duty cycles of roughly 1, 5, 25, 50, 75, 95 and 99%. At every point record commanded and measured frequency, commanded and measured duty, and a jitter figure from the scope's measurement statistics.

Present the result as a table plus a simple map showing where the criteria hold and where they fail. Capture scope screenshots at a few representative points (one clean, one at the frequency ceiling, one at an extreme duty cycle) rather than one per grid point.

Practice 11

(a) At 1 kHz, what on-time does a commanded duty cycle of 2% correspond to? At 20 Hz?

(b) If the software can only place an edge to within about 150 µs, estimate the lowest duty cycle that is reliable at 1 kHz, and at 50 Hz.

(c) A student reports “PWM works from 1 Hz to 10 kHz.” What is missing from that statement?

12 Measuring Rotation Rate

Task 4 asks you to design a detection system, and hints at an LED and a photodiode. This is a satisfying moment in the course: the light detector you built in Lab 1 becomes the sensor for the motor you built this week.

12.1 The principle

First, a rewind from Lecture 01. A photodiode is a light-controlled current source: the photocurrent Iphoto is proportional to the light falling on it. The transimpedance amplifier (TIA) turns that current into a voltage, Vout = −IphotoRf. Block the light and the output steps; that step is a tachometer pulse.

Photodiode equivalent circuit: photocurrent source Iph is in parallel with diode resistance rd and capacitance Cd; series resistance rs connects that parallel network to the output terminal.
Figure 30. The photodiode equivalent circuit: a photocurrent source Iph in parallel with the diode’s resistance rd and capacitance Cd, with a series resistance rs to the output terminal.
Transimpedance amplifier schematic. Photocurrent enters the inverting node, a feedback resistor connects output to that node, and the non-inverting input is grounded. Negative feedback holds the inverting node near zero volts.
Figure 31. The transimpedance amplifier. The photocurrent enters the inverting node, a feedback resistor Rf connects the output to that node, and the non-inverting input is grounded. Negative feedback holds the inverting node near 0 V, so all of the photocurrent flows through Rf.

Put an LED on one side of the spinning shaft and a photodiode on the other, and attach something to the shaft that interrupts the beam once (or N times) per revolution: a card with a slot, a strip of tape, a paper disc with holes. Each interruption produces a pulse. Count pulses over a known time and you have the rotation rate:

RPM = pulsesN × tgate × 60(9)

with tgate the counting interval in seconds and N the number of interruptions per revolution. Alternatively, measure the period between successive pulses on the oscilloscope and invert it. That is often the quicker route, and it needs no code at all. Count the pulses on the scope first, then with a GPIO input, but only after reading the warning below.

Optical tachometer: a slotted disc on the motor shaft passes between an LED and a photodiode; the photodiode feeds the transimpedance amplifier from Lab 1, whose output, a pulse each time a slot passes the beam, goes to a scope or GPIO input where the period T is measured.
Figure 32. An optical tachometer. A slotted disc on the motor shaft passes between an LED and a photodiode; the photodiode feeds the transimpedance amplifier from Lab 1, whose output is a pulse each time a slot passes the beam. The pulses go to the scope, or, once converted to 0–3.3 V logic, to a GPIO input, where the period T is measured. N slots give N pulses per revolution.
Never wire the Lab 1 TIA straight to a GPIO pin

The TIA from Lab 1 runs on ±15 V, and its output swings negative, down to about −14 V. A GPIO input accepts only 0 to 3.3 V, so a direct connection can destroy the Pi. The scope can take any of these voltages, so do your first measurements there. To count pulses with a GPIO input, first turn them into clean 0–3.3 V logic, for example with an open-collector comparator pulled up to the Pi’s 3.3 V. Check the result on the scope, and have a TA look at the circuit, before it goes anywhere near the header.

In terms of the pulse frequency the scope reports,

RPM = 60 fpulseN(10)
Worked example: a two-slot interrupter

With N = 2 and pulses arriving at fpulse = 80 Hz, the shaft turns 80/2 = 40 times per second, which is 60 × 40 = 2400 RPM. Assume N = 1 by mistake and you would report 4800 RPM.

Illustrative TIA output over 50 ms: pulses repeating every 12.5 ms, so f = 80 Hz, with a small 120 Hz ripple on the baseline from room lighting.
Figure 33. An illustrative TIA output over 50 ms: pulses repeating every 12.5 ms, so f = 80 Hz, as in the worked example above. The small ripple on the baseline is at 120 Hz, from room lighting (§12.2).
Get N right, or everything scales wrong

A single strip of tape gives one pulse per revolution. A disc with four slots gives four. A two-bladed interrupter gives two. If you get N wrong, every RPM in your table is wrong by that factor and your derived formula is wrong with it, while still looking perfectly self-consistent. State N explicitly in your report and justify it from the geometry you built.

12.2 Making the pulses clean

A raw photodiode signal is a small, slow, rounded bump, not a crisp pulse. Three things help, in increasing order of effort:

  1. Use the TIA from Lab 1 rather than a bare resistor. It gives real gain and holds the diode at a fixed bias, so the pulse is bigger and better shaped.
  2. Shield from room light. The overhead fluorescents flicker at 120 Hz, which lands squarely in the range of rotation rates you are trying to measure. It is an excellent way to record a completely fictitious RPM. Shroud the detector, and check what it reads with the motor stopped.
  3. Measure on the scope first. Confirm you have a clean, repeating pulse train before you write any counting code. If the waveform is ambiguous on screen, no amount of software will rescue it.
Two counting traps

Double counting. If the signal is noisy or the edges are slow, one interruption can register as several. On the scope this shows as extra small transitions at each edge. Cleaning up the optics or adding hysteresis is the real fix.

Counting the PWM. The motor is being switched at your PWM frequency. If that switching couples into the detector, electrically through a shared supply or optically if the motor has an indicator LED, you may count PWM edges instead of revolutions. A giveaway is a measured “RPM” that tracks the PWM frequency rather than the motor speed. Test for it by changing the PWM frequency at a fixed duty cycle: the true rotation rate should barely move.

13 What the RPM-vs-Duty Curve Looks Like

Task 4 asks for at least ten data points, a plot, a derived formula, and an analysis of accuracy. Knowing the shape in advance tells you where to put your points.

Conceptual motor speed versus PWM duty: an initial dead zone is followed by an approximately linear rise and then flattening at high duty. Actual values must be measured.
Figure 34. The expected shape of the speed–duty curve, drawn as an illustration rather than bench data: a dead zone below D0 (shaded), a roughly linear rise, and flattening toward the no-load speed. Fit Equation (11) only to the linear part, and take your motor’s numbers from measurement.

13.1 Three regions

  1. Dead zone. Below some duty cycle D0 the motor does not turn at all. The average torque is less than the static friction holding it still. This region is real, reproducible, and must appear in your data, so do not skip it.
  2. Roughly linear region. Above D0, the average applied voltage is (D/100) Vsupply, with D the duty cycle in percent, and from Equation (8) the steady-state speed is set by the balance between applied voltage and back-EMF. Speed therefore rises approximately linearly with duty cycle:
    RPM ≈ k(D − D0) (11)
    with D and D0 in percent, so k is in RPM per percentage point.
  3. Saturation. Approaching 100% duty the curve flattens as the motor reaches its no-load speed for that supply voltage.
Where to put your ten points

Do not space them evenly from 0 to 100%. Put several points close together around the dead-zone edge, where the interesting behavior is and where D0 is determined; spread the rest across the linear region; and take two or three near the top to show the flattening. Ten well-placed points say far more than twenty evenly spaced ones.

Fit Equation (11) to the linear region only, and say in your report which points you included and why. Quote k in RPM per percentage point of duty, with units, and D0 as a percentage.

13.2 Hysteresis: a result worth looking for

Take your data twice: once increasing the duty cycle from zero, once decreasing it from 100%. The motor typically keeps turning down to a lower duty cycle than the one needed to start it, because sliding friction is less than static friction and the spinning rotor has angular momentum.

If you find this, you have measured a real physical effect rather than just filling in a table, and that kind of observation lifts a lab report. If you do not find it, say so. A null result, honestly reported, is still a result.

13.3 Choosing the PWM frequency for the motor

The motor's mechanical time constant is the rotor's inertia divided by the damping, typically tens of milliseconds. If the PWM period is much shorter than that, the rotor cannot follow individual pulses and responds only to the average, which is what you want. If the period is comparable or longer, the motor jerks once per cycle.

Practically: a few hundred hertz to a few kilohertz works well. The instructor's reference code uses 50 Hz, which is a reasonable starting point and low enough that you can see the switching on the scope alongside the motor's response. Its 20 ms period is not much shorter than the mechanical time constant, though, so at low duty you may hear or feel the individual pulses. Try a few hundred hertz as well and compare. Above roughly 20 kHz the switching becomes inaudible, which is why commercial motor drives run there, but software PWM on the Pi will not get you that far reliably (§11.2). Report which frequency you used and why.

Practice 13

(a) A motor reaches 2400 RPM at 100% duty and has a dead zone up to 15%. Estimate k in Equation (11) and predict the RPM at 50% duty.

(b) Your tachometer counts 250 pulses in 5.0 s with a two-slot disc. What is the RPM? What would you have reported had you assumed one slot?

(c) The motor draws 0.45 A running and its winding measures 2.2 Ω on a 5 V supply. Compute the stall current and state the ratio to the running current.

(d) Name two distinct sources of error in your RPM measurement and estimate the size of each.

14 Measurement Technique

What you are measuringHowWatch out for
PWM gate signal (Task 1)Scope probe on BCM 12, ground clip to a header ground pin. DC coupling; measure Period, +Width, Duty with statistics on.AC coupling makes the duty-cycle reading meaningless.
Drain waveformProbe the MOSFET drain, ground clip to the common ground.Inductive spikes can exceed the probe's rating if the flyback diode is missing. Fit the diode first.
Motor currentDMM in series on the supply side, or the voltage across a small sense resistor.The reading is a time-average of a switched current; say so when quoting it.
Winding resistanceDMM on ohms, motor disconnected from everything.Brushed motors read differently at different shaft positions, so take several readings and quote the range.
Rotation rateTachometer pulse train on the scope; read Frequency directly, or count in software.Confirm N; shield from room light; verify the reading is zero with the motor stopped.

15 Common Mistakes and Bench Safety

15.1 Things that destroy hardware

  • No flyback diode, or the diode fitted backwards. The first kills the MOSFET; the second shorts the supply.
  • Motor powered from the Pi. Lab 4 states this explicitly: use a separate +5 V supply. The Pi's 5 V pin can brown out the board, or worse.
  • Missing common ground. Undefined gate voltage, unpredictable switching.
  • Motor terminals touching the Pi header. Back-EMF from a coasting motor can appear at the terminals after switch-off.
  • Bench supply current limit set high. Set it to somewhat above the expected running current before first power-up. A current limit is a fuse you can reset, and it converts a wiring error into a lesson rather than a replacement part.

15.2 Things that waste your afternoon

  • Confusing the MOSFET's pins. Identify D, G and S from the datasheet and mark them; the package outline is not self-explanatory.
  • Using a non-logic-level part. An IRF510 will half-turn-on at 3.3 V, run hot and give a weak, nonlinear response.
  • Forgetting the gate pull-down, then wondering why the motor twitches during boot.
  • Room light contaminating the tachometer (§12.2).
  • Taking RPM data before the motor has settled. Give it a second or two at each duty cycle.
  • A loose interrupter flag that shifts position mid-run, silently changing N.

15.3 Mechanical safety

A motor shaft spins fast enough to catch hair, sleeves and probe leads. Secure the motor to the bench; do not hold it in your hand. Keep the interrupter flag light and well attached; a stiff card thrown off a shaft at speed is a real eye hazard. Wear eye protection while the motor runs, and switch off before adjusting anything mechanical.

15.4 Before you leave

Transfer all programs, data and screenshots to your laptop, power down the Pi cleanly, turn off the bench supply, and return components. Verify the copy opens on your machine before deleting anything from the Pi.

16 Self-Check

  1. What does adding phosphorus to silicon produce, and what does adding boron produce? Name the majority carrier in each case.
  2. Describe a depletion layer, and say what widens it.
  3. State the equation relating collector and base current in a BJT. Why does that relationship make a BJT a poor match for a 16 mA GPIO pin?
  4. What physically separates the gate of a MOSFET from its channel, and what does that make the gate look like electrically?
  5. Explain how raising VGS creates a channel in an enhancement-mode device. Why is the result called an inversion layer?
  6. Which mode is normally on, depletion or enhancement? Which do you want for a motor switch, and what is the safety argument?
  7. Give three differences between a BJT and a FET, and state which device each difference favors.
  8. A switch should operate in which region, ohmic or saturation? What would going into the other region cost you?
  9. In a CMOS inverter, why is the static power nearly zero, and what does the gate burn power on instead?
  10. Give three independent reasons a GPIO pin cannot drive a DC motor directly. Which one is quantitative, and what number would you cite?
  11. A motor winding measures 2.5 Ω on a 5 V supply. Compute the stall current and compare it with the 16 mA pin rating.
  12. What does the “L” in IRL510 signify, and why does it matter for a 3.3 V controller?
  13. Draw the flyback diode across a motor and state its orientation relative to the supply. What happens if it is reversed?
  14. Explain why the MOSFET goes between the motor and ground rather than between the supply and the motor.
  15. Why must the Pi's ground and the bench supply's ground be connected? Answer in terms of VGS.
  16. What two roles do the gate series resistor and the gate pull-down resistor play?
  17. Define the dead zone in the RPM-vs-duty curve and explain its physical origin.
  18. Your tachometer gives 180 pulses in 6.0 s from a three-slot disc. Find the RPM.
  19. Why might the motor keep running at a lower duty cycle than the one needed to start it?
Lab takeaway

When a load needs more current than a pin can supply, the pin commands and a transistor does the work. Give the load its own supply, tie the grounds together, put a flyback diode across anything inductive, and switch fully on or fully off so the transistor stays cool. Then measure what you actually built: characterize the PWM before you trust it, and calibrate the tachometer before you believe an RPM.

17 Practical Engineering Connections

  1. Doping is the whole industry. Nearly every chip, sensor and solar cell you will use begins with deliberately contaminated silicon. The photodiode of Lab 1, the MOSFET of Lab 4 and the ADC of Lab 8 are three arrangements of the same two materials.
  2. Bipolar is not obsolete. BJTs still win where a low, predictable saturation voltage or good analogue matching matters: precision current mirrors, bandgap references and many audio output stages.
  3. CMOS. Every processor, memory and FPGA is the inverter of Figure 18 repeated billions of times. The C V² f term in Equation (4) is why clock speed, supply voltage and battery life are one design conversation.
  4. Gate charge and switching loss. At megahertz switching rates, charging the gate capacitance stops being free and becomes a real power term. It is why switching supplies use dedicated gate-driver chips rather than a logic pin.
  5. Electrostatic discharge. The fragile oxide of §4.2 is why boards ship in conductive bags, why assembly benches are grounded, and why most chip input pins carry small protection diodes.
  6. Low-side switching. The workhorse arrangement for solenoids, relays, valves, heaters, fans and lamps in cars, appliances and industrial controllers.
  7. PWM power control. Electric-vehicle traction drives, cordless tool controllers, variable-speed fans, induction cooktops and switching power supplies all control power exactly this way, and for the efficiency reason in Equation (5).
  8. Flyback protection. Almost every relay and solenoid driver includes this diode. It is also the operating principle of the boost converter, which harvests the inductive spike instead of clamping it.
  9. Logic-level gate drive. The 3.3 V-versus-10 V gate question appears whenever a modern microcontroller drives legacy power hardware, and is the reason gate-driver ICs exist.
  10. Back-EMF. Sensorless motor controllers measure back-EMF to infer rotor position, and regenerative braking recovers it as useful energy.
  11. Optical tachometry. Optical encoders on printer carriages, robot joints, CNC axes and computer mice all count interruptions of a light beam, exactly as your Task 4 detector does.
  12. Characterizing before trusting. Task 1's range-of-validity exercise is what an engineer does with any new subsystem: find the region where it behaves, and document the edges, before designing anything on top of it.
  13. Isolation. Where the power side is dangerous or noisy, the signal and power paths are separated further still, by optocouplers or transformers. Your common-ground circuit is the simplest member of that family.

← All course materials