# Machine Cycle and Instruction Cycle in 8051 Microcontroller – Microcontroller and Its Applications

Articles, Blog 8 Comments

Do subscribe to Ekeeda channel and press bell icon to get updates about latest Engineering HSC and IIT-JEE Mains and Advanced videos.Hello Friends, In this video we are going to study that what is a T State what is a machine cycle and what is an instruction cycle related to the 8051 microcontroller so let us start with the topic. The 8051 microcontroller it is a programmable device programmable device means that we can write programs and for different types of applications in the 8051 now what are programs they are a set of instructions and these instructions are written in the memory of the microcontroller and the microcontroller execute these instructions to get the result okay now when these instructions they are written in the program memory so the microcontroller what the steps what are the steps which the microcontroller performs first it is going to fetch the instruction then it is going to decode that instruction that what that instruction means and then it is going to execute that instruction so the whole working of the microcontroller we can say it’ll includes first fetching of the instruction second decoding of the instruction and third is execution of the instruction so the first term that is the instruction cycle it is that time taken to execute the complete instruction by the microcontroller is called the instruction cycle so we can write the definition of instruction cycle as the time required for completing the execution of an instruction now this time can be like two five microseconds one microsecond or point one microsecond so it can’t be anything in the third time okay so the complete time taken is called the instruction cycle now this instruction cycle it consists of many machine cycles because when an instruction is executed then suppose that instruction involves that if you have to read out data from some memory location or from an input of football or you have to write the data into the memory or to an input/output port okay or if you have to add some numbers or subtract some numbers so different types in the execution of an instruction it involves various steps so we can say that instruction cycle it is divided into various machine cycles okay so machine cycle means like we have in microcontroller we have opcode fetch machine cycle memory read machine cycle memory light machine cycle then input/output read machine cycle and input/output write machine cycle so because all these are when an instruction is executed it may involve read operation or write operation or fetching operation can be involved so each instruction cycle is divided into various machine cycle and we can say that you so machine side if we define what is a machine cycle then machine cycle is defined as 12 or selector periods in every controller in every microcontroller we have an oscillator which provides the clock frequency to all the internal circuitry of the controller okay so all the operations that is read and write operations or any of the external operations like input of to read or input/output write operations they are related with the oscillator frequency that is clock frequency so we can say that machine cycle it is defined as twelve oscillator clock periods okay so 12 hours later clock period is equal to one machine cycle now in a machine cycle there are six states and each state it lasts for two oscillator clock periods so if we divide the machine cycle we will have six states in that and each state is equal to two oscillator clock periods so total we will have twelve later clock periods now machine cycle they can be of various types like opcode fetch then we can have memory read or memory write and we can have input/output reads for input/output right okay so we can say that instruction cycle it consists of one or for machine cycle what we can say that when an instruction is executed the end instruction execution it will consist of one to four machine cycles okay so machine cycle it is a part of instruction cycle now in machine cycle it consists of two an oscillator clock period so there is another town called P States now this T state it is defined as one clock period so T state is defined as one subdivision of the operation performed in one clock period means like instruction cycle it consists of various machine cycle now machine cycle consists of various T states so in that machine cycle suppose in one machine cycle some operation is performed in one clock period so that is called the T State what we can say that one clock period is equal to 1 T State ok so in place of clock period also we can use the T stage so as I’ve said that machine cycle it is each machine cycle it has six states and each state consists of two oscillator clock periods so we can say that each state of the machine cycle it will consist of two three states okay so if we talk about this is our instruction cycle in instruction cycle we will have one two four machine cycles and in machine cycle we can have two two twelve T States okay so smallest division is T state then comes the Machine second and then comes the instruction cycle so the complete execution of the instruction by the microcontroller it consists of three parts so it is divided into three parts first part is the instruction cycle that is time required to complete the execution of the complete instruction then comes machine cycle in which instruction cycle it is divided into Vegas machine cycle like if the microprocessor it is first fetching the instruction they it is decoding and then it is executing so at the time of fetching we will have a code fetch machine cycle suppose it is performing memory read operation so we will involve the memory read machine cycle and suppose that it is writing the memory then we will have the memory write machine cycle so instruction cycle it will consist of various machine cycles now in every machine cycle like an opcode fetch machine cycle suppose it is completing in four clock periods so it means that 40 states are involved memory read memory right it is involving 3 T States so total T States what we require is 20 States okay or 10 T stage so this is the definition of all the three terms instruction cycle machine cycle and the three states now let’s take an example to more clearly understand the meaning of these three terms you so in this example we are given that 8:05 on microcontroller is there which is operated at 12 megahertz oscillator frequency and we have to find the execution time for the following instructions means how much time is taken to execute these instruction first instruction we have is add a comma 45 edge okay so we have to add the contents of the accumulator and the contents of this memory location now this the number of machine cycles involved in this instruction is 1 now oscillator clock frequency is given to us that is 12 megahertz if we calculate the clock period so clock period is equals to 1 by clock frequency that is reciprocal of the frequency so we will have 1 by 12 megahertz or we can say it is equal to 0.8 3 3 3 micro seconds or if we say that time taken okay because in each machine cycle we have the 12 T states are there so 12 into 0.833 so we will get 1 microseconds now this instruction it will require one machine cycle only that is opcode fetch because opcode when we are fetching this OP code we directly get the address we what we will get the data from this memory location and second data is there in the accumulator and result will be stored in the accumulator itself so here 1 machine cycle is involved so time taken to execute this instruction will be 1 microseconds next instruction we have is su b b a comma 55 h this is the 8 bit of data which is available in the instruction we have to subtract it from the accumulator along with the carry now here the number of machine cycle is 2 for 1 machine cycle we require 1 microsecond so for 2 machine cycle we will require 2 micro seconds so 2 micro second is the total time taken to execute this instruction next instruction we have is move DPT yard and a 16-bit number this also required to machine cycles so 2 machine cycle equals to 2 micro seconds for instruction we have is multiply a and B this require four machine cycles so for machine cycle is equal to four microseconds so if you want to calculate the total time taken by the total time taken to execute the instruction if the clock frequency is given to us first we will calculate the clock period so one clock period is equal to 1 T States we will calculate that how many machine cycles are involved in the instruction okay number of machine cycles and how many means these states are involved in that machine cycle so number of T States will be equal to the clock period okay so in this way we can calculate the time taken to execute any of the instruction if we know the T state value or if we know the clock period and if we know the Machine cycles involved in that instruction so in this video we studied that what is called a T State instruction cycle a machine cycle in 8:05 one microcontroller so I hope that this topic is clear to you thank you

Aman KumarPost authorWhy the oscillator period is 12 only not anything else.

IulianPost authorat minute 14, number of machine cycles for example 2 is 2..she just writes that without any explanation..not cool

Vaibhav DubeyPost authorNot much clear explanation of 8051

Nikhil hingePost authorHow to identify no of machine cycle!

Manasi MakotePost authorHow to find machine cycles

EkeedaPost authorHello Friends,

Watch Complete Video Series of Subject Microcontroller and Its Applications only on Ekeeda Application.

Use Coupon Code "NEWUSER" and access any one Subject free for 3 days!

Download Ekeeda Application and take advantage of this offer.

Android:- https://play.google.com/store/apps/details?id=student.ekeeda.com.ekeeda_student&hl=en

iOS:- https://itunes.apple.com/tt/app/ekeeda/id1442131224

Dave JenilPost author0.8333 us x 12 = 10us

Not a clear concept of the teacher

Sharone RexPost authorWorst explanation