Embedded Hardware Design

A wearable must run 7 days on a coin cell that holds about 225 mAh. That allows 1.34 mA on average. Left always on, the toy design draws 5 mA and dies in under 2 days. Measured in short bursts over Bluetooth LE, it lasts 28 days.

Pick a design, then drag how often it measures. Watch the battery line cross, or miss, the 7-day line. Then we build, piece by piece, the block diagram, the chip, the sensor path, the power rails, the radio, the copper and the first power-on.

You need Ohm's law and a little Python. Lesson 1 helps. We build the rest from zero.

Lesson 3 of the Embedded Systems series. Before: Lesson 2, Embedded C. Next: Lesson 4, Hardware Interfacing. The hands-on track is Firmware from Zero.

Make the coin cell last 7 days

30 s

Illustrative toy. The 225 mAh is Panasonic's CR2032 rating. The currents are round numbers we made up. A 2 s measurement draws 5 mA, a 5 ms BLE packet 8 mA, sleep 3 µA, and a 2 s Wi-Fi join 100 mA. Self-discharge and pulse limits are left out here (Chapter 5 adds the pulse limit).

Chapter 0

Requirements Become One Number

Turn "7 days on a coin cell" into an average current, then spend it mode by mode

You must build a wearable heart-rate monitor. It must measure the pulse and send it to a phone over Bluetooth LE. It must run 7 days on one CR2032 coin cell, on a board 25 mm square. Where do you start?

Start with the requirement that leaves the least room. Here it is the battery. A requirement is only useful when it is a number you can check. "Long battery life" is a wish. "7 days on 225 mAh" is a current you can measure with a meter.

A battery's capacity is the charge it holds, in milliamp-hours (mAh): 225 mAh supplies 1 mA for 225 hours. The device spends that charge in modes: asleep, measuring, sending. Each mode draws its own current for its own share of the time. That share is the mode's duty.

Call the capacity C. Call the duty of mode i di and its current Ii. The battery life L is:

Say it aloud

L equals C divided by the sum over i of d-i times I-i.

L
L the battery life, in hours. Divide by 24 for days.
C
C the battery capacity, in mAh. 225 mAh for this CR2032.
Σi
the sum over i add one term for each mode: sleep, measure, send.
di
d-i the duty of mode i: the fraction of each cycle spent in it, from 0 to 1. All duties add to 1.
Ii
I-i the current the board draws in mode i, in mA.
In plain words

For each mode, multiply its duty d-i by its current I-i. Add the products: that sum is the average current. Divide the capacity C by it. The result L is how many hours the battery lasts.

With numbers

With made-up currents: measure 2 s of every 30 s at 5 mA, send 5 ms at 8 mA, sleep the rest at 3 µA. The sum is 0.0667 × 5 + 0.000167 × 8 + 0.933 × 0.003 = 0.337 mA. L = 225 / 0.337 = 667 h, or 27.8 days. The 7-day requirement allows 225 / 168 = 1.34 mA, so this design has room.

Spend one cycle's charge

The bar is the charge one 30 s cycle uses, split by mode. The yellow line is what 7 days allows per cycle. Stretch the measurement, then leave a sensor powered in sleep.

2.0 s

Illustrative currents, as in the hero. A millicoulomb (mC) is 1 mA for 1 s. The budget per cycle is 1.34 mA × 30 s = 40.2 mC.

The device shows the lesson of the whole chapter. Measuring takes 10 of the 10.1 mC per cycle. The radio packet is a sliver. Sleep current is a sliver too, until a forgotten sensor raises it a hundredfold.

Symptom: the board lasts 15 days instead of 28, with the same firmware.

Measure: put a current meter in series with the cell and read the sleep floor. 300 µA where you expected 3 µA names a part that never sleeps.

Fix: switch the sensor's supply off with a load switch, or put it in its own shutdown mode before the MCU sleeps.

The road

  1. Wires: the block diagram, and pull-ups sized for the bus speed.
  2. The MCU: pick it with weights, then check the memory fits.
  3. Sensors: gain, a filter and the ADC's step.
  4. Power: LDO or buck, dropout and heat.
  5. Radio: charge per report. The hero's Wi-Fi and BLE numbers come from here.
  6. Copper: trace width and decoupling.
  7. Showcase: place the parts on a 25 mm board and pass the rule check.
  8. Buy or build: a module or a bare chip, by volume.
  9. Bring-up: power on a new board one layer at a time.
  10. Field guide: the numbers, the bug table and the code.
A design measures for 2 s of every 30 s at 5 mA and sleeps at 3 µA. Which change helps battery life most?

Chapter 1

Wire the Block Diagram

Choose a bus for each part, count the pins, and size the I²C pull-ups for the speed you want

A block diagram is the first drawing of the board: one box per chip, one line per connection. Each line is a bus. Lesson 1 taught what each bus sends; here we count what each costs.

BusSignal wiresGood forHardware it needs
I²C2, shared by addressslow sensors, small EEPROMstwo pull-up resistors
SPI3 + one select per devicedisplays, flash, fast ADCsa select pin per device
UART2, one partnerGPS modules, a debug consoleboth ends at one baud rate
PDMclock + datadigital MEMS microphonesa filter in the MCU

Count pins before you pick the chip. Eight sensors on SPI need 3 + 8 = 11 pins; on I²C they need 2. But I²C has a hidden part. Its lines are open-drain: a chip can pull a line low, and nothing drives it high. A pull-up resistor to the supply raises the line when every chip lets go.

Every pin and trace adds capacitance to the line. When the chips let go, the pull-up charges it, and the voltage rises along a curve. Call the pull-up resistance Rp and the bus capacitance Cb. The rise time tr, from 30% to 70% of the supply, is:

Say it aloud

t-r equals 0.8473 times R-p times C-b.

tr
t-r the rise time: how long the line takes to go from 30% to 70% of the supply, in seconds.
0.8473
zero point eight four seven three the natural log of 0.7 / 0.3. An RC curve reaches 30% at 0.357 RC and 70% at 1.204 RC; the gap is 0.8473 RC.
Rp
R-p the pull-up resistance, in ohms.
Cb
C-b the bus capacitance: all pins plus the traces, in farads. The I²C spec allows up to 400 pF.
In plain words

Multiply the pull-up R-p by the bus capacitance C-b. That product is the RC time constant. Take 0.8473 of it: that is t-r. Keep t-r under the bus mode's limit.

With numbers

A common 4.7 kΩ pull-up on a 100 pF bus: t-r = 0.8473 × 4,700 × 100 × 10−12 = 398 ns. Standard mode (100 kHz) allows 1,000 ns, so it passes. Fast mode (400 kHz) allows 300 ns, so it fails. A 2.2 kΩ pull-up gives 186 ns and passes.

Size the pull-up for the bus speed

The blue curve is the line voltage after every chip lets go. Pick a bus mode, then change the resistor and the capacitance. Too slow a rise fails the mode; too small a resistor fails the pin.

4.7 kΩ
100 pF

Limits from NXP's UM10204 I²C specification: rise time 1,000 ns (standard mode) and 300 ns (fast mode), 400 pF maximum, and a pin that must pull to 0.4 V while sinking 3 mA. The 3.3 V supply is illustrative.

The pull-up has a floor too. A low pin must sink the pull-up's current and still read low: 0.4 V at 3 mA. So Rp must be at least (3.3 − 0.4) / 0.003 = 967 Ω on a 3.3 V bus. Between that floor and the rise-time ceiling, pick a standard value.

Symptom: the sensor answers at 100 kHz and returns errors at 400 kHz.

Measure: scope the SDA line. Rounded rising edges that cross 70% late name a slow pull-up.

Fix: lower Rp (4.7 kΩ to 2.2 kΩ on 100 pF), or shorten the bus. Buses on the Wire reads these waveforms in depth.

A 100 pF I²C bus has 4.7 kΩ pull-ups. You change it from 100 kHz to 400 kHz. What happens?

Chapter 2

Pick the Brain by Weights, Then Check It Fits

Score each candidate against weighted requirements, then add up the flash and RAM it must hold

Spec sheets tempt you to pick the fastest chip. But speed is one of several requirements, and each requirement matters by a different amount. A decision matrix makes that explicit. Give each requirement a weight from 0 to 5. Score each chip from 1 to 5 on it. Multiply each score by its weight and add the products.

Weight the requirements, rank the chips

Each bar is one chip's weighted total. Move the weights, or load a preset, and watch the ranking change.

5
5
2
3

The 1 to 5 scores are illustrative judgements, not measurements. The facts behind them are the vendors'. Nordic nRF52840: Cortex-M4F, 64 MHz, 1 MB flash, 256 KB RAM, Bluetooth LE. Espressif ESP32-S3: two Xtensa LX7 cores at 240 MHz, Wi-Fi and Bluetooth LE. ST STM32L4R5: Cortex-M4 at 120 MHz, no radio. Raspberry Pi RP2040: two Cortex-M0+ cores, no radio, no FPU.

For the wearable, with weights 5, 5, 2 and 3, the nRF52840 scores 60 of 75 and wins. Its radio is on the chip, so the board needs no second radio chip. Load the camera preset and the ESP32-S3 wins with 56: it has Wi-Fi and the most compute. The matrix does not decide for you. It shows which weights decide.

Then check that the firmware fits. Flash holds the code and keeps it without power. RAM holds the variables, the stack and the buffers, and loses them at power-off. List every user of each and add them up.

RAM user (illustrative)BytesWhy that size
Pulse samples1,6004 s at 100 Hz = 400 samples × 4 bytes
Stack8,192main plus interrupt frames, with margin
A 320 × 240 colour frame153,600320 × 240 pixels × 2 bytes: 59% of 256 KB

The pulse buffer is nothing. One frame for a small screen takes more than half of the nRF52840's RAM. Data too big for RAM goes in external flash on a QSPI bus. Its 4 data lines at 80 MHz move at most 80 × 4 = 320 Mbit/s, or 40 MB/s.

Symptom: the board resets when the display code runs for the first time.

Measure: read the linker map: data plus zeroed data plus the stack, against the RAM size.

Fix: draw the screen in strips instead of a whole frame, or pick a chip with more RAM. The map file step shows how to read it.

Your MCU has 256 KB of RAM. How much does one 320 × 240 frame at 2 bytes per pixel take?

Chapter 3

Condition the Signal Before the ADC

Amplify the sensor to fill the ADC's range, filter out mains hum, and shift any 5 V signal down

An analog sensor sends a voltage, not a number. Before the ADC reads it, signal conditioning cleans it up: gain, a filter and a level shift.

Take a sensor that gives 10 mV per °C: 0 to 1 V from 0 to 100 °C. The 12-bit ADC spans 0 to 3.3 V, so the sensor uses less than a third of its steps.

How small a temperature change can you see? Call the ADC reference Vref and its bit count N. Call the amplifier gain G and the sensor's sensitivity s. One ADC step, in degrees, is ΔT:

Say it aloud

Delta T equals V-ref divided by 2 to the N, times G, times s.

ΔT
delta T the temperature change one ADC step stands for, in °C.
Vref
V-ref the ADC's reference voltage: its full scale. 3.3 V here.
2N
2 to the N the number of ADC steps. N = 12 bits gives 4,096.
G
G the amplifier gain: output volts per input volt.
s
s the sensor sensitivity: 0.010 V per °C.
In plain words

Divide V-ref by 2 to the N to get one step in volts at the ADC. Divide by the gain G to get volts at the sensor. Divide by s to turn those volts into degrees.

With numbers

With G = 1: 3.3 / (4,096 × 1 × 0.010) = 0.081 °C per step. With G = 3.3, 100 °C gives 3.3 V, the top of the range: 0.024 °C per step, more than 3 times finer. With G = 4 the ADC tops out at 82.5 °C and clips above it.

Wires near mains pick up hum at 50 or 60 Hz, far faster than a temperature changes. A low-pass filter removes it: a resistor R in series, then a capacitor C to ground. Its cutoff fc is where it starts to weaken a signal:

Say it aloud

f-c equals one divided by two pi R C.

fc
f-c the cutoff frequency, in hertz. There the filter passes 70.7% of the amplitude.
2π
two pi turns hertz into radians per second.
R
R the series resistor, in ohms.
C
C the capacitor to ground, in farads.
In plain words

Multiply R by C and by two pi. Take one over the product: that is f-c. Above f-c, each tenfold rise in frequency cuts the amplitude tenfold.

With numbers

For f-c = 10 Hz with R = 10 kΩ: C = 1 / (2π × 10 × 10,000) = 1.59 µF, so use 1.5 µF. At 50 Hz the filter passes 1 / √(1 + 5²) = 0.196 of the hum, a cut of 14.1 dB.

Fill the ADC, remove the hum

Pink is the true temperature, faint is the raw sensor with hum, blue is what the ADC sees. Raise the gain to fill the window, then lower the cutoff.

1.0
500 Hz

Illustrative signal: 20 to 95 °C in one second so it fits the screen, plus 50 mV of 50 Hz hum and some noise. The filter is the RC filter above.

Last comes the level shift: a 5 V output can damage a 3.3 V pin. A divider of 10 kΩ over 20 kΩ gives 5 × 20 / 30 = 3.33 V.

Symptom: readings stop rising above about 82 °C.

Measure: log the raw ADC codes. A flat run at 4,095 is clipping.

Fix: lower the gain so the hottest temperature you must read lands just under Vref.

A 10 mV/°C sensor feeds a 12-bit, 3.3 V ADC with no gain. What is one step in degrees?

Chapter 4

Regulators Turn Extra Volts into Heat, or Not

Compare a linear regulator with a buck converter, find the dropout, and check the chip's temperature

The chips want a steady 3.3 V, but the input is USB at 5 V or a lithium cell that falls from 4.2 V to about 3.0 V. A regulator makes the steady rail.

A linear regulator, or LDO (low-dropout regulator), is a valve. The same current flows in and out, and the extra voltage turns into heat. Its efficiency is about Vout / Vin. It is small, cheap and quiet. Its dropout is the least headroom it needs: with 0.2 V of dropout, a 3.3 V LDO needs at least 3.5 V in.

A buck converter switches the input on and off at high speed and smooths the result with an inductor. Little power turns into heat: 85 to 95% efficiency is common at moderate loads. It needs more parts and adds switching noise.

How hot does an LDO get? Call the input voltage Vin, the output Vout and the load current I. The part loses (Vin − Vout) × I as heat. Call the room temperature TA and the package's thermal resistance, the degrees it heats per watt, θJA. The silicon reaches TJ:

Say it aloud

T-J equals T-A plus theta-J-A times, V-in minus V-out, times I.

TJ
T-J the junction temperature: how hot the silicon is, in °C. Many regulators allow 125 °C.
TA
T-A the ambient temperature around the part, in °C.
θJA
theta-J-A the thermal resistance from junction to air, in °C per watt, from the datasheet.
Vin
V-in the input voltage, in volts.
Vout
V-out the regulated output voltage, in volts.
I
I the load current, in amps.
In plain words

Subtract V-out from V-in and multiply by I: that is the heat in watts. Multiply the heat by theta-J-A to get the temperature rise. Add the room temperature T-A. The sum T-J must stay under the part's limit.

With numbers

With an illustrative small package at 180 °C/W: 5 V to 3.3 V at 300 mA loses 1.7 × 0.3 = 0.51 W. At 40 °C inside a case, T-J = 40 + 180 × 0.51 = 132 °C, over a 125 °C limit. A buck at 90% loses 0.11 W for the same load.

Feed the 3.3 V rail, read the heat

Input power splits into power for the load (blue) and heat (pink); the thermometer is the silicon. Raise the load, then lower the input toward a dying cell.

5.0 V
300 mA

Illustrative parts at 40 °C ambient: an LDO with 0.2 V dropout in a small package at 180 °C/W, and a buck at a flat 90% efficiency. Real dropout grows with current, real buck efficiency falls at light load, and real θJA depends on the board's copper.

From a lithium cell at 3.7 V, an LDO is 3.3 / 3.7 = 89% efficient, close to a buck. In sleep, the regulator's own quiescent current matters more: 50 µA of it takes the 28-day wearable down to 24 days.

Symptom: the board resets after a minute of radio use on USB, but never on the bench supply at 3.6 V.

Measure: point a thermal camera at the regulator, and scope the rail as it resets.

Fix: the LDO hits thermal shutdown. Lower Vin, add copper under it, or use a buck.

An LDO makes 3.3 V from 5 V at 200 mA. How much heat does it make?

Chapter 5

The Radio Spends the Battery by the Report

Compare Wi-Fi, Bluetooth LE and LoRa by the charge each report costs, and by the peak current the cell must give

Compare radios by what one report costs, not by their data rate. A sensor that sends 20 bytes does not care about 100 Mbit/s. It cares how long the radio stays awake, and how hard it pulls while awake. Charge per report is current times time: 1 mA for 1 s is 1 mC.

Price one report in charge

Pick a radio and how often it reports. The top row is the peak current against what a coin cell can supply. The bottom row is battery life on a log scale, with the 7-day line.

1 min

Illustrative radio currents and times; real ones depend on the chip, the output power and, for LoRa, the spreading factor. Sleep is 3 µA and no sensor runs. The 10 mA pulse line is an illustrative coin-cell pulse rating; check your cell's datasheet.

Reporting once a minute, BLE averages 0.024 / 60 + 0.003 = 0.0034 mA, and 225 mAh lasts about 7.6 years on paper. The cell's own shelf life ends it first. LoRa lasts 135 days. Wi-Fi averages 3.4 mA and lasts under 3 days.

There is a second limit. Makers rate a coin cell's capacity at a tiny load: Energizer rates 235 mAh into 15 kΩ, about 0.2 mA. Its internal resistance makes the voltage sag under large pulses. A 100 mA Wi-Fi burst pulls a CR2032 so low that the chip browns out. A big capacitor across the cell helps with short BLE pulses; nothing helps a 2 s Wi-Fi join. The Coin-Cell Year works through the sag.

Symptom: the board resets every time the radio sends, on a coin cell only.

Measure: scope the cell voltage during a send. A dip below the brown-out level names the cause.

Fix: add bulk capacitance for short pulses, or change the radio or the battery for long ones.

A soil sensor on a farm reports once an hour to a gateway 2 km away. There is no Wi-Fi. Which radio fits?

Chapter 6

Copper Has Limits

Choose the layer stack, size a trace for its current, and put a capacitor next to every supply pin

A PCB (printed circuit board) is layers of copper on fibreglass, and the stack-up is their order. A radio board usually takes 4: signal, ground, power, signal. The solid ground layer gives every fast signal a short return path, and the antenna design relies on it.

A trace is a resistor, so current heats it. How wide must it be? Call the current I, the allowed temperature rise ΔT and the trace's cross-section area A. IPC-2221 gives a curve fit:

Say it aloud

I equals k times delta T to the 0.44, times A to the 0.725.

I
I the current the trace carries, in amps.
k
k a constant: 0.048 for outer layers, 0.024 for inner layers, which shed heat less well.
ΔT0.44
delta T to the 0.44 the allowed rise above ambient, in °C, raised to the power 0.44.
A0.725
A to the 0.725 the cross-section area in square mils (a mil is 0.001 inch), raised to 0.725. Area is width times thickness; 1 oz copper is 1.378 mil thick.
In plain words

Solve for the area: divide I by k and by delta T to the 0.44, then raise the result to the power 1 / 0.725. Divide the area A by the copper thickness to get the width.

With numbers

1 A on an outer layer, 10 °C rise: A = (1 / (0.048 × 100.44))1/0.725 = 16.3 square mils. With 1 oz copper the width is 16.3 / 1.378 = 11.8 mil, or 0.30 mm. On an inner layer it is 30.8 mil.

Size the trace for its current

Blue is the trace's cross-section, to scale; dashed is the fab's narrowest trace. Raise the current, then move to an inner layer.

1.0 A

IPC-2221 curve fit with 1 oz copper (1.378 mil). The 6 mil (0.15 mm) minimum is a typical fab rule, illustrative. IPC-2152 is the newer standard and often allows narrower traces.

The second rule is decoupling. A chip's current jumps each time its logic switches, faster than the regulator can answer. A capacitor next to the supply pin holds charge and covers the jump. Call the current step I, how long it lasts Δt and the capacitance C. The supply dips by ΔV:

Say it aloud

Delta V equals I times delta t, divided by C.

ΔV
delta V how far the supply pin's voltage dips, in volts.
I
I the extra current the chip pulls during the step, in amps.
Δt
delta t how long the step lasts before the regulator catches up, in seconds.
C
C the decoupling capacitance at the pin, in farads.
In plain words

Multiply the current I by its duration delta t: that is the charge the capacitor gives up. Divide by C. The result is how far its voltage falls.

With numbers

With made-up numbers: a 50 mA step for 10 ns from 100 nF dips 0.05 × 10 × 10−9 / 100 × 10−9 = 5 mV. From 10 nF the dip is 50 mV.

Distance matters as much as size. A trace has inductance L, which fights a change in current with a voltage L × (change in current / time). With an illustrative 10 nH of trace, 50 mA in 2 ns drops 0.25 V. So vendor power schemes put 100 nF at each supply pin, plus one bulk capacitor of a few microfarads.

Symptom: ADC readings jump whenever the radio or a fast bus is busy.

Measure: scope the supply pin with a short ground spring. Spikes of hundreds of millivolts name poor decoupling.

Fix: put 100 nF at each supply pin, with a via straight to the ground layer.

Why does an inner-layer trace need to be wider than an outer one for the same current?

Chapter 7

Lay Out the Board

Place the antenna, crystal, capacitors, regulator and connector on a 25 mm board until the rule check passes

Placement comes before routing, and it has an order. The antenna goes first, at an edge, because it needs clear space. The crystal goes next, close to the MCU. Then the decoupling capacitors, each at its supply pin. Then the regulator, near where power comes in. The connector sits on an edge so a cable can reach it.

Place the parts, pass the rule check

Drag each part. The MCU is fixed. The check runs as you move: green parts pass, red parts break a rule, and the read-out names the first broken rule.

Illustrative rules of thumb, not one vendor's. The antenna sits at an edge with a 3 mm keep-out. The crystal is within 5 mm of the MCU, each 100 nF capacitor within 2.5 mm of its pin, and the regulator within 6 mm of the connector. Parts keep 0.3 mm apart. Your radio's datasheet gives the real keep-out.

Each rule has a reason. Copper near the antenna detunes it and shortens the range. Long crystal traces pick up noise and add capacitance, so the oscillator can fail to start. A capacitor far from its pin sits behind the trace's inductance (Chapter 6). A long input path carries the full input current and its noise across the board.

Design rule (typical 4-layer fab)ValueWhy
Trace / space6 / 6 mil (0.15 mm)what the etching can hold
Via0.3 mm drill, 0.6 mm padannular ring (0.6 − 0.3) / 2 = 0.15 mm
Copper to board edge0.3 mmthe router that cuts the board out wanders
Antenna keep-outfrom the radio datasheetground and parts detune the antenna

A real tool runs the same check, called DRC (design rule check), over every trace and pad before the board goes to the fab. The toy checks six rules over six parts; the habit is the same.

Chapter 8

Buy the Module or Build the Circuit

Weigh a one-time cost against a per-unit saving, and find the volume where building pays

A COTS module (commercial off-the-shelf) is a small board you solder onto yours: a radio chip, its crystal, its antenna and its matching parts, already tested and often already certified. A bare chip costs less per unit. But the antenna design, the tuning and the radio certification are yours to pay for, once.

That once-only cost is NRE (non-recurring engineering). Call it E. Call the saving per unit of the bare chip over the module Δc. Building pays back at the break-even volume N*:

Say it aloud

N-star equals E divided by delta c.

N*
N-star the break-even volume: the unit count where both choices cost the same in total.
E
E the one-time engineering cost of building: RF design, tuning, certification, in dollars.
Δc
delta c how much less each unit costs with the bare chip than with the module, in dollars.
In plain words

Each unit you build saves delta c. Divide the one-time cost E by that saving. The answer N-star is how many units it takes to earn E back. Below N-star, buy; above it, build.

With numbers

With made-up prices: a module at $5.50, a bare chip and its parts at $4.50, so delta c = $1. With E = $30,000, N-star = 30,000 units. At 100,000 units, building saves $100,000 − $30,000 = $70,000.

Find the volume where building pays

The solid line is the total cost of buying modules; the dashed line is building. Both axes are log scales. Slide your volume across the yellow crossover.

10,000
$30,000
$1.00

Illustrative prices and engineering cost. Real certification costs vary by region, lab and product.

Money is not the only term. A first product with a module ships months sooner, because its radio already works. A rule that holds up well: buy anything with RF in it for the first build, and build the parts where your own power, size or cost limits beat a general module, such as the regulator.

Symptom: the board works on the bench but has half the expected range.

Measure: check the module's keep-out against your layout. Copper or a ground pour under the antenna area names it.

Fix: clear the keep-out on every layer, and put the module at the board edge as its datasheet shows.

Building saves $0.50 per unit and costs $40,000 once. At what volume does it break even?

Chapter 9

Bring Up One Layer at a Time

Check power, clock, debug, pins, console, buses and radio in order, so the first failure names the fault

The boards arrive. You plug one in, and nothing happens: no light, no console, no radio. Bring-up is the order of checks that turns "nothing works" into one named fault. Each check needs only the layers below it. So the first check that fails points at its own layer.

  1. Power: measure every rail with a meter before the MCU runs code.
  2. Clock: the MCU starts on its internal oscillator; scope the external crystal.
  3. Debug port: connect SWD. Can you halt the core and read its ID?
  4. Blink: toggle an LED. Power, clock and code all work.
  5. Console: print over UART. Now you have eyes.
  6. Buses: scan I²C for every address you expect.
  7. Radio: advertise, and look for the board on a phone.

Find the hidden fault

Each new board hides one fault. Run the checks in order and read what each one shows. Or jump straight to the full app and see how little it tells you.

Illustrative faults, one per board, each with the symptom it shows on real hardware.

One common clock fault is the wrong load capacitors. A crystal's datasheet gives its load capacitance CL: the capacitance it must see. The two capacitors C1 and C2 act in series, plus the stray capacitance of pins and traces:

CL = C1 C2 / (C1 + C2) + Cstray

With equal capacitors, each one is 2 × (CL − Cstray). For an illustrative 9 pF crystal and 3 pF of stray, that is 2 × (9 − 3) = 12 pF each. Check: 12 × 12 / 24 + 3 = 9 pF. ST's application note AN2867 covers oscillator design in depth.

Last comes the outside world. A finger can carry a static spark, and the IEC 61000-4-2 test at its top level fires 8 kV by contact. Its current peaks near 3.75 A per kV, so about 30 A for nanoseconds. A TVS diode at each connector pin clamps that before it reaches a chip.

Symptom: the board runs, the console prints, but the radio never advertises.

Measure: scope the 32 MHz crystal pins. No sine wave, or one that starts late, names the oscillator.

Fix: recompute the load capacitors from CL and the stray estimate. The Bench covers probing and root cause.

The console prints, but an I²C scan finds no devices. Which layer do you suspect?

Chapter 10

Field Guide

Keep the numbers, the bug table and the next steps in one place

Turn each requirement into a number, and start with the one that leaves least room. Wire the block diagram with pins and pull-ups counted. Pick the chip by weights, then check the memory. Fill the ADC and filter the hum. Choose the regulator by voltage drop and heat, and the radio by charge per report. Size the copper, decouple every pin, place the parts by rule, buy what is hard, and bring up the board one layer at a time.

QuantityRuleExample
Battery lifeL = C / Σ di Ii225 / 0.337 mA = 27.8 days
Current ceilingC / Lrequired225 / 168 h = 1.34 mA
I²C rise timetr = 0.8473 Rp Cb4.7 kΩ, 100 pF: 398 ns
Pull-up floor(VDD − 0.4) / 3 mA967 Ω at 3.3 V
ADC step in °CVref / (2N G s)0.081 °C, 0.024 at G = 3.3
RC cutoff1 / (2π R C)10 kΩ, 1.59 µF: 10 Hz
LDO junctionTA + θJA (Vin − Vout) I40 + 180 × 0.51 = 132 °C
Trace width(I / (k ΔT0.44))1/0.725 / t1 A outer: 11.8 mil
Decoupling dipΔV = I Δt / C50 mA, 10 ns, 100 nF: 5 mV
Break-evenN* = E / Δc$30,000 / $1 = 30,000
Crystal caps2 (CL − Cstray)9 pF crystal: 12 pF each
BugSymptomWhat names it
Part awake in sleephalf the battery lifesleep current on a series meter
Slow pull-upworks at 100 kHz, fails at 400 kHzrounded SDA edges on a scope
Too much gainreadings flat at the topraw codes stuck at 4,095
LDO too hotresets after a minute of loada hot regulator, rail dips
Cell sagresets on every sendcell voltage dip during TX
Far decouplingnoisy ADC when busyspikes on the supply pin
Antenna keep-out brokenhalf the rangecopper under the antenna
Wrong crystal capsradio never startsno sine on the crystal pins
python
import math

def battery_days(cap_mah, modes):
    """modes: list of (duty, current_mA); duties add to 1."""
    i_avg = sum(d * i for d, i in modes)
    return cap_mah / i_avg / 24

def i2c_rise_ns(r_ohm, c_pf):
    return math.log(0.7 / 0.3) * r_ohm * c_pf * 1e-3   # ohm * pF = ps

def ldo_tj(t_amb, theta_ja, v_in, v_out, i_a):
    return t_amb + theta_ja * (v_in - v_out) * i_a

def trace_width_mil(i_a, rise_c=10, oz=1, inner=False):
    k = 0.024 if inner else 0.048
    area = (i_a / (k * rise_c ** 0.44)) ** (1 / 0.725)   # square mils
    return area / (1.378 * oz)

def break_even(nre, saving_per_unit):
    return nre / saving_per_unit

We ran each function. With the wearable's three modes, battery_days gives 27.8. i2c_rise_ns(4700, 100) gives 398. ldo_tj(40, 180, 5, 3.3, 0.3) gives 131.8. trace_width_mil(1) gives 11.8, and break_even(30000, 1) gives 30000.

Where it sits. This lesson is the hardware under the code of Lessons 1 and 2. Lesson 4 goes deeper into each interface on the board. Past the first board come EMC testing, impedance-controlled traces for fast buses, and test fixtures for production.

Keep going

Read next

The habit. Turn every wish into a number you can measure, then find the part of the design that spends most of it. That part, not the most famous one, decides the board.
The wearable must last 7 days on 225 mAh. What is the most it may draw on average?

Now teach it: press Present or Teach and explain how "7 days on a coin cell" becomes 1.34 mA, and why the measurement, not the radio, sets the battery life. Then go back to the coin cell and predict the shortest measurement interval that still lasts 7 days before you drag.

Embedded Systems · Lesson 3: Embedded Hardware Design, from Requirements to PCB
Previous: Embedded C · Next: Hardware Interfacing · Back to Gleams