Timer programming

Similar documents
CHAPTER TIMER PROGRAMMING

8051 Peripherals. On-Chip Memory Timers Serial Port Interrupts. Computer Engineering Timers

8051 Timers. Class 7 EE4380 Fall Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

The 8051 microcontroller has two 16-bit timers/counters called T0 and T1.

CPEG300 Embedded System Design. Lecture 8 Timer

Interrupts, timers and counters

Department of EIE / Pondicherry Engineering College. Timer/Counters. Department of EIE / Pondicherry Engineering College 1

Interrupts. EE4380 Fall 2001 Class 9. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

Mod-3: Interrupts,Timer operation,serial communication 1

ELEG3923 Microprocessor Ch.9 Timer Programming

Timers and interrupts

Chapter 09. Programming in Assembly

Lecture 9. Timer Operations and Programming

8051 Timers and Serial Port

8051 Microcontroller memory Organization and its Applications

Lesson-3: Counters and Timers

EE6502- MICROPROCESSOR AND MICROCONTROLLER

MICROPROCESSORS AND MICROCONTROLLERS MATERIAL. Features of 8051:

Chapter 6 PROGRAMMING THE TIMERS

80C51 Block Diagram. CSE Overview 1

ISSI. IS89C51 CMOS SINGLE CHIP 8-BIT MICROCONTROLLER with 4-Kbytes of FLASH ISSI IS89C51 NOVEMBER 1998 FEATURES GENERAL DESCRIPTION

Rev. No. History Issue Date Remark


FACULTY OF ENGINEERING LAB SHEET

8051 Microcontroller

Timer-1 can be run using the internal clock, fosc/12 (timer mode) or from any external source via pin T1 (P3.5) (Counter mode).

8051 microcontrollers

MODEL ANSWER SUBJECT- MICROCONTROLLER(12187) CLASS-EJ5E CLASS TEST-02 Q1.)Attempt any THREE of the following.

Microcontroller and Embedded Systems:

Measuring Duty Cycles with an Intel MCS-51 Microcontroller

Fig 1. Block diagram of a microcomputer

UNIT IV MICROCONTROLLER

8051 Core Specification

The University of Texas at Arlington Lecture 21_Review

8-bit Microcontroller with 8K Bytes In-System Programmable Flash AT89S52

Chapter 2. Overview of Architecture and Microcontroller-Resources

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text

CoE3DJ4 Digital Systems Design. Chapter 5: Serial Port Operation

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

MCS-51 Serial Port A T 8 9 C 5 2 1

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

Three criteria in Choosing a Microcontroller

8051 Microcontrollers

The Final Word on 8051 Microcontroller

The Timers/Counters The Serial Interface The Interrupt System Reset P0.0-P0.7 P2.0-P2.7. Port 2 Drivers. Port 2 Latch

8051 MICROCONTROLLER

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: 8051 Architecture Module No: CS/ES/5 Quadrant 1 e-text

8051 Microcontroller

SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR. ELECTRONICS & COMMUNICATION DEPARTMENT Question Bank- 1

EE 354 September 16, 2016 C Sample Programs

THE 8051 MICROCONTROLLER Simple comparison: Pentium vs. 8051

Interrupt Programming: Interrupts vs. Polling Method:

CENG-336 Introduction to Embedded Systems Development. Timers


8-bit Microcontroller with 2/4-Kbyte Flash AT89LP2052 AT89LP4052

INTEGRATED CIRCUITS DATA SHEET. P89C738; P89C739 8-bit microcontrollers Dec 15. Product specification File under Integrated Circuits, IC20

EC Microprocessor and Microcontroller

AT Bit Spread- Spectrum Microcontroller. Preliminary. Features. Description. Pin Configuration

8XC51RA RB RC Hardware Description

AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Features. Introduction. AVR 8-bit Microcontrollers APPLICATION NOTE


1. Attempt any three of the following: 15

Handshake Solutions. HT80C51 User Manual

8254 is a programmable interval timer. Which is widely used in clock driven digital circuits. with out timer there will not be proper synchronization

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Serial Port Programming in Assembly Module No: CS/ES/12 Quadrant 1 e-text

2. Write an 8051 program to generate a square wave of 25 khz at pin P2.3 using XTAL = 12 MHz. Solution:

Lecture 10. Serial Communication

Using Timers of Microchip PIC18F Microcontrollers

Serial I-O for Dinesh K. Sharma Electrical Engineering Department I.I.T. Bombay Mumbai (version 14/10/07)

TW8816 Built-in MCU. Application Notes

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

Q.1. A) Attempt any THREE of the following:

UNIT 5. Microcontrollers. Syllabus

Microcontrollers. Fig. 1 gives a comparison of a microprocessor system and a microcontroller system.

IA8044/IA8344. SDLC Communications Controller. Data Sheet. SDLC Communications Controller January 9, 2015

Topic 11: Timer ISMAIL ARIFFIN FKE UTM SKUDAI JOHOR

8051 Serial Communication

8051 Microcontroller. Ali Ziya Alkar 1

P89V52X2. 1. General description. 2. Features. 8-bit 80C51 low power 8 kb flash microcontroller with 256 B RAM, 192 B data EEPROM

Question Bank Microprocessor and Microcontroller

VRS540-4kB Flash, 128B RAM, 25~40MHz, 8-Bit MCU

8-Bit Microcontroller with 8K Bytes Flash AT89S8252. Features. Description

Emulating an asynchronous serial interface (USART) via software routines

MPC89E515A. 8-bit micro-controller

Chapter C2051 Architecture and Serial Communication Link

Embedded Piano Interfaced with LCD

INTERRUPTS PROGRAMMING

CS 320. Computer Architecture Core Architecture

I/O Systems (3): Clocks and Timers. CSE 2431: Introduction to Operating Systems

R8032S RDC RDC. RDC RISC DSP Controller. 8-Bit RISC MCU IP Specification VERSION: 1.1 R8032S

Embedded Controller Programming II. I/O Device Programming in C Part 1: Input and Interrupts

T.Y. Diploma : Sem. V [EJ/EN/ET/EX/DE/IS/IC/IE/EV/MU] Micro-controller

C51 Family. C51 Family Programmer s Guide and Instruction Set. Summary

8XC151SA and 8XC151SB Hardware Description

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

MAHALAKSHMI ENGINEERING COLLEGE TIRUCHIRAPALLI

WINTER 14 EXAMINATION

2. (2 pts) If an external clock is used, which pin of the 8051 should it be connected to?

THE 8051 MICROCONTROLLER

VRS550-8kB Flash, 256B RAM, 25~40MHz, 8-Bit MCU VRS560-16kB Flash, 256B RAM, 40MHz, 8-Bit MCU

Transcription:

5.8051 Timer programming In this tutorial, we are going to discuss the Timer module of 8051. First, we will see what are timers, their working and later we will configure the 8051 timers to generate the delay of 100ms and 500ms respectively. At the end, we will see how to use the ExploreEmdedded Timer library. Contents 1 8051 Timer Module 2 Timer Basics 3 Timer Registers 4 Timer Calculation 5 Timer Mode1 5.1 Timer Calculation for 50ms delay 5.2 Polling Method 5.3 Interrupt Method 6 Timer Mode2 6.1 Timer Calculation for 250µs delay 7 Downloads 8051 Timer Module 8051 has two indepenndent timer which can be used as timer(to generate delays)/counters(count external events). Timer 1 is also used for generating baud rate in serial communication, which we will discuss in the next tutorial Below table provides the details of the 8051 Timers. Timer Size Control Register Count Register Min Delay Max Delay TIMER0 16-bit TMOD,TCON TH0,TL0 1.085µs 71.107ms TIMER1 16-bit TMOD,TCON TH1,TL1 1.085µs 71.107ms TIMER2(8052 only) 16-bit T2CON RCAP2H,RCAP2L 1.085µs 71.107ms Timer Basics As the name suggests these are used to measure the time or generate the accurate time delay. The microcontroller can also generate/measure the required time delays by running loops, but the timer/counter relieves the CPU from that redundant and repetitive task, allowing it to allocate maximum processing time for other tasks. The timer is nothing but a simple binary counter that can be configured to count clock pulses(internal/external). Once it reaches the Max value, it will roll back to zero setting up an OverFlow flag and generates the interrupt if enabled.

The Timer 0 is 16 bit wide as shown. This can be accessed as 2 eight bit registers TL0 and TL1. Same applies to Timer 1. The 8051 timer and counter are the same units, but in this tutorial, we will discuss only the timer unit to simplify the discussion. Fig 1, shows the basic 8051 timer unit. The registers TCON and TMOD affect the timer operation. The clock frequency is divided by 12 and used by the timer unit. Thus if a 11.0592MHz external crystal is used, the timer uses a frequency of 921KHz. Thus timer increments every (1/921Khz) = 1.085? seconds. The C/? = 0 bit of TMOD register selects operation of Timer/counter unit as timer. The TR bit of TCON register is used to start the timer.

Timer Registers TMOD Timer1 Timer 0 7 6 5 4 3 2 1 0 Gate C/T M1 M0 Gate C/T M1 M0 Gate Control 0 = Timer enabled 1 = Timer enabled if INTx is high C/T:Counter or Timer Selector 0 = Internal count source (clock/12) 1 = External count source T0/T1(P3.4/P3.5) pin. M1-M0:Mode Control 00-Mode 0, 13 bit count mode 01-Mode 1, 16 bit count mode 10-Mode 2, Auto reload mode 11-Mode 3, Split Timer mode TCON 7 6 5 4 3 2 1 0 TF1 TR1 TF0 TR0 TRx: Timer x run control 0 = Timer not running 1 = Timer running TFx: Timer x OverFlow flag 0 = Timer has not overflowed/rolled over 1 = Timer has overflowed/rolled over Timer Calculation 8051 Oscillator frequency is divided by 12 and then fed to the controller, Time to increment the Timer count by one(timer tick) can be determined as below. tick = (1/(Fosc/12) $$tick = 12/Fosc$$ For Fosc == 11.0592Mhz, the tick time will be tick = 12/11.0592M = 1.085069444us = 1.085us Now the Timer value for the required delay can be calculated as below. Delay = TimerCount * tick Count = (Delay/tick) RegValue = TimerMax- Count RegValue = TimerMax-(Delay/tick) = TimerMax - (Delay/1.085us) $$RegValue = TimerMax-((Delay/1.085) * 10^6)$$

Timer Mode1 The timer in Mode-1 can be used as a 16-bit timer to count from 0000 to FFFFH thus allowing to generate a wide range of delay. The timer value for the required delay needs to be loaded into Timer Count registers TH & TL. After loading the values to the register, the timers must be started. Now the Timer starts counting up and once it reaches the max value(0xffff), it rolls back to zero setting the overflow flag. At this point, the timer values must be reloaded and the overflow flag should also be cleared. Timer Calculation for 50ms delay Fosc = 11.0592Mhz Delay = 50ms $$RegValue = TimerMax-((Delay/1.085) * 10^6)$$ RegValue = 65536 - (50ms/1.085)*10^6 = 65536-46082 = 19453 = 0x4BFD Polling Method Interrupt Method Timer Mode2 The timer in Mode-2 can be used as an 8-bit timer to count from 00 to FFH. The timer value for the required delay needs to be loaded into Timer Count registers TH(which is copied to TL). After loading the values to the register, the timers must be started. Now the Timer starts incrementing TL and once it reaches the max value(0xff), it rolls back to zero setting the overflow flag and reloads the value from TH.

Timer Calculation for 250µs delay Fosc = 11.0592Mhz Delay = 250µs $$RegValue = TimerMax-((Delay/1.085) * 10^6)$$ RegValue = 256 - (250µs/1.085)*10^6 = 256-230 = 26 = 0x1A Downloads Download the sample code and design files from this link. Would like to have your feedback and suggestions here; Please enable JavaScript to view the comments powered by Disqus.