In embedded system design, single-chip microcomputers are core control units, and their operation depends on accurate clock signals. Whether it is a simple LED flashing (bu~ling~bu~ling~) or a complex industrial automation control, the stability of the clock signal directly affects the reliability and performance of the system. Currently, single-chip microcomputers on the market generally have built-in RC oscillators. Sometimes, considering the cost or application background, the built-in RC oscillator is directly used as the system clock source of the single chip, but in many application scenarios, an external crystal oscillator is still an indispensable configuration.
All operations of single-chip microcomputers rely on the drive of clock signals. For example, instruction execution needs to be read and decoded according to the clock beat; serial communication needs to accurately control the timing of data sending and receiving according to the baud rate; the generation of PWM (pulse width modulation) signals also requires a stable clock cycle. If the clock signal is unstable, it may cause the execution of instructions to be disordered, because the clock frequency deviation will cause the program to run abnormally, or even cause logical errors; or cause communication failure. In serial communication, if the baud rate error exceeds ±5%, the data may be lost or garbled due to the sampling point offset. Real-time out of control may also occur. In scenarios that require strict timing control (such as motor drive and sensor data acquisition), clock deviation may directly lead to system failure.
An external crystal oscillator can improve the stability and anti-interference of the system. The working principle of the crystal oscillator is to use the piezoelectric effect of the quartz crystal to achieve stable frequency output through mechanical vibration and electric field conversion. Its frequency error is usually at the ppm level (one millionth), while the error of the internal RC oscillator may be as high as 1%~5%. The oscillation signal amplitude of the crystal oscillator is large and the waveform is pure, and the sensitivity of the quartz crystal to temperature and voltage fluctuations is much lower than that of the RC circuit. In industrial sites with complex electromagnetic environments, crystal oscillators can avoid clock signal distortion caused by noise interference. The upper frequency limit of the internal RC oscillator is usually tens of MHz, while the external crystal oscillator can easily support high-frequency requirements of hundreds of MHz. For example, in high-speed communication (such as USB 3.0 and Ethernet), the STM32 series microcontrollers need to be connected to an external 25MHz or 50MHz crystal to meet the timing requirements. In the RF communication module, the internal RF chip needs to be connected to an external 26MH or 52MHz crystal to ensure a stable frequency, such as our SPI interface RF module.
The external crystal oscillator is not selected arbitrarily. It needs to be selected according to the usage scenario and there are some precautions during use. Different microcontrollers have different requirements for the frequency of the external crystal oscillator. For example, 8051 often uses 11.0592MHz (for serial communication), and STM32 often uses 8MHz crystal oscillator. The load capacitance of the crystal oscillator needs to match the external capacitance. For example, if a crystal oscillator with a nominal load capacitance of 20pF actually uses a 15pF capacitor, it will cause frequency deviation. SMD crystal oscillators (such as 3225 packages) are suitable for miniaturized designs, but attention should be paid to the length and layout of the PCB traces to avoid introducing parasitic capacitance that affects the frequency. The crystal oscillator itself has low power consumption, but the accuracy and power consumption need to be balanced in low-power power supply devices.
The external crystal oscillator has the advantages of high precision, high stability and high anti-interference ability, making it a key component to ensure reliability in the microcontroller system. Although the internal RC oscillator can reduce cost and space in simple applications, in scenarios with strict clock requirements (such as industrial control, high-speed communication, automotive electronics, etc.), the external crystal oscillator is still the only choice. With the development of technology, the crystal oscillator is also evolving towards miniaturization and low power consumption, but its core value (providing a stable clock reference) has remained unchanged.