Chapter 6 PROGRAMMING THE TIMERS

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

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

CoE3DJ4 Digital Systems Design. Chapter 4: Timer operation

Flash Microcontroller. Memory Organization. Memory Organization

Interrupts and the Timer Overflow Interrupts Huang Sections What Happens When You Reset the HCS12?

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

Timer Value IRQ IACK

Chapter 13. PIC Family Microcontroller

Motor Speed Measurement Considerations When Using TMS320C24x DSPs

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

Event counters in NOVA

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

Timer A (0 and 1) and PWM EE3376

Section 14. Compare/Capture/PWM (CCP)

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

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

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

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

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

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

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

Flexible Counter Series in DIN size 24 x 48 mm

Keil C51 Cross Compiler

Chapter 9 Latches, Flip-Flops, and Timers

Monitoring of Intravenous Drip Rate

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

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

DS1621 Digital Thermometer and Thermostat

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

Chapter 11: Input/Output Organisation. Lesson 06: Programmed IO

8051 MICROCONTROLLER COURSE

MAX II ISP Update with I/O Control & Register Data Retention

8-bit Microcontroller with 12K Bytes Flash and 2K Bytes EEPROM AT89S8253

AN3371 Application note

PART B QUESTIONS AND ANSWERS UNIT I

Microprocessor & Assembly Language

PWM IN AVR. Developed by: Krishna Nand Gupta Prashant Agrawal Mayur Agarwal

Small Hardware Development and Prototyping Board for the SX28

DS1821 Programmable Digital Thermostat and Thermometer

Section 29. Real-Time Clock and Calendar (RTCC)

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

PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks

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

RENESAS TECHNICAL UPDATE

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

HT46R14A Single Phase AC Induction Motor Frequency Converter Application

Interrupts. 1.Maskable interrupt request can be ignored or delayed by the microprocessor and used in telephone

DS1621 Digital Thermometer and Thermostat

Multifunction devices

8-bit Microcontroller. Application Note. AVR400: Low Cost A/D Converter

Crazy Alarm Clock L A K S H M I M E Y Y A P P A N J A M E S K A Y E W I L L I A M D I E H L C O N G C H E N

CHAPTER 11: Flip Flops

Application Note. 8-bit Microcontrollers. AVR091: Replacing AT90S2313 by ATtiny2313. Features. Introduction

Freescale Semiconductor, I

Programming A PLC. Standard Instructions

AVR134: Real Time Clock (RTC) using the Asynchronous Timer. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

TDA General description. 2. Features and benefits. Low power single card reader

Old Company Name in Catalogs and Other Documents

MEMOBUS/Modbus Communications

Serial Communications

Pulse Width Modulation

LAB #4 Sequential Logic, Latches, Flip-Flops, Shift Registers, and Counters

6-BIT UNIVERSAL UP/DOWN COUNTER

REAL TIME OPERATING SYSTEMS. Lesson-3:

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

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

DM54161 DM74161 DM74163 Synchronous 4-Bit Counters

AN974 APPLICATION NOTE

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

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

A High Resolution Performance Monitoring Software on the Pentium

DP8570A DP8570A Timer Clock Peripheral (TCP)

AN3252 Application note

AVR1321: Using the Atmel AVR XMEGA 32-bit Real Time Counter and Battery Backup System. 8-bit Microcontrollers. Application Note.

STEPPER MOTOR SPEED AND POSITION CONTROL

KeyStone Architecture TIMER64P. User Guide

DS2155 T1/E1/J1 Single-Chip Transceiver


8254 PROGRAMMABLE INTERVAL TIMER

CHAPTER 11 LATCHES AND FLIP-FLOPS

Programming Examples. B.1 Overview of Programming Examples. Practical Applications. Instructions Used

Flexible Active Shutter Control Interface using the MC1323x

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

Atmel Norway XMEGA Introduction

Motor Control using NXP s LPC2900

Voltage boost and buck circuits using Atmel AVR Tiny13V for driving a white LED.

Exception and Interrupt Handling in ARM

8741A UNIVERSAL PERIPHERAL INTERFACE 8-BIT MICROCOMPUTER

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

Computer Organization and Components

APPLICATION. si32library. Callback CMSIS HARDWARE. Figure 1. Firmware Layer Block Diagram

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

Hardware and Software Requirements

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

PACKAGE OUTLINE DALLAS DS2434 DS2434 GND. PR 35 PACKAGE See Mech. Drawings Section

AN3332 Application note

M25P05-A. 512-Kbit, serial flash memory, 50 MHz SPI bus interface. Features

8051 hardware summary

8-bit Microcontroller with 8K Bytes Flash AT89S8252

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

Transcription:

Chapter 6 PROGRAMMING THE TIMERS

Lesson 1 Programmable Timer-Counter Device 2

Timer-Counter Prescaling 3

Timer Pre-scaling 8051 T0 in Mode 0 Example Pre-scaling of TH0 by 32 through TL0 5-bit TL0 TH0 13-bit counter Count Inputs from internal clock or from pin T1 4

68HC11 TCNT (Time-Counter) Example 16-bit counter TCNT Register Pre scaling of E- clock inputs by PR0-PR1 bits programmable as 1, 4, 8 or 16 with in 64 clock cycles on power up reset Count Inputs from internal E- clock 2 MHz for 8 MHz 5

Example- 68HC11 TCNT Let XTAL clock = 8 MHz,therefore counter clock-input period = 0.5 µs. Let Pre-scaling factor programmed = 8 Therefore, clock-inputs to TCNT at each 8 0.5 µs = 4 µs interval When TCNT = 1FA0H,then after 4 16 µs TCNT reading will be will be 1FB0H; after next 1024 µs, 20B0H. 6

Timer-Counter Reset to 0000H 7

8051/52 16-bit Counters Resetting Timer-counter T1 resets on on writing 00H- 00H at TH1-TL1 or on T0 overflow Timer-counter T0 resets on writing 00H-00H at TH0-TL0 or on overflow of T0 Timer-counter T2 resets on writing 00H- 00H at TH2-TL2 or on overflow of T2 8

68HC11 16-bit Counters Resetting Timer-counter T1 resets on TCNT overflow 9

68HC11 TCNT Overflow example 16-bit counter Example Timer overflow interrupt if not masked, an ISR executes Overflows after 2 16 inputs after each 2 16 p 0.5µs from instance when count bits all 0s Clock Inputs period = 0.5 µs for 8 MHz XTAL, pre-scaling factor set = p = 1 or 4 or 8 or 16 10

8051 Timer-Counter Start/Stop 11

Timer-Counter start, stop and reset Finding time interval between two events. Finding period of a pulse at a port pin Find time taken for a motor for 1 or more revolutions Reset timer T counts = 0, and mode set for internal clock-inputs. On first event, start T and second event stop T. 12

8051 TH0-TL0 Mode 1 Let XTAL clock =12 MHz,therefore counter clock-input period = 1 µs. Let Mode T0 is C/T =0 (internal clock mode) Let T0 be programmed in mode 1 (TH0,TL0) 16-bit counter. WhenTR0 is set,timer T0 starts and TR0 reset T0 stops. 13

8051 T1 in Mode 1 Example 16-bit counter TH1 TL1 Count Inputs from internal clock or from pin T1 0 or 1 at External gate pin INT1 and 1 or 0 TR1 together starts/stops when programming of T1 is like that else set/reset of TR1 only starts/stops as per programming. 14

8052 T2 Example 16-bit counter Count Inputs from internal clock or from pin C/T2 as per programming of T2 1. External CP/RL2 for counter reload on overflow if EXEN2 bit set 2. TR2 bit set/reset programmed to start/stop. 15

68HC11 Timer-Counter Nonprogrammability except for Prescaling or counting rate setting 16

68HC11 TCNT Non- Programmability 16-bit counter Internal clock input rate or the prescaling only programmable TCNT Register Count Inputs from internal clock No TR bit; Start/stop and No reset programmable 17

8051 Timer-Counter Loading and Reload 18

8051 T0 in Mode 3 Example TH0 TL0 TH0 is written the counts = x0. TH0 overflows (256- x0) inputs from the start. Count Inputs from internal clock or from pin T1 TL0 is written the counts = x1. TL0 overflows after (256-x1) inputs from the start Loading of TH0 and TH0 by writing counts x0 and x1. Resetting by writing 0000H into TCNT. 19

8051 T1 in Mode 2 Example TH1 TL1 Count Inputs from internal clock or from pin T1 TH1 is first written the counts, x0. TL1 autoreloads x0 from TH1 on each overflow. 20

8052 T2 Example 16-bit counter Load by writing x at TH2-TL2. TH2-TL2 overflows after (2 16 x) inputs Count Inputs from internal clock or from pin C/T2 as programmed 21

8052 T2 Example 16-bit counter Count Inputs from internal clock or from pin C/T2 as programmed External CP/RL2 for counter reload if EXEN2 bit set. Reloads from the TH2-TL2 registers 22

68HC11 TCNT Example Internal clock input rate/ Prescaling factors only programmable 16-bit counter TCNT Count Inputs from internal clock. Read Only No loading of TCNT, No resetting by writing 0000H into TCNT. 23

An overflow delay two or four or eight times when pre-scaling factor = 2 or 4 or 8 24

Overflow after a Period 25

Example- 8051 TH1-TL1 Mode 1 Let XTAL clock =12 MHz,therefore counter clock-input period = 1 µs. Let Mode T1 is C/T,internal clock mode Let T1 be programmed in mode 1 (TH1,TL1) 16-bit counter. WhenTH1-TL1 written (loaded) E0H-01H then timer T1 will timeout and overflow after 1FFFH inputs. 26

Example- 8051 TL0 Mode 2 Let XTAL clock =12 MHz,therefore counter clock-input period = 1 µs. Let Mode T0 is C/T,internal clock mode Let T0 be programmed in mode 2; TL0 loads counts from TH0,TL0 runs as 8-bit counter. WhenTH0 (loaded) E0H then timer T0 uses TL0 and will timeout and overflow after each 20H inputs (= 32 µs) as TL0 reloads also from TH0 on overflow. 27

Program for finding the Time Interval of Counting in 8051/52 28

One Timer as Timer and other as counter Counter-timer device 1 programs the Timer for counting time interval in timer mode When device 1 starts, the counter mode timer-counter device 2 also starts counting. When device 1 overflows (timeouts), the ISR stops the device 2 counting. 29

Example- 8051 TH0-TL0 Mode 3 Let XTAL clock =12 MHz,therefore counter clock-input period = 1 µs. Let Mode T1 is C/T1= 1 for count mode TH0 and mode T0 is is C/T0= 0 for timer mode TL0 Let T0 programmed in mode 3. TH0-TL0 independent counters and TL0 be written 7DH, to set the interval to (100H-7EH) = 83H = 131 µs for timeout and overflow. 30

8051 TH0-TL0 Mode 3 Step1: Set TR0 = 1, reset TH0 = 00H Step 2: Run TH0 by setting TR1 =1, so that TH0 starts counting from 00H. Step3: TL0 overflows and interrupts after counting interval = 131 µs, the ISR resets TR1 = 0, it stopsth0. TH0 will gives the count pulses at C/T1 pin received in 131 µs. 31

Timer-Counter Overflow Events 32

Example of Timer-Counter Overflow Event Timer-counter T1 mode1 on overflow after one input from FFFFH and new reading = 0000H at TH1-TL1 33

Masking Interrupt Service on Timer- Counter Overflow Event T0 or T1 or T2 or TCNT overflow interrupt maskable If masked, no interrupt service routine executes on overflow 34

8051 TL0 timer mode 2 example 8-bit counter Example Clock Inputs period = 1 µs for 12 MHz XTAL Timer overflow interrupt if it is not masked, an ISR executes Overflows after 256 inputs in 256 µs if initial count bits all 0s. 35

68HC11 TCNT example 16-bit counter Example Clock Inputs period = 1/2 µs for 8 MHz XTAL, prescaling factor set = 1 Timer overflow interrupt if not masked, an ISR executes Overflows after 2 16 inputs in 2 16 /2 µs from count bits all 0s. 36

Example- 8051 TH0 Mode 3 Let XTAL clock =12 MHz,therefore counter clock-input period = 1 µs. Let Mode T1 is C/T,internal clock mode Let T0 programmed in mode 3. TH0-TL0 independent counters and TH0 be written 81H. WhenTH0 starts by setting TR1 = 1, Over-flow will be after (100H-81H) = 127 µs 37

Preset time interval ON-OFF of a unit Load timer T counts = x, and mode set for internal clock-inputs. Start T. switch ON and on over flow interrupt, switch OFF. Application- Output change (s) for a pre-fixed interval 38

Preset long time interval on-off of a unit Load n-bit timer T counts = x, define number of overflows = k, mode set for internal clockinputs. Switch on an output, Start T and on overflow interrupt, reload the counts on 1 to (k 1) th overflows and switch off the output on k th over flow interrupt. Delay = k.(2 n - x).x.p.t, where t = clock input period, p = pre scaling factor 39

Exemplary Applications Moving robot arm for a defined period. Output change for a pre-fixed interval Current output for a fixed interval A microwave oven ON for a fixed interval 40

Finding a long time interval between two events Reset timer T counts = 0, and mode set for internal clock-inputs. On first event, start T and till second event,find k the number of overflows and on second event stop T. Exemplary Applications Find time taken for a weight-lifter to lift Find time taken for an input event change 41

Time interval Time interval = [(2 n.k) +x1].p.t, where t = clock input period, p = pre scaling factor, x1 = final counts at the n-bit at T. 42

Summary 43

we learnt Two types of timer-counter devices - Start, stop, reset and preloading a count programmable Free running timer-counter: start,stop, reset and preloading counts x, each one is not programmable 44

We learnt Pre-scaling of timer-counter device - Programmable in TCNT 68HC11 Programmable as 32 in mode-0 at T1 or T0 in 8051 Pre-scaling extends the overflow rates and extends the increment interval of counts by pre-scaling factor 45

We learnt Loading of timer-counter device - Not Programmable in TCNT 68HC11 Programmable in T0, T1 or T2 at 8051 46

we learnt Overflow interrupt(s) of timer-counter device - Initiate an action Initiate an action after pre-fixed number of overflows 47