UART Baud Rate: How Accurate Does It Need to Be?

I really appreciate the convenience offered by microcontrollers that have a fairly-high-accuracy internal oscillator. But these oscillators are never as precise as a crystal, so there is always a lingering doubt—is the internal oscillator accurate enough for all the timing functionality that I might need?
One of the most common timing-sensitive tasks is UART communication. The interface lacks an external clock, and the Tx and Rx devices can reliably share data only when their internal baud rates are equal.

But of course “equal” is not really an engineering word—we always have to account for noise and error and variation, and in the case of a microcontroller’s internal oscillator, we’re not talking about a few parts per million. In my experience, microcontrollers rarely offer an internal oscillator that has accuracy better than ±1.5%. Two microcontrollers with ±1.5% clock sources will have baud rates that are different by as much as 3%. Is that good enough?

Baud Rate, Bit Period, and Sampling

(Note: For the remaining analysis we’ll use the Tx device as the reference; in other words, we’ll assume that the Tx device is always at the nominal baud rate and the Rx device is at the inaccurate baud rate.)
The first thing to keep in mind is that the only relevant error is the difference between the transmitter’s baud rate and the receiver’s baud rate (as opposed to the difference between an expected baud rate and an actual baud rate). For example, you will have no difficulty transferring data if your two communicating devices are both operating at 9800 baud, even if the expected rate (based on the nominal clock frequency) is 9600 baud.
The following diagram shows the basic timing procedure involved in UART reception. If the receiver baud rate perfectly matches the transmitter baud rate and the first bit is sampled at the exact middle of the bit period, the last data bit will also be sampled at the exact middle of the bit period.



If the baud rates (and thus the bit periods) are different, each sampling point will move gradually closer to the bit transition. In other words, the last data bit is the one that is most severely affected by baud rate discrepancy. Note: For convenience, we’ll always assume that the Rx bit period is longer than the Tx bit period; the result would be the same if we assumed a shorter Rx bit period.



Solving for Maximum Allowable Error: The Simpler Version

Based on this observation, we can first propose the following: the baud rates are sufficiently accurate if the last data bit is sampled before the transition from last data bit to stop bit. (We’re assuming here that the system can tolerate an improperly sampled stop bit.) But we don’t want to sample one nanosecond before the expected transition; we need some margin. I think a reasonable margin is 20%—i.e., the last bit must be sampled at least 20% of the bit period before the transition from last data bit to stop bit.



The bit period for the Tx device is defined as follows:

If we use E to refer to the absolute value of the percentage difference between the baud rate of the receiver and the baud rate of the transmitter, we have the following for the additional bit-period time on the Rx side:

For this first analysis, we’ll simplify by assuming that the timing procedure begins in the exact middle of the start bit. So for an eight-data-bit interface, the sampling time for the last data bit will be off by 8ΔTRX. Thus, our is-it-accurate-enough condition is the following:

because we said that the acceptable sampling window for the last data bit is from 50% (the ideal value) to 80% (as close to the transition as we are willing to go), and 80% – 50% = 30% = 0.3.
We can solve for maximum allowable E as follows:



So, based on this simplified analysis, eight-data-bit UART communication should be reliable as long as the difference between transmitter baud rate and receiver baud rate is less than 3.75%.

Maximum Allowable Error: The Complete Analysis

The previous section gives you a rule of thumb for any eight-data-bit UART system that can tolerate frame errors (i.e., errors indicating an improperly sampled stop bit). In this section, we’ll develop a comprehensive equation that can provide a more precise and customized estimate.
To do this, we will incorporate the following:
  • variable location of start-bit sampling
  • variable number of data bits
  • variable margin for sampling the final bit
  • presence or absence of a parity bit
  • frame-error tolerance
From the previous section, we have

Now our final-bit-sampling margin is a variable; we’ll use M (previously we used 20%). As you can see from the following equation, M must be entered as a decimal, not a percentage.


We still have the 8 out in front of ΔTRX. We need to change that because now the number of data bits (denoted by N) is a variable. We also will include a variable for the parity bit (P) and the stop bit (S). If you have a parity bit, use 1 for P; if not, use 0. If you want to ensure that the stop bit is sampled correctly, use 1 for S; if not, use 0.

The last thing we need is the variable that accounts for the actual position at which the start bit is sampled. The equation in its current form assumes 50% (i.e., the exact middle of the bit period). This is the ideal position. Any deviation from the ideal can cause the sampling position of later bits to be closer to the transition (and thus closer to an error). We will incorporate this into the equation by adding the following term to the left-hand side:

This term refers to the deviation from the ideal start-bit sampling position, expressed as a decimal multiplied by the receiver’s bit period. So, for example, if the start bit is sampled 60% of the way through the bit period, this term would be |(50% – 60%)|TRX = 0.1TRX. You can’t readily determine an exact value for this term, but if you know the details of your UART’s low-level functionality, you could come up with a reasonable worst-case estimate.
Now our equation is

If we recall that the Rx bit period is equal to the Tx bit period plus the additional time corresponding to the error percentage, our final equation is as follows:


Example and Conclusion

Let’s consider the following system:
  • margin is 30%
  • worst-case start-bit sampling deviation is 5%
  • eight data bits
  • no frame errors allowed
  • parity bit is used
Thus, we have




I hope this article helps you with any future baud-rate-accuracy concerns, and remember that a careful baud-rate analysis may indicate that you can confidently omit an external crystal, even if your internal oscillator is not as precise as you might like.
Previous
Next Post »
My photo

Hi, I`m Sostenes, Electrical Technician and PLC`S Programmer.
Everyday I`m exploring the world of Electrical to find better solution for Automation. I believe everyday can become a Electrician with the right learning materials.
My goal with BLOG is to help you learn Electrical.
Related Posts Plugin for WordPress, Blogger...

Label

KITAIFA NEWS KIMATAIFA MICHEZO BURUDANI SIASA TECHNICAL ARTICLES f HAPA KAZI TU. LEKULE TV EDITORIALS ARTICLES DC DIGITAL ROBOTICS SEMICONDUCTORS MAKALA GENERATOR GALLERY AC EXPERIMENTS MANUFACTURING-ENGINEERING MAGAZETI REFERENCE IOT FUNDAMENTAL OF ELECTRICITY ELECTRONICS ELECTRICAL ENGINEER MEASUREMENT VIDEO ZANZIBAR YETU TRANSDUCER & SENSOR MITINDO ARDUINO RENEWABLE ENERGY AUTOMOBILE SYNCHRONOUS GENERATOR ELECTRICAL DISTRIBUTION CABLES DIGITAL ELECTRONICS AUTOMOTIVE PROTECTION SOLAR TEARDOWN DIODE AND CIRCUITS BASIC ELECTRICAL ELECTRONICS MOTOR SWITCHES CIRCUIT BREAKERS MICROCONTROLLER CIRCUITS THEORY PANEL BUILDING ELECTRONICS DEVICES MIRACLES SWITCHGEAR ANALOG MOBILE DEVICES CAMERA TECHNOLOGY GENERATION WEARABLES BATTERIES COMMUNICATION FREE CIRCUITS INDUSTRIAL AUTOMATION SPECIAL MACHINES ELECTRICAL SAFETY ENERGY EFFIDIENCY-BUILDING DRONE NUCLEAR ENERGY CONTROL SYSTEM FILTER`S SMATRPHONE BIOGAS POWER TANZIA BELT CONVEYOR MATERIAL HANDLING RELAY ELECTRICAL INSTRUMENTS PLC`S TRANSFORMER AC CIRCUITS CIRCUIT SCHEMATIC SYMBOLS DDISCRETE SEMICONDUCTOR CIRCUITS WIND POWER C.B DEVICES DC CIRCUITS DIODES AND RECTIFIERS FUSE SPECIAL TRANSFORMER THERMAL POWER PLANT cartoon CELL CHEMISTRY EARTHING SYSTEM ELECTRIC LAMP FUNDAMENTAL OF ELECTRICITY 2 BIPOLAR JUNCTION TRANSISTOR ENERGY SOURCE 555 TIMER CIRCUITS AUTOCAD C PROGRAMMING HYDRO POWER LOGIC GATES OPERATIONAL AMPLIFIER`S SOLID-STATE DEVICE THEORRY DEFECE & MILITARY FLUORESCENT LAMP HOME AUTOMATION INDUSTRIAL ROBOTICS ANDROID COMPUTER ELECTRICAL DRIVES GROUNDING SYSTEM BLUETOOTH CALCULUS REFERENCE DC METERING CIRCUITS DC NETWORK ANALYSIS ELECTRICAL SAFETY TIPS ELECTRICIAN SCHOOL ELECTRON TUBES FUNDAMENTAL OF ELECTRICITY 1 INDUCTION MACHINES INSULATIONS ALGEBRA REFERENCE HMI[Human Interface Machines] INDUCTION MOTOR KARNAUGH MAPPING USEUL EQUIATIONS AND CONVERSION FACTOR ANALOG INTEGRATED CIRCUITS BASIC CONCEPTS AND TEST EQUIPMENTS DIGITAL COMMUNICATION DIGITAL-ANALOG CONVERSION ELECTRICAL SOFTWARE GAS TURBINE ILLUMINATION OHM`S LAW POWER ELECTRONICS THYRISTOR USB AUDIO BOOLEAN ALGEBRA DIGITAL INTEGRATED CIRCUITS FUNDAMENTAL OF ELECTRICITY 3 PHYSICS OF CONDUCTORS AND INSULATORS SPECIAL MOTOR STEAM POWER PLANTS TESTING TRANSMISION LINE C-BISCUIT CAPACITORS COMBINATION LOGIC FUNCTION COMPLEX NUMBERS ELECTRICAL LAWS HMI[HUMANI INTERFACE MACHINES INVERTER LADDER DIAGRAM MULTIVIBRATORS RC AND L/R TIME CONSTANTS SCADA SERIES AND PARALLEL CIRCUITS USING THE SPICE CIRCUIT SIMULATION PROGRAM AMPLIFIERS AND ACTIVE DEVICES BASIC CONCEPTS OF ELECTRICITY CONDUCTOR AND INSULATORS TABLES CONDUITS FITTING AND SUPPORTS CONTROL MOTION ELECTRICAL INSTRUMENTATION SIGNALS ELECTRICAL TOOLS INDUCTORS LiDAR MAGNETISM AND ELECTROMAGNETISM PLYPHASE AC CIRCUITS RECLOSER SAFE LIVING WITH GAS AND LPG SAFETY CLOTHING STEPPER MOTOR SYNCHRONOUS MOTOR AC METRING CIRCUITS BASIC AC THEORY BECOME AN ELECTRICIAN BINARY ARITHMETIC BUSHING DIGITAL STORAGE MEMROY ELECTRICIAN JOBS HEAT ENGINES HOME THEATER INPECTIONS LIGHT SABER MOSFET NUMERATION SYSTEM POWER FACTORS REACTANCE AND IMPEDANCE INDUCTIVE RESONANCE SCIENTIFIC NOTATION AND METRIC PREFIXES SULFURIC ACID TROUBLESHOOTING TROUBLESHOOTING-THEORY & PRACTICE 12C BUS APPLE APPS & SOFTWARE BATTERIES AND POWER SYSTEMS ELECTROMECHANICAL RELAYS ENERGY EFFICIENCY-LIGHT INDUSTRIAL SAFETY EQUIPMENTS MEGGER MXED-FREQUENCY AC SIGNALS PRINCIPLE OF DIGITAL COMPUTING QUESTIONS REACTANCE AND IMPEDANCE-CAPATIVE RECTIFIER AND CONVERTERS SEQUENTIAL CIRCUITS SERRIES-PARALLEL COMBINATION CIRCUITS SHIFT REGISTERS BUILDING SERVICES COMPRESSOR CRANES DC MOTOR DRIVES DIVIDER CIRCUIT AND KIRCHHOFF`S LAW ELECTRICAL DISTRIBUTION EQUIPMENTS 1 ELECTRICAL DISTRIBUTION EQUIPMENTS B ELECTRICAL TOOL KIT ELECTRICIAN JOB DESCRIPTION LAPTOP THERMOCOUPLE TRIGONOMENTRY REFERENCE UART WIRELESS BIOMASS CONTACTOR ELECTRIC ILLUMINATION ELECTRICAL SAFETY TRAINING FILTER DESIGN HARDWARE INDUSTRIAL DRIVES JUNCTION FIELD-EFFECT TRANSISTORS NUCLEAR POWER VALVE WWE oscilloscope 3D TECHNOLOGIES COLOR CODES ELECTRIC TRACTION FLEXIBLE ELECTRONICS FLUKE GEARMOTORS INTRODUCTION LASSER MATERIAL PID PUMP SCIENCE SEAL ELECTRICIAN CAREER ELECTRICITY SUPPLY AND DISTRIBUTION FEATURED MUSIC NEUTRAL PERIODIC TABLES OF THE ELEMENTS POLYPHASE AC CIRCUITS PROJECTS REATORS SATELLITE STAR DELTA VIBRATION WATERPROOF