1. Timing: MCU timing refers to the time sequence of control signals that should be issued when the MCU executes instructions. The temporal relationship between these control signals is the CPU timing. 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.
Extended reading: What is the timing of a microcontroller?
2. Clock cycle, machine cycle and instruction cycle
1. Clock cycle: also known as oscillation cycle. Refers to the oscillation source cycle that provides timing signals for the microcontroller. It is the smallest timing unit.
The higher the frequency of the oscillation source, the faster the microcontroller operates.
The clock cycle is divided into two beats, P1 and P2. In the first half of each clock cycle, the P1 signal is valid, and the CPU usually completes arithmetic and logical operations at this time; in the second half of each clock cycle, the P2 signal is valid, and data between internal registers generally occurs in this state.
2. Machine cycle: It is defined as the time required to achieve a specific function. Machine cycles are named according to their functions, such as instruction fetch machine cycle, etc.
The machine cycle time of MCS-51 is constant, which is 12 crystal oscillator cycles or 6 state cycles. It is divided into S1P1, SIP2; S2P1, S2P2; etc.
3. Instruction cycle: the time to execute one instruction.
According to the execution time of instructions, it can be divided into: single cycle, double cycle and four cycles (there are only two instructions, multiplication and division).
Clock cycle, machine cycle and instruction cycle are all timing units of single-chip microcomputer. Machine cycle is the basic timing unit for single-chip microcomputer to calculate other time values (such as baud rate, timer timing, etc.).
If the external crystal oscillator of MCS-51 is 12MHz, then:
Clock period = = =0.167us;
Machine cycle = = =1us;
Instruction cycle = (1~4) = (1~4) = 1~4us.
Example: If the microcontroller clock frequency is 12MHz, calculate the timer initial value required for a 2ms timing. (Assume the timer works in mode 1, that is, the modulus is )
Analysis: MCS-51 has two 8-bit counters. Each time a machine cycle comes, the counter increases by 1. When the counter increases from 0FFFFH to 0000H, the timer automatically generates an overflow request. Therefore, the maximum timing time of mode 1 is Tmax= ×T0, where T0 is the time of a machine cycle. Since the frequency of the clock cycle is 12MHz, here .
Tmax= ×T0=65536×1us=65.536ms.
Now we need to generate a 2ms timing time, so we must put a certain initial value x in the counter in advance, so that:
(216-x)T0=2ms.
untie:
( -x)T0=2ms=2×10-3s
X= - =216-2×103=63536=F830H.
Note:
How to quickly convert decimal numbers, binary numbers, and hexadecimal numbers
1. If the decimal number is less than 256, divide this number by 16 to get the quotient and remainder. If the decimal quotient is written in binary form, it is the upper 4 bits of the binary. If the decimal remainder is written in binary form, it is the lower 4 bits of the binary. Together, it is the converted 8-bit binary number. Similarly, if the decimal quotient is written in hexadecimal form, it is the hexadecimal representation of the upper 4 bits of the binary, and if the decimal remainder is written in hexadecimal form, it is the hexadecimal representation of the lower 4 bits of the binary, and together they are the converted hexadecimal representation.
2. If the decimal number is greater than 256 and less than 65536, divide this number by 256 to get the quotient and remainder, and then divide the quotient and remainder by 16 respectively. After the quotient is divided by 16, the quotient and remainder are obtained again. This quotient and remainder are in decimal form. When written in hexadecimal, they are the hexadecimal form of the upper 4 bits of the upper 8 bits and the lower 4 bits of the upper 8 bits. Dividing the remainder by 16 also gives the quotient and remainder. This quotient and remainder are also in decimal form. When written in hexadecimal, they are the hexadecimal form of the upper 4 bits of the lower 8 bits and the lower 4 bits of the lower 8 bits.
Example: Find the binary and hexadecimal versions of the following decimal numbers.
(1)212; (2)65365
Solution: (1)
212/16=13……4
If 13 is written as D in hexadecimal, and 4 is written as 4 in hexadecimal, then the hexadecimal number is:
212=D4(H)
If 13 is written as binary, it is 1101, and 4 is written as binary, it is 0100, then converted into binary:
212=11010100(B).
(2)
65365/256=255……85
(The quotient divided by 16 is the high 8 bits, and the remainder divided by 16 is the low 8 bits)
255/16=15……15
(The quotient is the high 4 bits of the high 8 bits, and the remainder is the low 4 bits of the high 8 bits)
Write the quotient 15 in hexadecimal as F, and write the remainder 15 in hexadecimal as F, so the hexadecimal of the upper 8 bits is: FFH;
85/16=5……5
(The quotient is the high 4 bits of the low 8 bits, and the remainder is the low 4 bits of the low 8 bits)
The quotient 5 is written as hexadecimal 5, and the remainder 5 is written as hexadecimal 5, so the hexadecimal of the lower 8 bits is: 55F.
The high 8 bits and the low 8 bits together are the hexadecimal form of this decimal number:
65365=FF55(H).
Converted to binary: 65365=FF55(H)=111111111010101010(B).
Previous article:Design of a practical eight-channel level measuring instrument based on 89C52 single chip microcomputer
Next article:How to use 51 single chip microcomputer related software and experimental board
Recommended ReadingLatest update time:2024-11-16 14:40
- Popular Resources
- Popular amplifiers
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
- More images of the sensor suite
- Modelsim 10.5b
- How to set up the serial port of msp430fr5739
- Arduino remote control kit solves all your problems
- Configuration and use of TMS320F28379D SCID SCIB
- How to set I2C1 on GD32E230C development board?
- EEWORLD University Hall----Live Replay: Interpretation of ON Semiconductor Power Solutions, Focusing on Server Power Supplies and Photovoltaic Inverters
- SD card FAT16 reading and writing program based on MSP430 learning and development system
- How to measure the phase difference between two signals
- Prediction: 3 diodes are called "an ultra-large current DC reverse connection protection circuit"