MCU Pin & Protocol Calculator
The 4.7k I2C pull-up is outside spec at 400 kHz, 16 MHz cannot hit 115200 baud, and PWM frequency trades directly against resolution.
PWM: what each frequency allows
Which clock hits your baud rate
I²C pull-up ceiling against bus capacitance
The 4.7 kΩ I²C pull-up is outside the window at 400 kHz
Rise time is 0.8473·R·C, and fast mode allows 300 ns. So a 100 pF bus needs a pull-up below 3.54 kΩ, while the 3 mA sink limit at 3.3 V puts the floor at 0.97 kΩ. The window is 0.97k–3.54k and the universally quoted default sits above it. It works fine at 100 kHz — where the ceiling is 11.8 kΩ — which is exactly why the folklore survives.
PWM frequency and resolution trade against each other, hard. The counter has to tick 2bits times per period, so f × 2bits ≤ fclock. On an ESP32's 80 MHz LEDC, 16-bit PWM tops out at 1,221 Hz, and 20 kHz — the usual motor choice, to put the whine above hearing — allows only 11 bits. Asking for 20 kHz at 16-bit needs a 1.31 GHz clock; the API accepts it and quietly gives you something else.
UART baud rates aren't exact, because the divisor is an integer. A 16 MHz AVR can't produce 115200: the nearest divisor gives −3.55%, and even double-speed mode only reaches +2.12% — both outside the roughly ±2% an 8N1 frame tolerates. That is why 14.7456 and 11.0592 MHz crystals exist: they divide exactly into every standard baud rate, which a round 16 MHz cannot. Those odd values aren't arbitrary; they're the frequencies that make the arithmetic come out whole.
And PWM pins aren't independent — they share timers. An Uno has six PWM pins on three
timers, so pins on the same timer can't have different frequencies. Worse, Timer0 also drives
millis(), delay() and micros(), so changing the
frequency on pins 5 or 6 breaks timekeeping. That leaves two genuinely usable
independent frequencies on a board that appears to offer six.
- Bus capacitance is the term nobody measures and everybody exceeds. Every device adds a few pF, every centimetre of track more, and a metre of ribbon cable can add a hundred alone. A bus that works on the bench and fails in the enclosure has usually just gained the capacitance of its wiring.
- A too-weak pull-up presents as intermittent corruption, not a dead bus. The edges are too slow, so the receiver samples a level that hasn't arrived — which is far harder to diagnose than nothing working at all.
- The RP2040's PWM slices have the same trap in a larger disguise: sixteen outputs, but the two channels of each slice share a frequency.
- Check the peripheral clock, not the CPU clock. The ESP32 runs at 240 MHz but its LEDC PWM peripheral is fed 80 MHz, and that's the number the resolution limit uses.
How to use
- Check frequency times resolution against the peripheral clock, not the CPU clock.
- Size I2C pull-ups from the bus capacitance, not from a default.
- Check the baud error before choosing a crystal.
- Check which timer a PWM pin uses before changing its frequency.
Frequently asked questions
What value should an I2C pull-up resistor be?
It depends on the bus capacitance and the speed, and the usual 4.7k answer is often wrong. Rise time is 0.8473 times R times C, and fast mode at 400 kHz allows 300 nanoseconds — so a 100 pF bus needs a resistor under 3.54k. The floor is set by the 3 mA sink limit, about 970 ohms at 3.3 volts. The window is roughly 1k to 3.5k, and 4.7k sits above it.
Why does 4.7k work for some people and not others?
Because it is fine at 100 kHz and marginal at 400. Standard mode allows a full microsecond of rise time, which puts the ceiling near 11.8k on a typical bus — so the default has enormous margin there. Move to fast mode and the ceiling drops to 3.54k, and the same resistor that worked for years starts producing intermittent corruption.
Why does my I2C bus stop working when I add devices?
Bus capacitance. Every device adds a few picofarads and every centimetre of track or cable adds more, and the maximum pull-up resistance scales inversely with it. A bus that worked at 100 pF has half the allowed resistance at 200, so a pull-up that was inside the window falls outside it without anything else changing. A metre of ribbon cable can add a hundred picofarads on its own.
Why can I not get 16-bit PWM at 20 kHz?
Because the counter has to tick 65,536 times per period, and 20,000 times 65,536 is 1.31 gigahertz. The peripheral clock sets a hard limit: frequency times two to the resolution cannot exceed it. On an ESP32 80 MHz LEDC, 20 kHz allows 11 bits and 16-bit allows 1,221 Hz. The API accepts the impossible request and quietly gives you something else.
What is the highest PWM resolution I can use?
The base-two logarithm of the peripheral clock divided by your frequency, capped by the counter width. Each doubling of frequency costs exactly one bit. That is why motor PWM at 20 kHz, chosen to put the whine above hearing, ends up with a couple of thousand steps rather than sixty-odd thousand — which is still far more resolution than a motor can use.
Why do some microcontrollers use odd crystal frequencies like 14.7456 MHz?
Because they divide exactly into every standard baud rate, and a round number does not. UART divisors are integers, so the achievable baud rate is the clock divided by a whole number. A 16 MHz clock misses 115200 by 3.55 per cent, or 2.12 in double-speed mode, both marginal against the roughly two per cent an 8N1 frame tolerates. 14.7456 and 11.0592 MHz hit every rate at zero error.
How much baud rate error can a UART tolerate?
About two per cent for a standard 8N1 frame, though the exact figure depends on both ends. The receiver samples in the middle of each bit, and error accumulates across the ten bits of a frame — so by the stop bit a two per cent mismatch has drifted a fifth of a bit. Two devices that are each two per cent off in opposite directions will not talk to each other at all.
Why does changing PWM frequency break delay() on an Arduino?
Because Timer0 drives both the PWM on pins 5 and 6 and the millis, delay and micros functions. Changing the timer prescaler to alter the PWM frequency changes the tick rate those functions count, so delay(1000) no longer waits a second. Pins 9, 10, 3 and 11 are on other timers and can be changed freely.
Can two PWM pins have different frequencies?
Only if they are on different timers. An Uno has six PWM pins on three timers, in pairs, so the two pins sharing a timer are locked to the same frequency — they can have different duty cycles but not different periods. The RP2040 has the same trap in a larger disguise: sixteen PWM outputs, but the two channels of each slice share a frequency.
Are microcontroller pins interchangeable?
Rarely, and the exceptions are what make the ESP32 unusual. On most parts each peripheral is hard-wired to a small set of pins through an alternate-function multiplexer, so finding a pin assignment where every peripheral you need has a free pin is a genuine design step rather than an afterthought. The remap options are a table in the reference manual.
What clock does the PWM peripheral actually use?
Often not the CPU clock, which is the trap. An ESP32 runs its core at 240 MHz but feeds the LEDC PWM peripheral 80, and that is the number the resolution limit uses. Working from the headline clock speed overestimates the available resolution threefold. The same applies to timers behind prescalers and to parts with separate peripheral clock domains.
What happens if an I2C pull-up is too weak?
The rising edges are too slow, so the receiver samples a level that has not finished arriving. That produces intermittent corruption rather than a dead bus, which is considerably harder to diagnose — the bus mostly works, then fails under load or when a longer cable is fitted. Too strong a pull-up fails the other way, exceeding the sink current so the low level never reaches a valid zero.
🔒 This tool runs entirely in your browser. Nothing you enter is uploaded, logged, or stored.