What is a clock cycle? What is a machine cycle? What is an instruction cycle?
Clock cycleThe clock cycle is also called the oscillation cycle, which is defined as the reciprocal of the clock pulse (it can be understood that the clock cycle is the reciprocal of the crystal oscillator connected to the microcontroller. For example, the time cycle of a 12M crystal oscillator is 1/12 us). It is the most basic and smallest time unit in the computer. In one clock cycle, the CPU only completes one basic action. For a certain microcontroller, if a clock frequency of 1MHZ is used, the clock cycle is 1us; if a clock frequency of 4MHZ is used, the clock cycle is 250ns. Since the clock pulse is the basic working pulse of the computer, it controls the working rhythm of the computer (making every step of the computer unified to its pace). Obviously, for the same type of computer, the higher the clock frequency, the faster the computer works. However, since different computer hardware circuits and devices are not exactly the same, the required clock cycle frequency range is not necessarily the same. The clock range of the 8051 microcontroller we are studying is 1.2MHz-12MHz. In the 8051 microcontroller, one clock cycle is defined as one beat (indicated by P), and two beats are defined as one state cycle (indicated by S).
Machine Cycle
In computers, for ease of management, the execution process of an instruction is often divided into several stages, and each stage completes a task. For example, fetching instructions, memory reading, memory writing, etc., each of these tasks is called a basic operation. The time required to complete a basic operation is called a machine cycle. Generally speaking, a machine cycle consists of several S cycles (state cycles). A machine cycle of the 8051 series microcontroller consists of 6 S cycles (state cycles). As mentioned earlier, a clock cycle is defined as a beat (represented by P), and two beats are defined as a state cycle (represented by S). The machine cycle of the 8051 microcontroller consists of 6 state cycles, that is, one machine cycle = 6 state cycles = 12 clock cycles.
Instruction cycle
The instruction cycle is the time required to execute an instruction, which is generally composed of several machine cycles. Different instructions require different numbers of machine cycles. For some simple single-byte instructions, in the instruction fetch cycle, the instruction is immediately decoded and executed after it is fetched into the instruction register, and no other machine cycles are required. For some more complex instructions, such as transfer instructions and multiplication instructions, two or more machine cycles are required.
Usually, instructions that contain one machine cycle are called single-cycle instructions, and instructions that contain two machine cycles are called two-cycle instructions.
1. Calculation of the initial value of the 10MS timer:
1. Crystal oscillator 12M
12MHz divided by 12 is 1MHz, which means one second = 1000000 machine cycles. 10ms = 10000 machine cycles.
65536-10000 = 55536 (d8f0)
TH0 = 0xd8, TL0 = 0xf0
2. Crystal oscillator 11.0592M
11.0592MHz divided by 12 is 921600Hz, which is 921600 machine cycles per second, 10ms=9216 machine cycles.
65536-9216=56320(dc00)
TH0=0xdc, TL0=0x00
2. Calculation of the initial value of the 50MS timer:
1. Crystal oscillator 12M
12MHz divided by 12 is 1MHz, which means one second = 1,000,000 machine cycles. 50ms = 50,000 machine cycles.
65536-50000=15536(3cb0)
TH0=0x3c, TL0=0xb0
2. Crystal oscillator 11.0592M
11.0592MHz divided by 12 is 921600Hz, which means 921600 machine cycles per second, and 50ms=46080 machine cycles.
65536-46080=19456(4c00)
TH0=0x4c, TL0=0x003. Instructions
Take the 12M crystal oscillator as an example: it can execute 1,000,000 machine cycles per second. Each overflow of T is at most 65,536 machine cycles. We should try to minimize the number of overflow interrupts (such as 50ms), so that the interference to the main program is minimized. During development, crystal oscillators of different frequencies may be replaced as needed (for example, the c51 microcontroller uses an 11.0592M crystal oscillator, which is very suitable for generating serial port clocks, while the 12M crystal oscillator is very convenient for calculating the timer time). It is more convenient to use a plug-in type.
For 12MHz 1 machine cycle 1us 12/fosc = 1us
Mode 0 13-bit timer maximum time interval = 2^13 = 8.192ms
Mode 1 16-bit timer maximum time interval = 2^16 = 65.536ms
Mode 2 8-bit timer maximum time interval = 2^8 = 0.256ms = 256 us Timing 5ms, calculate the initial value of the timer M = 2^KX*Fosc/12 12MHz Mode 0: K=13,X=5ms,Fosc=12MHz Then M = 2^13 - 5*10^(-3)*12*10^6/12= 3192 = 0x0C78 THx = 0CH,TLx = 78H,
Mode 1: K=16,X=5ms,Fosc=12MHz Then M = 2^16 - 5*10^(-3)*12*10^6/12= 60536 = 0xEC78 THx = ECH,TLx = 78H,
50ms 12MHz THx = 3CH, TLx = B0H, 10ms THx = D8H, TLx = F0H,
Method 2: Maximum time 2^8Fosc/12 = 0.256ms
How do decimal numbers come from? 6MHz One machine cycle 12/6 = 2us Timing 1ms Count initial value x (2^16-x)*2us = 1000us x = 2^16 - 500, TH, TL can be set to -50012MHz One machine cycle 12/12 = 1us 12MHz One machine cycle 12/12 = 1us Timing 50ms Count initial value x (2^16-x)*1us = 50000us x = 2^16 - 50000, TH, TL can be set to -500 Timer Counts the frequency of the internal crystal oscillator Counter
Counts the number of pulses on the external input CPU pin P3.4 (T0) P3.5 (T1) Negative jump plus one
When the crystal oscillator is 6MHz, the maximum counting frequency is 500KHz
Previous article:Flexible use of 51 single chip microcomputer timer
Next article:51 MCU Timer 2 Counting Example
Recommended ReadingLatest update time:2024-11-16 18:05
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Fundamentals and Applications of Single Chip Microcomputers (Edited by Zhang Liguang and Chen Zhongxiao)
- Single chip microcomputer control technology (Li Shuping, Wang Yan, Zhu Yu, Zhang Xiaoyun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- About Industrial Control System Development
- Everspin MRAM optimizes system energy consumption
- The impact of 5g wireless network on the development of e-sports market
- Anlu SparkRoad Development Board Review (9) Use of on-chip SDRAM, TD debugging function
- Introduction to the method of board-level online compilation and downloading of C6000 DSP code
- Working principle of lithium battery equalization circuit
- [SAMR21 new gameplay] 31. Using NVM storage
- [ATmega4809 Curiosity Nano Review] Buttons
- Have you fallen into these customer support "pitfalls"? Read the story, write a comment, grab a post and win a gift!
- About rail-to-rail op amps