Understanding Timing and Instruction Execution in the 8051 Microcontroller, Lecture notes of Microcontrollers

An overview of the timing and instruction set of the 8051 microcontroller, explaining how the crystal oscillator is used to synchronize operations and calculate instruction execution rates. It also discusses the variation in instruction execution times and the importance of timers in time-critical applications.

Typology: Lecture notes

2011/2012

Uploaded on 11/10/2012

taariq
taariq 🇵🇰

4.4

(16)

61 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Microcontroller Interfacing Lab
pf3

Partial preview of the text

Download Understanding Timing and Instruction Execution in the 8051 Microcontroller and more Lecture notes Microcontrollers in PDF only on Docsity!

Microcontroller Interfacing Lab

Chapter 6 - Instruction Set, Timing, and Low-Level Info

In order to understand --and better make use of--the 8051, it is necessary to understand some underlying information concerning timing.

The 8051 operates based on an external crystal. This is an electrical device which, when energy is applied, emits pulses at a fixed frequency. One can find crystals of virtually any frequency depending on the application requirements. When using an 8051, the most common crystal frequencies are 12 megahertz and 11.059 megahertz--with 11.059 being much more common. Why would anyone pick such an odd-ball frequency? There’s a real reason for it--it has to do with generating baud rates and we’ll talk more about it in the Serial Communication chapter. For the remainder of this discussion we’ll assume that we’re using an 11.059Mhz crystal.

Microcontrollers (and many other electrical systems) use crystals to syncrhronize operations. The 8051 uses the crystal for precisely that: to synchronize it’s operation. Effectively, the 8051 operates using what are called "machine cycles." A single machine cycle is the minimum amount of time in which a single 8051 instruction can be executed. although many instruc tions take multiple cycles.

A cycle is, in reality, 12 pulses of the crystal. That is to say, if an instruction takes one machine cycle to execute, it will take 12 pulses of the crystal to execute. Since we know the crystal is pulsing 11,059,000 times per second and that one machine cycle is 12 pulses, we can calculate how many instruction cycles the 8051 can execute per second:

11,059,000 / 12 = 921, This means that the 8051 can execute 921,583 single -cycle instructions per second. Since a large number of 8051 instructions are single -cycle instructions it is often considered that the 8051 can execute roughly 1 million instructions per second, although in reality it is less--and, depending on the instructions being used, an estimate of about 600,000 instructions per second is more realistic.

For example, if you are using exclusively 2-cycle instructions you would find that the 8051 would execute 460,791 instructions per second. The 8051 also has two really slow instructions that require a full 4 cycles to execute--if you were to execute nothing but those instructions you’d find performance to be about 230,395 instructions per second.

It is again important to emphasize that not all instructions execute in the same amount of time. The fastest instructions require one machine cycle (12 crystal pulses), many others require two machine cycles (24 crystal pulses), and the two very slow math operations require four machine cycles (48 crystal pulses).