When learning about the 51 microcontroller, there are many questions related to crystal oscillators. In fact, the crystal oscillator is like the heart of a person, it is the blood and the pulse. Once the crystal oscillator issues are clarified, other issues with the 51 microcontroller can be easily resolved…
Here are some summarized questions about the crystal oscillator related to the 51 microcontroller, hoping to help those learning the 51 microcontroller.
1. Why do 51 microcontrollers prefer to use 11.0592MHz crystal oscillators?
Firstly: Because it can accurately divide into clock frequencies related to the common baud rates of UART (Universal Asynchronous Receiver/Transmitter). Especially at higher baud rates (19600, 19200), no matter how strange the values are, these crystal oscillators are accurate and commonly used.
Secondly: The reason for using an 11.0592 crystal oscillator is caused by the timer of the 51 microcontroller. When using the timer of the 51 microcontroller as a baud rate generator, if an 11.0592MHz crystal oscillator is used, according to the formula, the values set for the timer are all integers; if a 12MHz crystal oscillator is used, the baud rates will have deviations. For example, at 9600, using the timer to get 0XFD results in an actual baud rate of 10000, and a general baud rate deviation of about 4% is acceptable, so the STC90C516 crystal oscillator at 12M baud rate of 9600 can still be used, with a multiple error rate of 6.99% and a non-multiple error rate of 8.51%. Data will definitely be incorrect. This is why everyone prefers to use the 11.0592MHz crystal oscillator for serial communication; at multiple baud rates, it can reach up to 57600 with an error rate of 0.00%. Using 12MHz, the maximum is only 4800, with an error rate of 0.16%, but within the acceptable range, so it does not have much impact.
2. Why is the crystal oscillator required to be placed close to the microcontroller when designing the PCB for the 51 microcontroller system?
The reason is as follows: The crystal oscillator generates fixed frequency mechanical vibrations through electrical excitation, which in turn generates current feedback to the circuit. The circuit amplifies the signal after receiving the feedback and uses the amplified electrical signal to excite the mechanical vibration of the crystal oscillator again, which then feeds back the current generated by the vibration to the circuit. When the excitation electrical signal in the circuit matches the nominal frequency of the crystal oscillator, the circuit can output a strong signal with a stable frequency sine wave. The shaping circuit then converts the sine wave into a square wave for use in digital circuits.
The problem is that the output capability of the crystal oscillator is limited; it only outputs electrical energy in milliwatts. Inside the IC (Integrated Circuit), this signal must be amplified hundreds of times or even thousands of times to be used normally.
The connection between the crystal oscillator and the IC is generally through copper traces, which can be seen as a wire or several segments of wire. When the wire is cut through magnetic field lines, it generates current; the longer the wire, the stronger the generated current. In reality, magnetic field lines are not common, but electromagnetic waves are everywhere, such as in wireless broadcasting, TV tower transmissions, mobile communications, etc. The connection between the crystal oscillator and the IC becomes an antenna; the longer it is, the stronger the received signal and the generated electrical energy. Until the received electrical signal strength exceeds or approaches the signal strength generated by the crystal oscillator, the output from the amplifier circuit inside the IC will no longer be a fixed frequency square wave but a chaotic signal, leading to synchronization failures in digital circuits.
Therefore, when designing the PCB, the crystal oscillator should be as close to its amplifier circuit (IC pins) as possible.
3. Analysis of the reasons why the microcontroller circuit crystal oscillator does not oscillate
Encountering a situation where the microcontroller’s crystal oscillator does not oscillate is a common phenomenon. So what are the reasons for the crystal oscillator not oscillating?
1) Incorrect PCB wiring; 2) Quality issues with the microcontroller; 3) Quality issues with the crystal oscillator; 4) Load capacitance or matching capacitance not matching the crystal oscillator or quality issues with the capacitors; 5) PCB dampness leading to impedance mismatch and failure to oscillate; 6) Long wiring in the crystal oscillator circuit; 7) Wiring between the two pins of the crystal oscillator; 8) Influence of peripheral circuits.
The solution is to suggest eliminating faults one by one as follows:
1) Exclude the possibility of circuit errors, so you can compare with the recommended circuit of the corresponding model of the microcontroller. 2) Exclude the possibility of peripheral component failure, as peripheral components are just resistors and capacitors, which are easy to identify as good or bad. 3) Exclude the possibility of the crystal oscillator being a non-oscillating type, as it is not likely that only one or two crystal oscillators were tested. 4) Try changing the capacitance on both ends of the crystal; perhaps the crystal oscillator will start oscillating, and the capacitance size should refer to the crystal’s usage instructions.
5) When wiring the PCB, the wiring of the crystal oscillator circuit should be as short as possible and as close to the IC as possible, avoiding wiring between the two pins of the crystal oscillator.
4. How are the capacitance values determined when using a 12MHz crystal oscillator in the clock circuit of a 51 microcontroller? Let’s explain with the internal clock circuit!
In fact, no one can clearly explain how to select these two capacitance values because 22pF is really too small. This can only be said to relate to the internal characteristics of the oscillation circuit itself, used in combination to correct the waveform; no one delves into why it is exactly this size.
What will happen if the 89C52 microcontroller does not connect to a crystal oscillator?
The microcontroller will not work, and the program cannot be burned in…
5. What happens if the two trimming capacitors in the microcontroller crystal oscillator circuit are asymmetrical? How much difference will cause frequency changes? When testing the receiving module of a wireless mouse, it was found that the frequency always slowly changes (that is, when the probe is held, the frequency gradually decreases) and the crystal oscillator is new!
Asymmetrical capacitance will not cause frequency drift; the so-called frequency drift may be caused by the instability of the capacitance of the crystal oscillator. You can try changing them; changing two capacitors is not difficult, or the stability of the crystal oscillator is too poor, or the measuring method has issues.
6. Questions about microcontroller crystal oscillators and speed. Isn’t the execution cycle of an instruction determined by the crystal oscillator? So, for example, if the 51 microcontroller is connected to a high-speed crystal oscillator and the MSP430 is connected to a low-speed one, does that mean the 51 will run faster? Is the speed of the microcontroller only related to the crystal oscillator, or is it crucial whether the microcontroller can support such a large crystal oscillator?
The speed of each microcontroller is limited by the internal logic gate level transition speed. If both chips use the same crystal oscillator, for example, 12M. Because AVR is a RISC instruction set, it is faster than 51 at the same external crystal frequency.
For example, the 51 can connect to a maximum of 40M, while the AVR can connect to a 16M crystal oscillator.
STC89C52 mostly uses a 12MHz crystal oscillator, but since it takes 12 clock cycles for one machine cycle, its main frequency is only 1MHz.
MSP430 uses the RISC reduced instruction set, and the 430 microcontroller can reach a main frequency of 21MHz if it uses internal DCO oscillation. One clock cycle can execute one instruction, making it 12 times faster than the 51 with the same crystal oscillator.
For a 51, using a higher crystal oscillator will make it run a bit faster. However, for advanced microcontrollers, it is different. Advanced microcontrollers generally have frequency control registers internally, so simply increasing the crystal oscillator may reach the microcontroller’s limits, causing it to run away.
7. Is there a method to determine if a certain microcontroller can work normally with a certain size crystal oscillator?
Choosing a crystal oscillator that is too high is not suitable. The specific upper limit of the crystal oscillator is difficult to measure; you can only follow the requirements of the microcontroller. Generally, the upper limit of STC series microcontrollers is 35M or 40M. For example, STC11F16XE 35I-LQFP44G, where 35I indicates that it is an industrial-grade chip with a maximum of 35M.
What problems will arise if the upper limit is exceeded? It is generally not tested. Usually, a 12M crystal oscillator is chosen more; if you select a 1T instruction, it is equivalent to a 12*12=144M crystal oscillator. For serial communication, it is recommended to use an 11.0592M or 22.184M crystal oscillator. The main principle for selecting a crystal oscillator is still to refer to the manufacturer’s instructions.
8. Can four AT89C51 microcontrollers use one 12M crystal oscillator to work normally? One uses internal clock mode, while the other three use external mode… Can all four use internal mode (connecting all four microcontrollers to one crystal oscillator)?
Yes, one can be normally connected to the crystal oscillator, and its XTAL2 output can be connected to the XTAL1 inputs of the other three.
9. The relationship between the operating speed of the microcontroller and the size of the crystal oscillator. If the maximum working frequency of the microcontroller is 40M, can the crystal oscillator be chosen as 24M or higher, but not exceeding 40M? Will this greatly increase the operating speed of the microcontroller? Will working at this frequency for a long time have adverse effects on the microcontroller? What are the principles for selecting a crystal oscillator?
Of course, there is an impact. The faster the microcontroller’s operating speed, the greater the power consumption and the more susceptible it is to interference. In short, if it can run at a maximum of 40M, it is fine as long as it does not exceed 40M, but it will require much more related technology (such as PCB design, component selection, etc.).
10. Why is a 12MHz crystal oscillator commonly used in the reset circuit of the 89C51 microcontroller, but slightly less than 12MHz is found on the market?
Answer: When serial communication is needed, 11.0582MHz is generally used, so that the baud rate can be calculated easily.
Using 12MHz makes the working cycle easier to calculate.
11. The crystal oscillator does not oscillate when powered on, but it starts oscillating when touched. Why? How can one determine whether the microcontroller’s crystal oscillator is oscillating?
Check if the capacitors paired with the crystal oscillator are soldered, and whether the values are correct?
The simplest way is to use an oscilloscope; additionally, check if the power supply is normal.
12. How to determine whether the external crystal oscillator of the microcontroller is oscillating? The STC89C52 microcontroller was working fine, but later it stopped working. After replacing the crystal oscillator, it worked again. However, after a few hours, it failed again. What could be the reason? Also, how to determine whether the crystal oscillator is oscillating?
1) Try replacing the microcontroller first; if the problem persists, exclude the microcontroller. 2) It may be due to cold soldering; pay attention to this point. 3) Similar issues have occurred with the STC89C52; replacing the crystal oscillator resolved it, but it seems that the STC does not oscillate as smoothly as the AT89S52. In fact, for the STC89C52, you can directly check pin 30 (ALE); connecting a light will allow you to see the oscillation immediately.
13. How to choose the capacitance size connected to the crystal oscillator of the 51 microcontroller? Should the capacitance value be larger if the crystal oscillator is bigger? What is the commonly used size? It is said that commonly used values range from 15-33pF; how to choose the best effect? For example, for a 6M and a 12M crystal oscillator, what capacitance is more suitable?
15-33pF is acceptable; we generally use 15P and 30P. The size of the crystal oscillator does not significantly affect the commonly used 4M, 12M, 11.0592M, and 20M, 24M; we all use 30P. The microcontroller has corresponding shaping circuits, so we need not worry.
23. What will happen if a 12M crystal oscillator is connected to a 2200pF capacitor? The circuit diagram seems to suggest 22pF, but if there is no 22pF, will connecting 2200pF cause it to fail to work properly?
No, the crystal will not work. 15-33p is a reasonable range. You can try it; it will not damage the microcontroller.
14. Can an external crystal oscillator oscillate in a blank microcontroller without a program?
In microcontrollers without internal oscillators, external crystal oscillators can oscillate. For traditional MS51 series microcontrollers with internal oscillators, external crystal oscillators will not oscillate unless configured; if not configured, they will still use internal oscillators, such as Silicon Lab series C8051F020 microcontroller.
15. Why does the AT89C52 output 2.5V on P1.0, and it seems the microcontroller is not working? The waveform of the crystal oscillator is an irregular sine wave; is that acceptable? The circuit board did not achieve the expected effect, and the LED remains lit. It seems to be a problem with the microcontroller. P1.0 outputs 2.5V; what is going on?
Remove the watchdog and temporarily create a minimum system, which includes only the power supply, 8952, crystal oscillator, and two capacitors of about 30P.
1) Set P1.0 to 1, and test whether the voltage at that pin is over 2.5V; 2) Set P1.0 to 0, and test whether the voltage at that pin is approximately 0V.
If so, it is OK; otherwise, check the power supply voltage, crystal oscillator, and 8952. The power supply voltage should be 5±0.25V, and the ripple should be minimal.
16. When making a MAX232 downloader for the microcontroller, is it necessary to add an external crystal oscillator?
Of course, it is necessary. Without an external crystal oscillator, the microcontroller’s clock circuit will be absent, causing the microcontroller’s serial port to be unable to transmit data, ultimately resulting in the downloader being unable to download the program.
17. If the 89C52 microcontroller uses an external crystal oscillator, how should it be set up?
The two pins of the crystal oscillator should each connect to a 20~30pF capacitor, which are then connected to the XTAL1 and XTAL2 of the microcontroller. The other ends of the two capacitors are connected together and grounded, with no further settings needed.
18. What is the principle of the crystal oscillator, and how does it generate a sine signal? Please analyze it in detail from a circuit perspective!
The crystal can be equivalent to an inductor, forming an oscillation loop with the capacitance inside it, allowing energy to transfer from the inductor to the capacitor and back, creating oscillations. The positive half-cycle is the charging and discharging process of the capacitor, while the negative half-cycle is the charging and discharging process of the inductor.
19. Now, if you want to use the 52 microcontroller to create a traffic light circuit, requiring red light, green light for 30 seconds, and yellow light for 3 seconds in a cycle, how should the external crystal oscillator be chosen? What is a suitable instruction cycle? What is the role of the two external capacitors, and what size is appropriate?
If choosing a crystal oscillator, the two capacitor values can be selected as approximately 30±10PF (frequency between 0~33MHZ);
If choosing a ceramic crystal oscillator, the capacitor values can be selected as approximately 40±10PF (frequency between 1.2~12MHZ). The oscillator should be as close to the capacitors as possible. The instruction cycle can be calculated, as there is a formula for it!
20. The frequency of the crystal oscillator for the 89C52 microcontroller is only 12MHz, which is too small. How can the crystal oscillator frequency be increased?
Use an external 18.432 or 24MHz crystal oscillator. Alternatively, switch to a 4T W77E58 microcontroller, which effectively triples the operating frequency. Or switch to a 1T DS89C4XX microcontroller, which effectively increases the operating frequency by eight times! Using a 1T STC12C5A60S2 microcontroller will also have the same effect.
21. If the microcontroller cannot work normally, could it be a crystal oscillator issue? How to check if the crystal oscillator is normal? Additionally, it has been said that the crystal oscillator and the two small capacitors should be very close, with no leads trimmed (just plug it in as long as it is). Does this matter?
Use a multimeter to measure the two pins connected to the crystal oscillator on the microcontroller. In a normal oscillating state, the voltage is approximately slightly lower than half the supply voltage. If one or both pins are at supply voltage or zero, it indicates that it is not oscillating. The length of the leads generally does not have much impact; in comparison, grounding is more critical. The grounding end of the two resonant capacitors should be as close as possible to the ground of the microcontroller.
Some screenshots of electronic books