How to calculate the instruction cycle of a microcontroller

Publisher:Serendipitous55Latest update time:2024-03-15 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  Instruction cycle: The time consumed by the instruction cycle to execute a certain instruction, which is equal to an integer multiple of the machine cycle. Most of the instruction cycles of the traditional 80C51 microcontroller are single-cycle instructions, that is, the instruction cycle = machine cycle, and a small number of them are double-cycle instructions. Now (as of 2012) new microcontrollers can achieve no frequency division, and try to use a single instruction cycle, that is, instruction cycle = machine cycle = clock cycle.

  How to calculate the instruction cycle of a microcontroller

  Looking at this 8051 microcontroller external data, the changing frequency of ALE and $PSEN$ here is less than one machine cycle. If you use C language to simulate this signal, there is no way to achieve a one-to-one correspondence, so you can only try to match the timing above. Same, the cycle is extended.

  The instruction cycle is uncertain because it is related to the machine cycle included in the instruction. One instruction cycle = 1 (or 2 or 3 or 4) machine cycle. Multiplication or division contains 4 machine cycles, and a single instruction only contains 1 machine cycle.

  For most 51 microcontrollers, 1 machine cycle = 12 clock cycles (or oscillation cycles)

  There are also some microcontrollers whose clock cycle and oscillation cycle are not equal. For example, 1 clock cycle = 2 oscillation cycles.

  This definition refers to the time required to execute an instruction. Usually an instruction cycle consists of several machine cycles. Different instructions require different number of machine cycles.

  For some simple single-byte instructions, in the instruction fetch cycle, after the instruction is fetched into the instruction register, it is immediately decoded and executed, and no other machine cycles are needed. For some more complex instructions, such as transfer instructions and multiplication instructions, two or more machine cycles are required. Generally, instructions that contain one machine cycle are called single-cycle instructions, and instructions that contain two machine cycles are called two-cycle instructions.

  PIC microcontroller instruction cycle calculation

  Every four clock cycles of the PIC microcontroller is an internal instruction cycle

  For example: for an 8MHz crystal oscillator, the internal command cycle is 1/(8/4) = 0.5 uS

  Example 1: 35us, 8MHz crystal oscillator, 8-bit timer, frequency division ratio 1/2, initial value E4

  Example 2: 156.25us, 32768Hz crystal oscillator, 8-bit timer, frequency division ratio 1/32, initial value FC

  Calculation method one: 35 = = (256-initial value)*frequency division*4/crystal oscillator+14/frequency division=(256-initial value)+14/2

  Calculation method two: 0.015625 = (256-initial value)*frequency division*4/crystal oscillator = (256-initial value)*32*4/32768

  Special note: the frequency division ratio 1-8 needs to be added with a 14/division ratio

  What is prescaler ratio and postscaler ratio?

  Frequency dividers are generally used in conjunction with counting units.

  The prescaler ratio takes effect before the value of the counting unit changes (if prescaler is not used, the counter increases by 1 at each rising edge, and now a prescaler with a division ratio of 1:2 is used, Then you must wait until two rising edges arrive before the counter will add 1)

  The postscaler has the same function as the prescaler, except that it takes effect after the counter value changes. Like the TMR2 postscaler, if it is not used, once the counter overflows, the flag will be set to TMR2IF immediately. However, if there is a 1:2 postscaler, it must overflow twice before it is set.

  Nowadays, the commonly used microcontroller programming software is keil. After writing the program, we can determine the time required for program execution through software debugging, and we can also see each instruction:

  How to calculate the instruction cycle of a microcontroller


Reference address:How to calculate the instruction cycle of a microcontroller

Previous article:What is 51 microcontroller? How to learn 51 microcontroller by yourself
Next article:What is AT89S51 microcontroller?

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号