We all know that the school uses bells to control the class start and end times of all classes. How does the microcontroller fetch instructions, execute instructions and perform other operations? Here we introduce the concept of timing:
1. Clock circuit
There are three types of microcontroller clock circuits:
1. There is a high-gain inverting amplifier inside the microcontroller to form an oscillator. Pins XTAL1 and XTAL2 are the input and output of this amplifier respectively. XTAL1 and XTAL2 need to be connected to a crystal and a suitable capacitor.
2. Some microcontrollers also have built-in clock circuits to generate clock signals.
3. The microcontroller pin XTAL2 is directly connected to the crystal oscillator.
2. Cycle
1. Clock cycle
The period of the clock signal generated by the clock circuit is called the clock period (oscillation period).
When the microcontroller is powered on, a pulse signal with a fixed nominal value is generated. Driven by the pulse signal, the microcontroller sequentially takes out instructions from the ROM (program memory) and executes them one by one, and then performs a series of micro-operation controls to complete various specified actions.
2. Machine Cycle
The time it takes for a microcontroller to access the memory is called a machine cycle. It is a time base just like the seconds we use in our daily lives. A machine cycle in a microcontroller includes 12 oscillation cycles. The oscillation cycle is the cycle of the oscillation source, which is also the time cycle of the crystal oscillator we use. A 12M crystal oscillator has a time cycle of 1/12 microseconds, so a machine cycle of a microcontroller using a 12M crystal oscillator should be equal to 12*1/12 microseconds, which is 1 microsecond.
3. Instruction cycle
Some instructions in the microcontroller only need one machine cycle, while some instructions need two or three machine cycles. There are also two instructions that need four machine cycles. To measure the length of instruction execution time, we need to use a new concept: instruction cycle, which is the machine cycle required to execute an instruction.
3. Timing
The timing of a single-chip microcomputer refers to the time sequence of control signals that should be issued when the single-chip microcomputer executes instructions. The relationship between these control signals in time is the timing of the CPU. It is a series of pulse signals with a time sequence.
There are two types of timings issued by the CPU: one is used to control the functional components within the chip, which is the concern of chip designers and has little meaning to users. The other is used to control off-chip memory or I/O ports, which need to be sent to the outside of the chip through the control pins of the device. This part of the timing is crucial to analyzing the principles of hardware circuits and is also the principle followed by software programming, which needs to be carefully mastered.
There are two types of timings issued by the CPU: one is used to control the functional components within the chip, which is the focus of chip designers and has little meaning to users. The other is used to control the external chips of the microcontroller. This part of the timing is crucial to analyzing the principles of hardware circuits and is also the principle followed by software programming.
The operating timing is always the most important content of any IC chip. All the usage details of a chip will be included in its official device manual. Therefore, when using a device, the first thing to do is to extract the useful content from its device manual and master its working timing.
Here we take LCD 1602 as an example to analyze its operation timing. Its basic timing includes read status, write command, read data and write data.
Here, we need to pay attention to several pins of 1602, namely RS, RW, E, D0...D7. From the above description we can know:
RS: Data/command (status) selection terminal. When this pin is at a high level, the data byte transmission operation can be performed on 1602, and when this pin is at a low level, the command (status) byte transmission operation is performed.
RW: Read/write selection terminal. When this pin is at a high level, data can be read from LCD1602, otherwise data can be written.
E: Enable signal, which is actually the data control clock signal of LCD1602. The rising edge of this signal is used to realize data transmission to LCD1602.
D0…D7: 8-bit parallel data port.
Here, we analyze two write timings: write command and write data.
1. When we want to write instruction words and set the working mode of LCD1602: we need to set RS to low level, RW to low level, and then send the data to data port D0~D7, and finally write the data with a high pulse on the E pin.
void WriteCommandLCD(unsigned char WCLCD,BuysC) //BuysC is 0 and the busy detection is ignored
{
if (BuysC) ReadStatusLCD(); //Check busy as needed
LCD_Data = WCLCD; //Put the command to be written on the data line
LCD_RS = 0; //RS is low, indicating that the command to be written
LCD_RW = 0; //RS is low, indicating that a write operation is being performed
LCD_E = 0;
LCD_E = 0;
LCD_E = 1; //The above three statements introduce a high pulse
}
2. When we want to write data words and display them on 1602: we need to set RS to a high level, RW to a low level, and then send the data to data ports D0~D7. Finally, a high pulse on the E pin will write the data.
void WriteDataLCD(unsigned char WDLCD)
{
ReadStatusLCD(); //Detection busy
LCD_Data = WDLCD; //Put the command to be written on the data line
LCD_RS = 1; //RS is high, indicating that the data to be written is data
LCD_RW = 0; //RS is low, indicating that a write operation is being performed
LCD_E = 0;
LCD_E = 0;
LCD_E = 1; //The above three statements introduce a high pulse
}
The only difference between writing instructions and writing data is the different RS levels. The following is the timing diagram of LCD1602. When writing driver code, you must fully understand the timing diagram of the device (with text instructions), otherwise you will not be able to write qualified driver code and the device will not work. You can compare the above code with the figure below to see if it is the same.
Things to note when looking at the timing diagram:
1. Pay attention to the time axis. The direction from left to right is the positive time axis, that is, time is increasing.
2. The leftmost part of the timing diagram is usually the logo of a certain pin, indicating that this line of the graph reflects the changes of the pin. The above figure respectively indicates the timing changes of four types of pins: RS, R/W, E, and DB0~DB7.
3. The part with crossed lines indicates that the electrical level is changing.
4. The two parallel lines correspond to high and low levels, as shown in the upper right corner of the above figure.
5. The sealed diamond part indicates that the data is valid, and the word Valid Data also shows this.
6. The level changes of each pin in the timing diagram are based on the same time axis. You must observe the timing diagram accurately in strict accordance with the growth direction of the time axis. Make sure the device strictly follows the changes in the timing diagram.
7. Time marking is also very important information. These time markings indicate the shortest or longest time that certain states need to be maintained. Because the working speed of the device is also limited and generally cannot keep up with the speed of the main control chip, there must be timing coordination between them. The following is a timing parameter table
Previous article:Design of 51 single chip wireless music doorbell
Next article:Taxi meter project design
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Purgatory Legend-FIFO Battle
- How bias circuit works!!!
- The best articles of Bluetooth in the past 10 years
- Program to replace Matlab results with EXCEL formulas
- C2000 ±0.1° Accurate Discrete Resolver Front-End Reference Design
- Unboxing ESP32-S2 and S3
- Easily solve design challenges with MSP430 MCUs
- TI Logistics Robot CPU Board
- I would like to ask which one has better performance, thank you for your recommendation
- TI supports Bluetooth technology for high-precision body temperature measurement flexible PCB reference design