ElecEng Handbook Electronic Engineer Reference
Home โ€บ MCU

Embedded / MCU

Timer, baud-rate, ADC, clock-tree and throughput calculators for firmware bring-up, plus condensed tables for common MCU families, clock sources, GPIO and power modes.

Opens the browser print dialog โ€” choose "Save as PDF".
Register dividers, BRR fields and prescalers are integer values โ€” rounding changes timing. Always confirm clock-source frequencies and allowed divider ranges in the reference manual for your exact MCU.

Timer PWM & Overflow

fPWM = Fclk / ((PSC+1) ยท (ARR+1)); PWM resolution = log2(ARR+1) bits. Add a compare value CCR to read the duty cycle.
Hz
cnt
cnt
cnt
PWM frequency
โ€”
Period T
โ€”
PWM resolution
โ€”
Duty (CCR/ARR)
โ€”
(PSC+1) and (ARR+1) are the actual counter values. Higher resolution means a longer period at the same clock.

UART Baud Rate & Error

BRR = round(Fclk / (baud ยท oversampling)); actual baud = Fclk / (oversampling ยท BRR). Errors under ~2 % are usually usable for 8N1.
Hz
bd
ร—
Recommended BRR
โ€”
Actual baud
โ€”
Baud error
โ€”
High oversampling (16ร—) gives finer BRR steps. If your clock cannot hit a clean divisor, pick a baud the exact part supports or add a direct/independent BRR mode.

ADC Resolution & Conversion

V = code ยท Vref / 2^N; LSB = Vref / 2^N. Enter a code to read voltage or a voltage to read the code.
bit
V
cnt
V
LSB step
โ€”
Full-scale code
โ€”
Voltage at code
โ€”
Code at voltage
โ€”
Real ADCs add gain/offset error and noise; the quantization LSB is only the ideal step. Check INL/DNL and Vref accuracy in the datasheet.

PLL System Clock

VCO = HSE / M ร— N; SYSCLK = VCO / P. M divides the source, N multiplies into the VCO, P scales it down to the core clock.
Hz
/
ร—
/
PLL VCO output
โ€”
System clock SYSCLK
โ€”
Keep the VCO inside the allowed range (often 100โ€“432 MHz) and M/N/P within the exact part's limits. The value is valid only if the FLASH wait-states and APB prescalers fit the resulting SYSCLK.

Independent Watchdog Timeout

T = prescaler ยท reload / LSI. The reload register is 0โ€“4095; the prescaler divides the low-speed clock before the counter.
Hz
/
cnt
Watchdog timeout
โ€”
Max timeout (reload 4095)
โ€”
Feed the dog before the count hits zero or the MCU resets. LSI accuracy is coarse (ยฑ10โ€“30 %), so leave margin: refresh at most a fraction of the computed timeout.

SPI Data Throughput

Max bytes/s = SCLK / bits-per-frame ยท frame-bytes. Transfer time for a block = 8 ยท bytes / SCLK (8-bit frames).
Hz
bit
B
Max bytes/second
โ€”
Block transfer time
โ€”
Real SPI rates are limited by the peripheral max, GPIO speed and PCB routing. This is the wire-level figure โ€” software/DMA overhead adds time on top.

I2C Bit-Rate & Frame Time

SCL = fclk รท (2ยทCCR) for the classic peripheral; bit time = 1/SCL. A frame = 1 start + 7 address + R/W + ack + N bytes (8+ack each).
Hz
Hz
B
Actual SCL frequency
โ€”
Error vs target
โ€”
Bit time
โ€”
Frame time (addr+data)
โ€”
This is the wire-level timing for a classic 7-bit controller. It excludes bus turnaround, repeated starts, multi-byte spanning and clock stretching by slow slaves; the I2C spec caps the divisor patterns per mode, so check the part's CCR bit layout.

Sleep Timer & Battery Life

Wake-up period = reload รท LSE; average current = Iยทduty% + I(sleep)ยท(1โˆ’duty%); battery life = mAh รท avg current.
Hz
mA
ยตA
%
mAh
Wake-up period
โ€”
Average current
โ€”
Battery life
โ€”
Battery life assumes the full average current flows to the end of life โ€” real cells self-discharge and lose capacity with temperature and cycles. Add derating and measure the sleep current; the LSE wake timer only stops power draw, not the regulator's own consumption.

๐Ÿ“Š MCU Diagrams

Simplified views of a minimal MCU system, timer PWM timing, the PLL clock tree and GPIO output stages.

MINIMAL MCU SYSTEM MCU VDD·GND·NRST·BOOT OSC_IN / OSC_OUT SWDIO / SWCLK 3V3 + 100nF NRST → R to VDD 8 MHz crystal SWD + reset + boot debug header

Minimal MCU system โ€” A working MCU needs a decoupled supply, a reset that is pulled high, a clock source (crystal or RC) and access to the debug port (SWD) plus a boot-mode pin.

PWM TIMING ยท period = (ARR+1) · (PSC+1)/Fclk PWM out (CCR) counter t0 CCR ARR duty = CCR/(ARR+1)

PWM counter & output โ€” The timer counts from 0 to ARR; the output goes high until the counter reaches CCR. Adjusting CCR changes only the duty, while ARR sets both the period and the resolution.

CLOCK TREE ยท HSE / M × N / P HSE osc PLL ÷M · N /P SYSCLK → peripherals 8 MHz

PLL clock tree โ€” The oscillator is divided by M, the PLL multiplies by N to a VCO, and the post-divider P scales it to SYSCLK, which feeds the AHB/APB domains and peripherals.

GPIO OUTPUT STAGES push-pull VDD 0V pin open-drain VDD pin pull-up

GPIO output stages โ€” Push-pull drives the pin high and low through two transistors; open-drain only pulls low and needs an external pull-up, which lets the line rise to whatever rail it is tied to.

I2C ADDRESS FRAME SDA SCL S 7-bit address (A6..A0) R/W Ack data / Ack... t0 START slave may stretch clock

I2C address frame โ€” SCL clocks SDA through a START condition then 7 address bits plus the read/write bit; the addressed slave stretches the clock if it needs more time and acks by pulling SDA low on the next clock.

POWER-MODE STATE MACHINE Running Sleep Stop mA–high µA–low µA any IRQ wakes EXTI / RTC wakes Standby nA; RAM lost wake-up pin / reset

Power-mode state machine โ€” The core advances Running โ†’ Sleep โ†’ Stop โ†’ Standby, trading wake latency against draw. Sleep wakes on any interrupt, Stop on EXTI/RTC, Standby only on reset or a wake-up pin โ€” and loses RAM contents.

INTERRUPT SERVICING main ISR IRQ asserted main loop ISR executes latency (cycles) + context save keep ISRs short; return to main-loop context after ISR ends

Interrupt servicing โ€” When an event asserts an IRQ, the core finishes the current instruction, saves context and jumps to the ISR after a fixed latency, then returns to the main loop. Keep ISRs short so lower-priority work still meets its deadline.

๐Ÿ“š MCU Reference Tables

Condensed specs for common MCU families, clock sources, GPIO electricals and power modes. Values are typical โ€” always refer to the part's datasheet.

Common MCU Families

PartCoreFlash/RAMMax clockPeripheralsNotes
STM32F103C8Cortex-M364K/20K72 MHz3×TIM, USART×3, SPI, I2C, ADCBlue Pill classic; USB, cheap
STM32G030Cortex-M0+32K/8K64 MHzTIM×6, USART×2, ADC, DACLow-cost HSI-only, 32-bit
ATmega328PAVR32K/2K20 MHz3×TIM, UART, SPI, I2C, ADCArduino Uno; 5 V native
PIC16F877A8-bit PIC14K/36820 MHz3×TIM, USART, MSSP, ADCLegacy but everywhere; 40-pin
MSP430G255316-bit RISC16K/0.5K16 MHzTIM, UART, SPI, I2C, ADCUltra-low power, analog
nRF52840Cortex-M4F1M/256K64 MHzBLE, USB, QSPI, NFC, ADCRadio + lots of RAM
ESP32Xtensa LX64M/520K240 MHzWi-Fi, BT, UART×3, SPI, ADCWireless SoC; external flash
RP2040Cortex-M0+ ×22M/264K133 MHzPIO, DMA, USB, ADC, I2C/SPIPico; programmable IO

Clock Sources

SourceTypical freqAccuracyNotes
HSI (internal RC)8 / 16 MHz±1–3 %Boots instantly; drift with temperature
HSE (external)4–25 MHz±20–100 ppmCrystal; the source for accurate timing / USB
LSI (internal)32 / 40 kHz±10–30 %Drives IWDG / low-power auto-wake; coarse
LSE (external 32k)32.768 kHz±20 ppmWatch crystal; keeps RTC accurate in sleep

GPIO Electricals (typical)

ParameterTypical valueNotes
Input high VIH0.6–0.7 × VDDAbove this reads as logic 1
Input low VIL0.3–0.4 × VDDBelow this reads as logic 0
Output push current4–20 mADo not drive LEDs/relays directly
Pull-up / pull-down20–50 kΩWeak; not for strong loads
Max toggle rate5–50 MHzNeeds matching output speed config
Absolute max V / VDDVDD ± 0.3–0.5 VOver-driving pins damages the IO

Low-Power Modes

ModeWake sourcesTypical drawNotes
SleepAny interruptμA–mACPU halts, clock keeps running
StopEXTI, RTC, wake-up pinµ–few µAPeripherals off, SRAM retained
StandbyReset, wake-up pin, RTCµA and belowEverything off; RAM lost