CoE3DJ4 Digital Systems Design. Chapter 4: Timer operation



Similar documents
8051 Serial Port. Crystal TXD. I/O Device RXD. Embedded Systems Peripherals

Flash Microcontroller. Memory Organization. Memory Organization

AN108 IMPLEMENTING A REALTIME CLOCK. Relevant Devices. Introduction. Key Points. Overview

8051 hardware summary

4 Character 5x7 LED Matrix Display

Embedded. Engineer s. Development. Tool (EEDT 5.0)

Small Hardware Development and Prototyping Board for the SX28

Experiment # 9. Clock generator circuits & Counters. Eng. Waleed Y. Mousa

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

AVR Timer/Counter. Prof Prabhat Ranjan DA-IICT, Gandhinagar

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

Real-Time Clock. * Real-Time Computing, edited by Duncan A. Mellichamp, Van Nostrand Reinhold

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Hardware and Software Requirements

Serial Communications

Chapter 9 Latches, Flip-Flops, and Timers

AT89C Bit Microcontroller with 1 Kbyte Flash. Features. Description. Pin Configuration

ETEC 2301 Programmable Logic Devices. Chapter 10 Counters. Shawnee State University Department of Industrial and Engineering Technologies

Flash Microcontroller. Architectural Overview. Features. Block Diagram. Figure 1. Block Diagram of the AT89C core

Timer A (0 and 1) and PWM EE3376

Lesson-16: Real time clock DEVICES AND COMMUNICATION BUSES FOR DEVICES NETWORK

Microtronics technologies Mobile:

Section 14. Compare/Capture/PWM (CCP)

Decimal Number (base 10) Binary Number (base 2)

8051 MICROCONTROLLER COURSE

T.C. Yeditepe University. Department of Electrical-Electronics Engineering

Asynchronous counters, except for the first block, work independently from a system clock.

Counters and Decoders

ADS9850 Signal Generator Module

Below is a diagram explaining the data packet and the timing related to the mouse clock while receiving a byte from the PS-2 mouse:

24-Bit Analog-to-Digital Converter (ADC) for Weigh Scales FEATURES S8550 VFB. Analog Supply Regulator. Input MUX. 24-bit Σ ADC. PGA Gain = 32, 64, 128

Design Example: Counters. Design Example: Counters. 3-Bit Binary Counter. 3-Bit Binary Counter. Other useful counters:

Interfacing Analog to Digital Data Converters

8254 PROGRAMMABLE INTERVAL TIMER

University of Portsmouth Faculty of Technology Department of Electronic and Computer Engineering. Content

Module 3: Floyd, Digital Fundamental

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

DP8570A DP8570A Timer Clock Peripheral (TCP)

Flip-Flops, Registers, Counters, and a Simple Processor

8085 MICROPROCESSOR PROGRAMS

Cascaded Counters. Page 1 BYU

Old Company Name in Catalogs and Other Documents

Microprocessor & Assembly Language

Debouncing Switches. Mechanical switches are one of the most common interfaces to a uc.

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

DIGITAL COUNTERS. Q B Q A = 00 initially. Q B Q A = 01 after the first clock pulse.

ASYNCHRONOUS COUNTERS

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

SPI. Overview and Use of the PICmicro Serial Peripheral Interface. Getting Started: SPI

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

AP TriCore. Sinusodial 3-Phase Output Generation Using The TriCore General Purpose Timer Array. Microcontrollers

Hello, and welcome to this presentation of the STM32L4 reset and clock controller.

CHAPTER 11: Flip Flops

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

PART B QUESTIONS AND ANSWERS UNIT I

Microcontroller Based Infrared Tracking Device In 2D Motion

A High Resolution Performance Monitoring Software on the Pentium

A simple RF/Microwave frequency counter

Digital Fundamentals

AN974 APPLICATION NOTE

Timing Methodologies (cont d) Registers. Typical timing specifications. Synchronous System Model. Short Paths. System Clock Frequency

DS2155 T1/E1/J1 Single-Chip Transceiver

Embedded Based Automated Student Attendance Governing System

Quick Start Tutorial. Using the TASKING* Software Development Tools with the Intel 8x930 Family Evaluation Board

6-BIT UNIVERSAL UP/DOWN COUNTER

DS1621 Digital Thermometer and Thermostat

8741A UNIVERSAL PERIPHERAL INTERFACE 8-BIT MICROCOMPUTER

css Custom Silicon Solutions, Inc.

EC313 - VHDL State Machine Example

To design digital counter circuits using JK-Flip-Flop. To implement counter using 74LS193 IC.

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

AN3252 Application note

AN141 SMBUS COMMUNICATION FOR SMALL FORM FACTOR DEVICE FAMILIES. 1. Introduction. 2. Overview of the SMBus Specification. 2.1.

Lecture-3 MEMORY: Development of Memory:

DM54161 DM74161 DM74163 Synchronous 4-Bit Counters

ECONseries Low Cost USB DAQ

Design and Implementation of Home Monitoring System Using RF Technology

Systems I: Computer Organization and Architecture

DIGITAL ELECTRONICS. Counters. By: Electrical Engineering Department

Event counters in NOVA

Digital Logic Design Sequential circuits

Atmel Norway XMEGA Introduction

Simulating Power Supply Sequences for Power Manager Devices Using PAC-Designer LogiBuilder

Hello, welcome to this presentation of the low power timer, or LPTMR, module for Kinetis MCUs. In this session you ll learn about the LPTMR, it s

DATA SHEET. HEF40193B MSI 4-bit up/down binary counter. For a complete data sheet, please also download: INTEGRATED CIRCUITS

Chapter 7. Registers & Register Transfers. J.J. Shann. J. J. Shann

DM74LS169A Synchronous 4-Bit Up/Down Binary Counter

Keil C51 Cross Compiler

54191 DM54191 DM74191 Synchronous Up Down 4-Bit Binary Counter with Mode Control

PIC Programming in Assembly. (

HANDBOOK. Measuring System DESIGN EDITORS PETER H. SYDENHAM RICHARD THORN ARTICLE OFFPRINT

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

Sequential Logic Design Principles.Latches and Flip-Flops

Software Serial Port for ROM/RAM Monitor

EE552. Advanced Logic Design and Switching Theory. Metastability. Ashirwad Bahukhandi. (Ashirwad Bahukhandi)

Freescale Semiconductor, Inc. Product Brief Integrated Portable System Processor DragonBall ΤΜ

Transcription:

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 runcontrol 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, #00010000 B This instruction sets M1=0, M0=1 (for mode 1), leave C/T=0 and GATE=0, for internal clocking and clear Timer 0 mode bit). 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 highbyte 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 Interval in microseconds 10 256 65536 No limit Technique Software tuning 8-bit timer with auto reload 16 bit timer 16 bit timer plus software loops 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

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 -10000 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