CoE3DJ4 Digital Systems Design Chapter 4: Timer operation.

Slides:



Advertisements
Similar presentations
The 8051 Microcontroller and Embedded Systems
Advertisements

Dr A Sahu Dept of Comp Sc & Engg. IIT Guwahati I/O + Timer 8155 I/O + Timer 8255 I/O 8255 I/O 8253/54 Timer 8253/54 Timer 2 Port (A,B), No Bidirectional.
4-1 Timers Timers can be used for  timing  event counting  pulse width measurement  pulse generation  frequency multiplication There are 8 Timers.
8051 Core Specification.
CSC Timers Since this is a microcontroller it mainly finds itself in embedded devices Quite often embedded devices need to synchronize events The.
5-1 Timer/Counters In many microprocessor systems we need to:  count logic pulses  measure the frequency of signals  measure the period of pulses 
Chapter 6 Interrupts (I. Scott Mackenzie).
Embedded Systems UNIT 3. Pin Details of 8051 Pins 1-8: Port 1 Each of these pins can be configured as an input or an output. Pin 9: The positive voltage.
1.  8051 Timers “count up,” incrementing the Timer’s respective “count register” each time there is a triggering clock pulse. 2  When the “count register”
The 8051 Microcontroller and Embedded Systems
INTERRUPTS PROGRAMMING
Lecture 9 Timer Operations and Programming. 2  Introduction  Summary of timers  Timer programming sequence  Summary of timer SFRs  Timer 0: 8-bit.
UNIT V INTERFACING MICROCONTROLLER
Chapter Timer Programming in Assembly and C
NATIONAL TAIWAN OCEAN UNIVERSITY 國立台灣海洋大學 2002/4/8 Microcomputers and Microprocessors Chapter 9 COUNTER/TIMER PROGRAMMING IN THE 8051.
CHAPTER TIMER PROGRAMMING Timers The 8051 has two timers/counters, they can be used as ◦ Timers to generate a time delay ◦ Event counters.
8051 timer/counter.
8051 timer/counter.
ENEE 440 Chapter Timer 8254 Register Select The 8254 timer is actually 3 timers in one. It is an upgraded version of the 8253 timer which was.
1 Chapter 4 Timer Operation (I. Scott MacKenzie).
Chapter 9 Counter/Timer Programming in the 8051
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
8253 TIMER. Engr 4862 Microprocessors 8253 / 8254 Timer A.k.a. PIT (programmable Interval Timer), used to bring down the frequency to the desired level.
8254 Counter/Timer Counter Each of the three counter has 3 pins associated CLK: input clock frequency- 8 MHz OUT GATE: Enable (high) or disable.
Chapter 4 TIMER OPERATION
Timers The timers of the PIC16C7X microcontroller can be briefly described in only one sentence. There are three completely independent timers/counters.
Lecture Set 9 MCS-51 Serial Port.
Timers /Counters Programming  The 8051 has 2 timers/counters: ○ timer/counter 0 ○ timer/counter 1 They can be used as 1. The timer is used as a time.
1. Registers Used in Timer/Counter  TH0, TL0, TH1, TL1  TMOD (Timer mode register)  TCON (Timer control register) 2.
8051 Timer/Counter Lec note 7.
8051 Micro controller. Architecture of 8051 Features of 8051.
MCS51 - lecture 3. Lecture 3 2/30 Timers/counters MCS51.
8254 Timer.
Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,
Jump, Loop, and Call Instructions
The Silicon Laboratories C8051F020
8051 Aula 02 Prof Afonso Ferreira Miguel. Microcontrolador 8051 (MCS-51)  Timers do MCS51 Two 16-bit Counter/Timers: Two 16-bit Counter/Timers: Up counters,
Lecture 41 CSE 341 – Microprocessors Lecture 4 Md. Omar Faruqe UB 1228
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
kashanu.ac.ir Microprocessors Interrupts Lec note 8.
Timer Programming in Assembly and C Prepared By:
80C51 Block Diagram 1. 80C51 Memory Memory The data width is 8 bits Registers are 8 bits Addresses are 8 bits – i.e. addresses for only 256.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
Serial I/O Port.
Assembly Language * * * * * * * 8051 Timer
Source: Serial Port Source:
8051 Timers Timers are the peripherals of the 8051 Microcontroller.
Timer Source: under
Programmable Interval Timer
Programmable Interval Timer
Interrupt Source: under
Introduction to Micro Controllers & Embedded System Design Interrupt
UNIT 5 TIMRERS/COUNTERS
Introduction to Micro Controllers & Embedded System Design I/O Processing and Serial Port Operation Department of Electrical & Computer Engineering Missouri.
Timer Operations and Programming
EMT 348: Microcontroller Timer/counter
8051 Timers Prof. Rajiv R Bhandari.
Introduction to Micro Controllers & Embedded System Design Timer Operation Department of Electrical & Computer Engineering Missouri University of Science.
8254 Timer and Counter (8254 IC).
Timer.
8051 Timers / Counters It has two timers Timer 0 and Timer 1.
Programmable Interval timer 8253 / 8254
Timer Source: under
Interrupt Source: under
Programmable Interval timer 8253 / 8254
Interrupt Source: under
Timer Source: under
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
PROCESSORS & CONTROLLERS
Presentation transcript:

CoE3DJ4 Digital Systems Design Chapter 4: Timer operation

Timer There are two 16-bit timers each with four modes of operation Timers are used for (a) interval timing, (b) event counting or (c) baud rate generation for built in serial port Each 16-bit timer is in fact an asynchronous counter therefore the 16 th or last flip-flop divides the input clock frequency by 2 16 =65536 The output of last stage clocks an overflow flip-flop In interval timing applications, a timer is programmed to overflow at a regular interval and set the timer overflow flag Flag is used to synchronize the program to perform an action (e.g., turning on a light) Interval timing can be used to measure the elapsed time

TCON and TMOD Event counting is used to determine the number of occurrences of an event An event is an external stimulus that provides a 1 to 0 transition 8051 timers are accessed using six of SFRs (i.e., TCON, TMOD, TL0, TL1, TH0,TH1) TMOD register contains two groups of four bits that set the operating mode for Timer 0 and Timer 1 TMOD is not bit addressable and is loaded once at the beginning of a program to initialize the timer TCON contains status bits and control bits for Timer 0 and Timer 1.

TCON and TMOD Upper four bits in TCON (TCON.4 to TCON.7) are used to turn timers on and off (TR0,TR1) or signal a timer overflow (TF0,TF1) The lower four bits in TCON are used to detect and initiate external interrupts THx is used to represent TH0 or TH1

Timer Modes Mode 0 is a 13-bit timer mode and is not generally used in new designs Timer high-byte (THx) is cascaded with five least-significant bits of the timer low-byte (TLx) to form a 13-bit timer Upper three bits of TLx are not sued Mode 1 is a 16-bit timer mode Clock is applied to combined high and low timer registers (TLx/THx) Timer counts up and an overflow occurs on FFFF to 0000 transition and sets the timer overflow flag. The timer continues to count Overflow flag is the TFx bit in TCON

Timer Modes Mode 2 is 8-bit auto reload mode Timer’s low-byte (TLx) operates as an 8-bit timer while timer high-byte (THx) holds a reload value When the count overflows from FF not only the flag is set, but the value in THx is loaded into TLx. Counting continues from this value up to next FF Mode 3 is split timer mode and is different for each timer Timer 0 in mode 3 is split into two 8-bit timers. TL0 and TH0 act as separate timers with overflow setting the TF0 and TF1 bits respectively Timer 1 can be switched into one of the other modes. The only limitation is that the usual timer 1 overflow flag TF1, in not affected by Timer 1 since it is connected to TH0.

Clocking sources How the timers are clocked? There are two sources for clock which can be selected by writing to the counter/timer (C/T) bit in TMOD when the timer is initialized. One source is for interval timing and the other one for event counting Interval timing: If C/T=0, timer is clocked from on-chip oscillator –A divide by 12 stage is added to reduce the clocking frequency (for a 12 MHz oscillator the timer clock will be 1 MHz.

Clocking sources Event counting: If C/T=1, timer is clocked from an external source In most applications, external source supplies timer with a pulse upon the occurrence of an “event”, and the timer is an event counter External clock comes through Port 3 pins: P3.4 is the external clocking for Timer 0 and P3.5 is the clocking input for Timer 1. In counter applications, timer registers are incremented in response to a 1 to 0 transition

Starting, stopping and controlling timers Simplest method for starting and stopping timers is with run- control bit (TRx) in TCON TRx is clear after a system reset, therefore, timers are disabled by default TRx is set by software to start timers Example: to start Timer 0 SETB TR0 To stop Timer 0: CLR TR0 Another method for controlling timers is with GATE bit in TMOD and external input INTx (INT0 and INT1 are on Port 3, pins 2 and 3) Setting GATE=1 allows timer to be controlled by INTx

Starting, stopping and controlling timers Assume INT1 is low but pulses high for a period of time to be measured. Initialize Timer 1 for mode 2, 16 bit timer mode withTL1/TH1=0000H, GATE=1 and TR1=1 When INT1 goes high, timer is gated on and is clocked at a rate of 1 MHz. When INT1 goes low, timer is gated off and duration of pulse in microseconds is the count in TL1/TH1

Initializing and accessing timer registers Timers are usually initialized once at the beginning of a program to set the correct operating mode Within the body of a program, timers are started, stopped, flag bits tested, cleared, timer registers read or updated and so on. Example: MOV TMOD, # B –This instruction sets M1=0, M0=1 (for mode 1), leave C/T=0 and GATE=0, for internal clocking. Timer will not begin working until TR1 is set If an initial count is necessary timer registers (e.g., TL1/TH1) must also be initialized. Timer counts up and sets the overflow flag on an FFFFH to 0000H transition

Initializing and accessing timer registers Example: a 100 us interval could be timed by initializing TL1/TH1 to 100 counts less than 0000H which is FF9CH. MOV TL1,#9CH MOV TH1,#FFH SETB TR1 –Overflow flag is automatically set 100 us later. A loop can check to see when the overflow flag is set WAIT: JNB TF1, WAIT –When timer overflows, it is necessary to stop timer and clear the overflow flag: CLR TR1 CLR TF1

Initializing and accessing timer registers In some applications it is necessary to read the value in timer registers on the fly Possible problem: if we read the low byte first and the high byte second and between these two reads the low byte overflows into high byte we have a wrong read value Solution: Read high-byte first, then low-byte and read high- byte again. If high-byte has changed repeat read operation AGAIN:MOV A, TH1 MOV R6,TL1 CJNE A, TH1, AGAIN MOV R7,A

Short intervals and long intervals Write a program that creates a periodic waveform on P1.0 with as high a frequency as possible. What are frequency and duty cycle of waveform? LOOP:SETB P1.0 CLR P1.0 SJUMP LOOP Creates a pulse waveform on P1.0 with a period of 4 us. Signal is high for 1 us (duty cycle of 25%) Period of waveform can be lengthened by inserting NOP instructions into loop Interval in microsecondsTechnique 10Software tuning 2568-bit timer with auto reload bit timer No limit16 bit timer plus software loops

Short intervals and long intervals Example: Write a program using Timer 0 to create a 10 kHz square wave on P1.0 MOV TMOD,#02H MOV TH0,#,-50 SETB TR0 LOOP:JNB TF0, LOOP CLR TF0 CPL P1.0 SJMP LOOP This program creates a square wave on P1.0 with a high-time of 50 us and low time of 50 us. CPL is a complement bit instruction

Short intervals and long intervals Example: write a program using timer 0 to create a 1 kHz square wave on P1.0 MOV TMOD,#01H LOOP:MOV TH0,#FEH MOV TL0,#0CH SETB TR0 WAIT: JNB TF0,WAIT CLR TR0 CLR TF0 CPL P1.0 SJMP LOOP –A 1kHz square wave requires a high time of 500 us and a low time of 500 us. Sine the interval is longer than 256 us, mode 2 cannot be used. Mode 1 (16 bit) is required.

Short intervals and long intervals Example: A buzzer is connected to P1.7, and a debounced switch is connected to P1.6. Write a program that reads logic level provided by the switch and sounds the buzzer for 1 second for each 1 to 0 transition detected.

HUNDRED EQU 100 COUNT EQU ORG 8100H MOV TMOD, #01H LOOP:JNB P1.6, LOOP WAIT:JB P1.6, WAIT SETB P1.7 CALL DELAY CLR P1.7 SJMP LOOP DELAY: MOV R7,#HUNDRED AGAIN: MOV TH0,#HIGH CONT MOV TL0,#LOW COUNT SETB TR0 WAIT2:JNB TF0,WAIT2 CLR TF0 CLR TR0 DJNZ R7,AGAIN RET END