# Ohmforge Microcontroller Timing Calculator > UART baud error (UBRR, BRR), timer prescalers, PWM resolution, ADC LSB/ENOB and RC delays. Five firmware calculations with exact integer arithmetic: the UART divider (AVR UBRR normal and double speed, STM32 BRR with 16× or 8× oversampling, or any divider) with the real baud rate and error for your clock, a timer solver that finds prescaler and compare value for a target frequency or period on 8-, 16- or 32-bit timers, PWM frequency against resolution for fast and phase-correct PWM, ADC LSB size, ideal SNR and ENOB from SINAD, and RC reset or debounce times to a logic threshold. Part of usefulweb.site (https://usefulweb.site/). Part of [Ohmforge](https://ohmforge.usefulweb.site/) (ownerApp: ohmforge). Results are deterministic calculations from the inputs and the listed assumptions; the API returns exactly what the web page shows. ## Use it - Human interface: https://ohmforgemcutiming.usefulweb.site/ (interactive tool at https://ohmforgemcutiming.usefulweb.site/tool) - JSON API: POST https://ohmforgemcutiming.usefulweb.site/api/v1/calculate with a JSON object of inputs (schema: https://ohmforgemcutiming.usefulweb.site/api/v1/tool) - OpenAPI: https://ohmforgemcutiming.usefulweb.site/openapi.json - MCP (Streamable HTTP): https://ohmforgemcutiming.usefulweb.site/mcp - tool `ohmforge_mcu_timing` ## Inputs - mode (select): Calculation - clockMHz (number): Clock (peripheral or timer clock) - baud (number): Baud rate - uartMode (select): Baud-rate generator - oversampling (integer): Oversampling (generic) - Clock cycles per bit of a generic UART, e.g. 16 for a 16550. - fractionBits (integer): Fractional divider bits (generic) - 0 = integer divider; 4 = divider in 1/16 steps. - maxErrorPercent (number): Accepted baud error - ±2 % is the usual design limit when both ends have their own error. - target (number): Target frequency (timer, PWM) or period - Hz, or seconds when "Target is" is set to period. - targetKind (select): Target is - bits (select): Timer width - prescalers (select): Prescaler options - customPrescalers (text): My prescalers - For "My own list": whole numbers separated by commas. - pwmMode (select): PWM mode - adcBits (integer): ADC resolution - vref (number): Reference voltage - vin (number): Input voltage to convert (optional) - sinadDb (number): SINAD or SNR from the datasheet (optional) - r (text): Resistor R - Engineering notation: 10k, 4k7, 1M. - c (text): Capacitor C - 100n = 100 nF, 1u = 1 µF. - supply (number): Supply voltage - highThreshold (number): High input threshold - Voltage at which the input reads 1 (Schmitt trigger VT+, reset threshold). - lowThreshold (number): Low input threshold (optional) - Voltage at which the input reads 0 again (VT−). - targetTime (text): Delay you want (optional) - For example 20m = 20 ms: the capacitor for it is computed with your R. ## Method - UART: AVR UBRR = round(fOSC/(16·baud) − 1) (U2X = 1: /8), real baud = fOSC/(16·(UBRR + 1)); STM32 USARTDIV = round(fCK/baud) with 16× oversampling and round(2·fCK/baud) with 8× oversampling, where BRR keeps USARTDIV[15:4] and BRR[2:0] = USARTDIV[3:0] >> 1 (USARTDIV ≥ 16); generic divider D = round(f/(N·baud)·2^F)/2^F. Error = real/wanted − 1. - Timer: f = fCLK/(P·N) with prescaler P and N counts per period (compare/auto-reload value N − 1). For each prescaler N = round(fCLK/(P·f)) must fit the timer (1 … 2^bits). "Any 1 … 65536" searches every prescaler and keeps the 10 best by error, then by most counts (finest resolution). - PWM: fast (single-slope) PWM f = fCLK/(P·(TOP + 1)); phase-correct (dual-slope) PWM f = fCLK/(2·P·TOP). In both modes the compare value runs 0 … TOP, so the resolution is log2(TOP + 1) bits. - ADC: LSB = Vref/2^N (the convention of most datasheets: code = floor(Vin·2^N/Vref)), quantisation noise LSB/√12, ideal SNR = 6.02·N + 1.76 dB for a full-scale sine, ENOB = (SINAD − 1.76)/6.02. - RC: the capacitor charges through R from 0 V: t = −RC·ln(1 − Vth/V) to the high threshold; discharging from V: t = −RC·ln(Vth/V) to the low threshold; settling to 1 % takes RC·ln 100 ≈ 4.6 RC. ## Limits - Register names and formulas follow the cited families; other microcontrollers differ (extra prescaler stages, fractional dividers, clock trees). Check the reference manual of your exact part. The RC result assumes ideal parts and a high-impedance input; real thresholds vary with supply and temperature.