Literacy: What is MCU timing and how to understand the timing diagram

Publisher:dfdiqcLatest update time:2022-01-11 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

insert image description here

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

insert image description here

Keywords:MCU Reference address:Literacy: What is MCU timing and how to understand the timing diagram

Previous article:Design of 51 single chip wireless music doorbell
Next article:Taxi meter project design

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号