I want to make a new board working with 115200 (gsm modem) UART. so I want minimum baud error rate. I look at


table and decide to work with ATmega328P 7.3728 Mhz / 3v3

The second step is choosing the right XTAL capacitance (Ce)

Cl = 18 pF (Load Capacitance of External Crystal) [ECS-073-18-20BM-JEN-TR]
Cs = 5 pF (Stray Capacitance; in additional sources says you can take it 2-5 pF)
Ci = 18 pF (ATmega328P datasheet; XTAL/TSOC capacitance)

This formula is given in ATmega datasheet

Ce = 2Cl - Cs - Ci


Ce = 2.18 - 5 - 18

External Capacitance is

Ce = 13 pF
CRYSTAL ESR = 70 ohm

is that a true calculation? and true settings for my clock setting?

Fuse Settings :

 Low Byte Fuse : 0xFD 
 High Byte Fuse : 0xDA 
 Extended Byte Fuse : 0xFD
  • \$\begingroup\$ Just as a note: Normally the CPU and speed are chosen for the amount of work to be done. You will have 640 CPU cycles to process each byte (assuming n,8,1). \$\endgroup\$ – Oldfart Feb 12 '19 at 10:22
  • \$\begingroup\$ The answer to your actual problem is that it doesn't matter a bit. The UART resyncs at least once every new byte, and can tolerate timing errors up to several percent before you start dropping bytes. Your 20 ppm crystal is thousand times better than what is needed. It's a good question though, for other reasons you might want better assurance of crystal speed (and startup stability) \$\endgroup\$ – pipe Feb 12 '19 at 10:42
  • \$\begingroup\$ I make the other board with 328P and internal 8 Mhz crystal (with Li-Ion battery power source). And when I started to communicate with GSM modem sometimes have a frame error. So I want to be careful with that. \$\endgroup\$ – Mehmet Günce Akkoyun Feb 12 '19 at 11:16
  • 1
    \$\begingroup\$ @MehmetGünceAkkoyun As you can see from the table you posted, 8 MHz gives you over 7% mismatch. It has nothing to do with capacitor matching. \$\endgroup\$ – pipe Feb 12 '19 at 12:29
  • \$\begingroup\$ @pipe, using U2X bit will halve the error to only 3.5%. The internal oscillator is factory calibrated at 3.0V and 25C to give 10% tolerance, so statistically it could work. Then using oscillator calibration register, you can calibrate the oscillator to 1% which will work. But it is no match for an external crystal. \$\endgroup\$ – Justme Feb 12 '19 at 17:50

The external capacitor selection is not so accurate, and the 18pF value for pin capacitance is from the table for using it with 32kHz tuning fork crystals, not for higher frequency crystals.

You have a crystal with CL=18pF. AVR datasheet says to use identical capacitor values between 12pF and 22pF. If you put 22pF capacitors there, it creates 11pF of load, if you assume the pin and stray capacitance to be 5-10pF in total, you end up with 16pF to 21pF of load which is very close to the required 18pF. It will certainly just simply work. For any more accurate capacitor values, and to include larger variations, you would have to find a tool to measure the frequency or estimate the PCB stray capacitance. But as you see you can't really put a crystal with higher CL rating there, so if you have higher stray and pin capacitance, perhaps using 18pF capacitors and crystal with CL=16pF would be better, but overkill as a starting point.

You can also keep using the internal oscillator if you use USART U2X bit and calibrate the internal oscillator down to 7.37MHz.

| improve this answer | |
  • \$\begingroup\$ Thaks for your answer. I look for new crystal with CL=16 pf and find this mouser.com.tr/ProductDetail/IQD/… if i use this crystal with 18pf capacitors is it more accurate from my values given above ? and what is your crystal advice ? \$\endgroup\$ – Mehmet Günce Akkoyun Feb 13 '19 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.