Time Delay in AVR Microcontroller Last Updated : 21 Dec, 2020 Comments Improve Suggest changes Like Article Like Report In this article, we will see how to create delays for the AVR. Also, we will discuss the instruction pipeline. Delay Calculation for AVR : In Assembly Language instructions, to create a time delay one must consider two important factors. The crystal frequency - The frequency of the crystal oscillator connected to XTAL1 and XTAL2 is one factor for calculating the time delay. The duration of the clock period for the instruction cycle is a function of this crystal frequency. The AVR design - AVR microprocessors are able to execute an instruction in one cycle. There are three ways of doing this. Use Harvard architecture to get the maximum amount of code and data into the CPU. Use RISC architecture features such as fixed-size instructions. Use pipelining to overlap fetching and execution of instructions. Pipelining : In the early microprocessors, the CPU could either fetch or execute at a given time. In other words, the CPU had to fetch an instruction from the memory, then execute it then again fetch the next instruction, execute it, and so on. Pipelining allows the CPU to fetch and execute the given instruction at the same time. We can use the pipeline to speed up execution of instructions. In pipelines, the process of execution is split up into smaller steps that are all executed in parallel. In the execution of instructions, we must make sure that the sequence of instructions is kept intact and that there is no different execution. Instruction cycle time for the AVR : It takes a certain amount of time for the CPU to execute an instruction. This time is referred to as machine cycles. All the instructions in the AVR are either 2-byte or 4-byte and hence most of the instructions take no more than 2 machine cycles to execute (some instructions may take up 3 to 4 machine cycles to execute). In the AVR family, the duration of the machine cycle depends upon the frequency of the oscillator connected to the AVR system. In the AVR, one machine cycle consists of one oscillator period, which means that with each oscillator clock, one machine cycle passes. Therefore, to calculate the machine cycle for the AVR, we take the inverse of the crystal frequency. Example-1 : For the given crystal frequencies, calculate the period of the instruction cycles. a) 8 MHz b) 16 MHz Solution : a) instruction cycle = 1/ 8 MHz = 0.125 us (microsecond) b) instruction cycle = 1/ 16 MHz = 0.0625 us Instruction cycles required by different instructions (considering 1 MHz as the crystal frequency) : InstructionInstruction cyclesTime to executeLDI11 usDEC11 usOUT11 usADD11 usNOP11 usJMP33 usCALL44 usBRNE2/12 us if taken, 1 us if it fails Example-2 : Find the delay in us of the code snippet below if the crystal frequency is 10 MHz. Instruction Cycles DELAY : LDI COUNT, 0XFF 0 Again : NOP 1 NOP 1 NOP 1 DEC COUNT 1 BRNE AGAIN 2/1 RET 4 Solution : Time Delay = [1 +(( 1+ 1+ 1+ 1 + 2 ) x 255) + 4 ] x 0.1 us = 153.5 us Comment More infoAdvertise with us K kunalsg18elec Follow Improve Article Tags : Electronics Engineering Computer Organization and Architecture Similar Reads Electronic Devices & ComponentsAvalanche PhotodiodeAn Avalanche photodiode (APD) is a highly sensitive semiconductor detector that uses the photoelectric effect to convert optical signals into electrical signals. In case of conventional photodiodes, PIN photodiodes operate in a linear mode and the output current is very small and also has limited ga 4 min read PIN DiodeA PIN diode, abbreviated as a Positive-Intrinsic-Negative diode, is a semiconductor tool that belongs to the diode family. Power electronics play an essential role in converting and controlling electrical strength in numerous packages, ranging from electricity components and motor drives to renewabl 15+ min read Schottky DiodeThe Schottky diode is popularly known as a hot-carrier diode, low-voltage diode, or Schottky barrier diode. It is a type of diode formed by the junction of a semiconductor with a metal. We know that in a PN junction diode, p-type and n-type semiconductors are joined collectively to form a PN junctio 13 min read Solar CellA Solar Cell is a device that converts light energy into electrical energy using the photovoltaic effect. A solar cell is also known as a photovoltaic cell(PV cell). A solar cell is made up of two types of semiconductors, one is called the p-type silicon layer and the n-type silicon layer. So Solar 8 min read Power Semiconductor DevicesIn electronic components, Power Semiconductor Devices are electronic devices that need an external power source to operate actively. Materials used to make semiconductor devices are neither excellent insulators nor conductors. They mainly manipulate, amplify, switch, or control the flow of electric 15+ min read Digital Circuits & LogicDigital Electronics and Logic Design TutorialsDigital Electronics and Logic Design are key concepts in both electronics and computer science. Digital systems are at the core of everything from basic devices like calculators to advanced computing systems. Digital systems use binary numbers (0s and 1s) to represent and process information.Logic g 4 min read CMOS Logic GateThe logic gates are the basic building blocks of all digital circuits and computers. These logic gates are implemented using transistors called MOSFETs. A MOSFET transistor is a voltage-controlled switch. The MOSFET acts as a switch and turns on or off depending on whether the voltage on it is eithe 4 min read CMOS InverterThe CMOS inverter is crucial in electronics, employed in memory chips and microprocessors among others. It generates complementary outputs whenever there are input signals through it. These inverters allow flexibility among circuit designers because they can be classified into many categories depend 10 min read Difference Between Static CMOS and Dynamic CMOSStatic and Dynamic CMOS are the two types of CMOS. The static CMOS is a combinational circuit. It made up with pull-up network and pull-down network functions. On the other side, the dynamic CMOS is a digital logic that has a single clock signal to execute the pre charge and evaluation operation. In 6 min read What is CMOS FABRICATION(P-WELL PROCESS)?CMOS means Complementary Metal Oxide Semiconductor. It is used to fabricate digital circuits and IC chips. It is a combination of NMOS (N-type Metal Oxide Semiconductor) and PMOS (P-type Metal Oxide Semiconductor) transistor pairs that are symmetrical. CMOS fabrication can be carried out in many way 3 min read Analog & Circuit BehaviorRectifierA rectifier is an electronic component that converts alternating current (AC) into direct current (DC), ensuring a unidirectional flow of electric charge. As we know, electricity reaches our homes from power grids in the form of AC, but most commonly used electric appliances, such as mobile phones, 10 min read Diode As a SwitchThe diode is an electronic instrument of great importance, one of them being using the diode as a switch. It is interesting to note that under certain conditions we can use a diode as a switch. In this article, we will study what is an electrical switch and how it differs from a mechanical switch. W 11 min read Forward BiasForward Bias is a term commonly used in semiconductor electronics, particularly concerning diodes and transistors. A diode is considered to be in forward bias when its p-side is connected to the positive side of a power supply and its n-side to the negative side. In the case of an NPN transistor, th 9 min read Schmitt TriggerWe use Schmitt Triggers in digital electronics. It is used for rejecting the noise from the input signals by using the hysteresis curve. To provide accurate and more stable results, it uses two threshold voltages i.e., upper threshold voltage (VUT) and lower threshold voltage (VLT). It is mainly use 11 min read Integrated CircuitsIntegrated circuits (ICs) also called microelectric chips are used to create a device that can perform certain electrical operations such as signal amplification which is called a transistor from the combination of words of the transfer and resistor. Solid-state electronics is the name given to the 8 min read Solid-State DevicesSolid-State LightingIn this article, we will study solid-state lighting, which is the use of solid-state materials as a source of illumination, usually light-emitting diodes (LEDs). Solid-state lighting, as opposed to conventional incandescent or fluorescent lighting, which depends on thermal processes, produces light 7 min read Avalanche PhotodiodeAn Avalanche photodiode (APD) is a highly sensitive semiconductor detector that uses the photoelectric effect to convert optical signals into electrical signals. In case of conventional photodiodes, PIN photodiodes operate in a linear mode and the output current is very small and also has limited ga 4 min read Avalanche PhotodiodeAn Avalanche photodiode (APD) is a highly sensitive semiconductor detector that uses the photoelectric effect to convert optical signals into electrical signals. In case of conventional photodiodes, PIN photodiodes operate in a linear mode and the output current is very small and also has limited ga 4 min read MOSFET CharacteristicsMOSFETs (Metal-Oxide-Semiconductor Field-Effect Transistors). It is a transistor that controls the flow of electric current in the circuit. The MOSFETs have 3 main terminals: the Gate (G), the Drain (D), and the Source (S). They are popular because they work efficiently. MOSFETs are able to handle h 6 min read Junction Field Effect Transistor or JFETIn electronics, the junction field effect transistor is a fundamental component, operating on the principle of electric field control. It is a three-terminal device, and it consists of the gate, drain, and source terminals. There are two types of JFETs: N-channel JFET and P-channel JFET. The N chann 11 min read Communication SystemsGetting Started with Communications EngineeringCommunication engineering forms an essential part of our daily life. Therefore, it becomes necessary to understand the basics of Communication engineering in different domains. In this article, we will study what is communication engineering and which components are used in communication engineering 9 min read Difference between Amplitude Modulation and Frequency ModulationAmplitude Modulation (AM) and Frequency Modulation (FM) are two fundamental techniques used in analog communication systems to transmit information, such as audio signals, over radio waves. While both serve the purpose of modulating a carrier signal to encode data, they differ in their modulation te 5 min read Difference between Pulse Code Modulation (PCM) and Delta Modulation (DM)PCM stands for Pulse Code Modulation and DM stands for Delta Modulation. PCM is basically used for reworking analog to digital signals and DM is a conversion technique between analog and digital signals. In this article, we will discuss these two topics and also see the differences between these PCM 6 min read Frequency Division and Time division multiplexingMultiplexing is used in cases where the signals of lower bandwidth and the transmitting media is having higher bandwidth. In this case, the possibility of sending a number of signals is more. In this, the signals are combined into one and are sent over a link that has greater bandwidth of media than 4 min read Signal ProcessingSignals and SystemsElectronics and communication engineering deals with signal processing and signal transmission. This field of engineering is known as signals and systems. In this article, we will introduce the readers to signals and systems by defining all the necessary ââterms and discussing the components that ma 10 min read Fourier Transform in Circuit AnalysisIn this article, we will study about the Fourier transform analysis or Fourier Transform in Circuit Analysis. The Fourier transform is basically a mathematical operation that decomposes a signal into its constituent frequency components. In simple words, it converts a signal from the time domain to 10 min read Laplace Transform in Circuit AnalysisThe analysis of circuit analysis is a fundamental discipline in electrical engineering. It enables engineers to design and construct electrical circuits for several purposes. The Laplace transform is one of the powerful mathematical tools that play a vital role in circuit analysis. The Laplace trans 7 min read Properties of z-TransformsPrerequisite: What is Z-transform? A z-Transform is important for analyzing discrete signals and systems. In this article, we will see the properties of z-Transforms. These properties are helpful in computing transforms of complex time-domain discrete signals. 1. Linearity: If we have two sequences 4 min read What is Digital Signal Processing (DSP)?Digital Signal Processing (DSP) is a branch of engineering and applied mathematics that deals with the processing and analysis of digital signals. A digital signal is a discrete-time signal, that is represented by a sequence of numbers sampled at regular intervals. DSP involves various algorithms, t 15 min read Like