- Where Lab 4 Sits
- PWM Revisited: the Range of Validity
- Why a GPIO Pin Cannot Drive a Motor
- From Silicon to a Transistor
- The Field Effect
- FET Against BJT
- CMOS, and the Pin You Have Been Using
- The MOSFET as a Switch
- The Flyback Diode
- The Complete Motor-Drive Circuit
- Measuring Rotation Rate
- What the RPM-vs-Duty Curve Looks Like
- Measurement Technique
- Common Mistakes and Bench Safety
- Self-Check
- Practical Engineering Connections
1Where 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 be the command.
That separation is the central idea of this lab and of most real embedded hardware:
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 (§7 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 task | What you build | Concept & section |
|---|---|---|
| 1 | Generate a range of PWM signals on BCM 12; find the range over which the output is valid; capture scope screenshots | Software-PWM limits at extreme frequency and duty (§2) |
| 2 | Read the IRL510 datasheet, document the pinout, build the motor circuit on a +5 V supply — not the Pi | MOSFET as a switch; flyback diode; grounding (§3–6) |
| 3 | Move the gate drive from the bench supply to BCM 12 and vary the speed | Logic-level gate drive (§4.3) |
| 4 | Build a rotation-rate detector; tabulate duty vs RPM (≥ 10 points); plot; derive a formula; analyse accuracy | Optical tachometry, the RPM–duty relation (§7–8) |
2PWM Revisited: the Range of Validity
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 characterisation task, and the answer is a region on a two-dimensional map, not a single number.
2.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.
2.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:
| Region | What 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 (§8.3). |
| Useful mid-band | Frequency and duty both track the commands. This is the region you will use for the motor. |
| High frequency | The 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: 1% duty is 10 ms at 1 Hz and 10 µs at 1 kHz. Note the distinction — it is a good observation for the report. |
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.
(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?
3Why a GPIO Pin Cannot Drive a Motor
Three independent reasons, any one of which is sufficient.
3.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.
With no rotation there is no back-EMF (§3.3), so the only thing limiting the current is the winding's DC resistance — often 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.
3.2 Inductance
A motor winding is an inductor. Current through an inductor cannot change instantaneously, and interrupting it produces a voltage spike
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 — far outside anything a 3.3 V pin or a MOSFET can survive. §5 deals with this.
3.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:
This is genuinely 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.
4From 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.
4.1 Doping: making carriers on purpose
Silicon has four valence electrons and shares all four with its neighbours 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:
| Dopant | Valence electrons | What it leaves behind | Result |
|---|---|---|---|
| Phosphorus | five | one spare electron per atom | n-type: majority carriers are electrons |
| Boron | three | one missing bond per atom | p-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.
4.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 — the depletion layer — and a built-in potential barrier across it.
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.
4.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 lightly doped and physically thin, and a collector in between the two in doping level. 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.
4.4 What the BJT costs you
Equation (4) 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.
Suppose you wanted a BJT to carry 1 A to a motor, and the part offers β = 50 at that current. The base needs
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.
(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.
5The 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.
5.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.
| Type | Gate is | Modes available | Used for |
|---|---|---|---|
| JFET | a reverse-biased PN junction | depletion only | amplifiers, mixers, voltage-controlled resistors |
| MOSFET | metal over an insulating oxide | depletion or enhancement | switching, 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.
5.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 (§4.2) into the channel, narrowing the path until it pinches off entirely.
5.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.
5.4 Enhancement and depletion
The channel in Figure 1 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.
| VGS < 0 | VGS = 0 | VGS > 0 | |
|---|---|---|---|
| Depletion mode, n-channel | channel off | channel on | channel on |
| Enhancement mode, n-channel | — | channel off | channel on |
5.5 Ohmic and saturation regions
With the device on, its behaviour 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.
(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 1 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?
6FET 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.
| BJT | FET | |
|---|---|---|
| Controlled by | base current | gate voltage |
| Control terminal draws | current, continuously | nothing, once the switching edge is over |
| Input impedance | moderate | extremely high — an insulator |
| Carriers involved | electrons and holes | one kind only, hence unipolar |
| Fully on looks like | a residual VCE(sat) ≈ 0.2 V | a resistance RDS(on) |
| Conduction loss at 1 A | ≈ 0.2 W, fixed by that voltage | I²RDS(on), and RDS(on) keeps falling with each part generation |
| Driving it from logic | a base resistor, and current for the whole on-time | connect the pin through a gate resistor |
| Typically destroyed by | heat and overcurrent | static discharge and gate over-voltage |
6.1 Why the comparison settles Lab 4
Line them up against the numbers from §3. 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.
6.2 What you give up
The oxide that makes the gate free to hold is a few tens of atoms thick, and it is the part that fails. Static discharge from a fingertip can puncture it, and so can exceeding the datasheet's VGS(max), typically around ±20 V. 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 (§8.5), and check VGS(max) before connecting anything other than a logic output to it.
(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?
7CMOS, and the Pin You Have Been Using
This section is a short detour, and it pays for itself twice: 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.
7.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.
7.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.
Equation (5) 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.
7.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 processor die, drawn exactly as Figure 3. 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.
8The MOSFET as a Switch
8.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 no current at all — 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.
8.2 Why the power dissipation is small
In the on state the MOSFET dissipates
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 — which is the same efficiency argument that made PWM dimming attractive in Lab 3, now carrying real current.
A MOSFET with RDS(on) = 0.54 Ω carries 500 mA:
A small fraction of a watt — no heatsink needed. 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. Look up your IRL510's actual RDS(on) and repeat this calculation with your measured current.
8.3 “Logic-level” gates, and why the IRL510 was chosen
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.
8.4 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 Equation-level, not stylistic: 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, so VGS collapses and the transistor turns itself off — which is why high-side switching needs a dedicated gate driver.
8.5 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.
9The 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 (2) the inductor develops whatever voltage it takes to keep that current flowing — and with the switch open, that voltage appears across the MOSFET's drain and can far exceed its VDS rating.
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. This is worth being deliberate about: it is the one orientation error in this lab that produces smoke rather than a wrong reading.
If your scope can safely reach the drain node, look at it with and without the diode fitted. The difference — a large narrow spike at each switch-off, versus a clean clamped edge — makes an excellent figure for the report.
10The Complete Motor-Drive Circuit
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 — and 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.
- 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.
- Have an instructor or TA check the circuit before powering the motor — Task 2 requires this.
- Task 3. Disconnect the +5 V gate supply, connect BCM 12 to the gate resistor, and confirm the common ground. Now the signal path is under test, and only one thing has changed.
Changing one thing at a time is why Lab 4 is structured this way. Resist the temptation to build it all at once.
11Measuring Rotation Rate
Task 4 asks you to design a detection system, and hints at an LED and a photodiode. This is a genuinely satisfying moment in the course: the light detector you built in Lab 1 becomes the sensor for the motor you built this week.
11.1 The principle
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:
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 — often the quicker route, and it needs no code at all.
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.
11.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:
- 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.
- 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 — an excellent way to record a completely fictitious RPM. Shroud the detector, and check what it reads with the motor stopped.
- 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.
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.
12What 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.
12.1 Three regions
- 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 — do not skip it.
- Roughly linear region. Above D0, the average applied voltage is D Vsupply, and from Equation (3) 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) (8)
- Saturation. Approaching 100% duty the curve flattens as the motor reaches its no-load speed for that supply voltage.
Do not space them evenly from 0 to 100%. Put several points close together around the dead-zone edge, where the interesting behaviour 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 (8) to the linear region only, and say in your report which points you included and why. Quote k in RPM per percent duty, with units, and D0 as a percentage.
12.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 genuine physical effect rather than just filling in a table, and it is exactly the kind of observation that lifts a lab report. If you do not find it, say so — a null result honestly reported is still a result.
12.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. 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 (§2.2). Report which frequency you used and why.
(a) A motor reaches 3000 RPM at 100% duty and has a dead zone up to 18%. Estimate k in Equation (8) 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.
13Measurement Technique
| What you are measuring | How | Watch 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 waveform | Probe 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 current | DMM 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 resistance | DMM on ohms, motor disconnected from everything. | Brushed motors read differently at different shaft positions — take several readings and quote the range. |
| Rotation rate | Tachometer 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. |
14Common Mistakes and Bench Safety
14.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 will 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.
14.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 (§7.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.
14.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. Keep the interrupter flag light and well attached; a stiff card thrown off a shaft at speed is a genuine eye hazard. Wear eye protection while the motor runs, and switch off before adjusting anything mechanical.
14.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.
15Self-Check
- What does adding phosphorus to silicon produce, and what does adding boron produce? Name the majority carrier in each case.
- Describe a depletion layer, and say what widens it.
- 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?
- What physically separates the gate of a MOSFET from its channel, and what does that make the gate look like electrically?
- Explain how raising VGS creates a channel in an enhancement-mode device. Why is the result called an inversion layer?
- Which mode is normally on, depletion or enhancement? Which do you want for a motor switch, and what is the safety argument?
- Give three differences between a BJT and a FET, and state which device each difference favours.
- A switch should operate in which region, ohmic or saturation? What would going into the other region cost you?
- In a CMOS inverter, why is the static power nearly zero, and what does the gate burn power on instead?
- Give three independent reasons a GPIO pin cannot drive a DC motor directly. Which one is quantitative, and what number would you cite?
- A motor winding measures 2.5 Ω on a 5 V supply. Compute the stall current and compare it with the 16 mA pin rating.
- What does the “L” in IRL510 signify, and why does it matter for a 3.3 V controller?
- Draw the flyback diode across a motor and state its orientation relative to the supply. What happens if it is reversed?
- Explain why the MOSFET goes between the motor and ground rather than between the supply and the motor.
- Why must the Pi's ground and the bench supply's ground be connected? Answer in terms of VGS.
- What two roles do the gate series resistor and the gate pull-down resistor play?
- Define the dead zone in the RPM-vs-duty curve and explain its physical origin.
- Your tachometer gives 180 pulses in 6.0 s from a three-slot disc. Find the RPM.
- Why might the motor keep running at a lower duty cycle than the one needed to start it?
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: characterise the PWM before you trust it, and calibrate the tachometer before you believe an RPM.
16Practical Engineering Connections
- Doping is the whole industry. 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.
- 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.
- CMOS. Every processor, memory and FPGA is the inverter of Figure 3 repeated billions of times. The C V² f term in Equation (5) is why clock speed, supply voltage and battery life are one design conversation.
- 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.
- Electrostatic discharge. The fragile oxide of §6.2 is why boards ship in conductive bags, why assembly benches are grounded, and why every modern input pin carries protection diodes.
- Low-side switching. The workhorse arrangement for solenoids, relays, valves, heaters, fans and lamps in cars, appliances and industrial controllers.
- 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 (6).
- Flyback protection. Every relay and solenoid driver in existence includes this diode. It is also the operating principle of the boost converter, which harvests the inductive spike instead of clamping it.
- 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.
- Back-EMF. Sensorless motor controllers measure back-EMF to infer rotor position, and regenerative braking recovers it as useful energy.
- 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.
- Characterising 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.
- 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.
PHYS 351 · Lecture 04 Notes · © Ran Yang, Ph.D. · yangran.org/teaching/phys351/