M68HC11 Timer. Definition

Similar documents
COSC3215. Input Capture Output Compare

o The 9S12 has a 16-bit free-running counter to determine the time and event happens, and to make an event happen at a particular time

o The 9S12 has a 16-bit free-running counter to determine the time and event happens, and to make an event happen at a particular time

Point System (for instructor and TA use only)

RS flip-flop using NOR gate

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

Figure 30.1a Timing diagram of the divide by 60 minutes/seconds counter

Menu. 68HC12 Timer Block Diagram EEL 3744 EEL Input Capture (IC)

EMT 125 Digital Electronic Principles I CHAPTER 6 : FLIP-FLOP

ELE2120 Digital Circuits and Systems. Tutorial Note 8

EKT 121/4 ELEKTRONIK DIGIT 1

Introduction to Sequential Circuits

Decade Counters Mod-5 counter: Decade Counter:

Digital Fundamentals: A Systems Approach

Chapter 4. Logic Design

IT T35 Digital system desigm y - ii /s - iii

Other Flip-Flops. Lecture 27 1

CSE Latches and Flip-flops Dr. Izadi. NOR gate property: A B Z Cross coupled NOR gates: S M S R Q M

MUHAMMAD NAEEM LATIF MCS 3 RD SEMESTER KHANEWAL

Counters

Tutorial Introduction

Registers and Counters

YEDITEPE UNIVERSITY DEPARTMENT OF COMPUTER ENGINEERING. EXPERIMENT VIII: FLIP-FLOPS, COUNTERS 2014 Fall

RS flip-flop using NOR gate

Experiment 8 Introduction to Latches and Flip-Flops and registers

DIGITAL SYSTEM FUNDAMENTALS (ECE421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE422) COUNTERS

Counter/timer 2 of the 83C552 microcontroller

Experiment # 9. Clock generator circuits & Counters. Digital Design LAB

ASYNCHRONOUS COUNTER CIRCUITS

Sequential Digital Design. Laboratory Manual. Experiment #7. Counters

Flip-Flops. Because of this the state of the latch may keep changing in circuits with feedback as long as the clock pulse remains active.

Digital Logic Design Sequential Circuits. Dr. Basem ElHalawany

Microcontrollers. Outline. Class 4: Timer/Counters. March 28, Timer/Counter Introduction. Timers as a Timebase.

Lecture 8: Sequential Logic

LATCHES & FLIP-FLOP. Chapter 7

EKT 121/4 ELEKTRONIK DIGIT 1

Lab #10: Building Output Ports with the 6811

Registers and Counters

2. Counter Stages or Bits output bits least significant bit (LSB) most significant bit (MSB) 3. Frequency Division 4. Asynchronous Counters

Chapter. Synchronous Sequential Circuits

CHAPTER 4: Logic Circuits

TV Synchronism Generation with PIC Microcontroller

ECE 263 Digital Systems, Fall 2015

CHAPTER 4: Logic Circuits

CHAPTER 6 COUNTERS & REGISTERS

Logic Gates, Timers, Flip-Flops & Counters. Subhasish Chandra Assistant Professor Department of Physics Institute of Forensic Science, Nagpur

Introduction. NAND Gate Latch. Digital Logic Design 1 FLIP-FLOP. Digital Logic Design 1

Logic and Computer Design Fundamentals. Chapter 7. Registers and Counters

Analog Input & Output

Introduction to Mechatronics. Fall Instructor: Professor Charles Ume. Analog to Digital Converter

The part chosen for the encoder was the Hamatsu P5587 photoreflector. The device

Advanced Devices. Registers Counters Multiplexers Decoders Adders. CSC258 Lecture Slides Steve Engels, 2006 Slide 1 of 20

Name Of The Experiment: Sequential circuit design Latch, Flip-flop and Registers

Logic Design. Flip Flops, Registers and Counters

UNIVERSITI TEKNOLOGI MALAYSIA

Asynchronous (Ripple) Counters

FLIP-FLOPS AND RELATED DEVICES

Flip Flop. S-R Flip Flop. Sequential Circuits. Block diagram. Prepared by:- Anwar Bari

Synchronous Sequential Logic

Rangkaian Sekuensial. Flip-flop

Electrical & Computer Engineering ECE 491. Introduction to VLSI. Report 1

Last time, we saw how latches can be used as memory in a circuit

Flip-Flops and Sequential Circuit Design

Slide 1. Flip-Flops. Cross-NOR SR flip-flop S R Q Q. hold reset set not used. Cross-NAND SR flip-flop S R Q Q. not used reset set hold 1 Q.

CS 110 Computer Architecture. Finite State Machines, Functional Units. Instructor: Sören Schwertfeger.

SEQUENTIAL LOGIC. Satish Chandra Assistant Professor Department of Physics P P N College, Kanpur

EET2411 DIGITAL ELECTRONICS

Digital Circuits 4: Sequential Circuits

Chapter 6. Flip-Flops and Simple Flip-Flop Applications

NH 67, Karur Trichy Highways, Puliyur C.F, Karur District UNIT-III SEQUENTIAL CIRCUITS

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

CPE 200L LABORATORY 3: SEQUENTIAL LOGIC CIRCUITS UNIVERSITY OF NEVADA, LAS VEGAS GOALS: BACKGROUND: SR FLIP-FLOP/LATCH

Logic Devices for Interfacing, The 8085 MPU Lecture 4

Chapter 8 Sequential Circuits

1. Convert the decimal number to binary, octal, and hexadecimal.

Analogue Versus Digital [5 M]

Chapter 5 Flip-Flops and Related Devices

VTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS Registers

Read-only memory (ROM) Digital logic: ALUs Sequential logic circuits. Don't cares. Bus

Review of digital electronics. Storage units Sequential circuits Counters Shifters

Chapter 4: One-Shots, Counters, and Clocks

Asynchronous Counter

MODULE 3. Combinational & Sequential logic

UNIT-3: SEQUENTIAL LOGIC CIRCUITS

Long and Fast Up/Down Counters Pushpinder Kaur CHOUHAN 6 th Jan, 2003

QUICK GUIDE COMPUTER LOGICAL ORGANIZATION - OVERVIEW

Final Exam review: chapter 4 and 5. Supplement 3 and 4

Today 3/8/11 Lecture 8 Sequential Logic, Clocks, and Displays

Name: Date: Suggested Reading Chapter 7, Digital Systems, Principals and Applications; Tocci

Counter dan Register

Sequential Logic and Clocked Circuits

Vignana Bharathi Institute of Technology UNIT 4 DLD

Digital Circuit And Logic Design I. Lecture 8

Digital Circuit And Logic Design I

Synchronous sequential circuits

Chapter 2. Digital Circuits

Chapter 5 Sequential Circuits

Latches, Flip-Flops, and Registers. Dr. Ouiem Bchir

Unit 11. Latches and Flip-Flops

Chapter 6 Registers and Counters

Transcription:

M68HC Timer March 24 Adam Reich Jacob Brand Bhaskar Saha Definition What is a timer? A timer is a digital sequential circuit that can count at a precise and programmable frequency Built-in timer (like in 68HC) The frequency is linked to the one of the internal clocks/oscillators External timer Larger ranges of frequencies

Memory Elements Flip Flop Introduction Flip Flops are the basic building blocks of digital sequential circuits Brief History 99: W. H. Eccles and F. W. Jordan publish the first flip-flop circuit design. TI Type 52 Flip Flop: st production IC in 96. R-S Flip Flop Logic Symbol Set Input Reset Also called: Normal R-S Latch S Q Set-Reset FF FF Complementary R Q Truth Table Wiring Diagram Waveform Diagram Mode of Operation Prohibited Set Reset Input S Input R Q Q Effect Prohibited Do not use For setting Q to Resetting Q to S R Q Set Reset Hold Set Hold Hold Q Q Depends Previous State Q

D Flip-Flop Schematic D Flip-Flop Schematic

D Flip-Flop Schematic D Flip-Flop Schematic

D and J-K Flip Flops The D flip-flop avoids the undefined states in the RSFF truth table by reducing the number of inputs. S Q R Q The JKFF simplifies the RSFF truth table but keeps two inputs. The toggle state is useful in counting circuits. S Q R Q Counters There are several different ways of categorizing counters: binary-coded decimal (BCD) versus binary, one direction versus up/down and asynchronous ripple-through versus synchronous. Q Q Q2 Q Q Q2 3-bit Ripple Counter 3-bit Synchronous Counter

You will learn how to: prescale the main timer counter record the time an event occurs take an action at a specific time handle counter overflows use Real-Time Interrupts use the Pulse Accumulator to: count events measure the duration of an event Usage of timers Where can timers be found? EVERYWHERE! Clocks Digital camera Radar Space exploration Anywhere you could think to put one! Anything that could be linked to time

Examples - Input Time between two rising edges Radar Compute the time between two successive falling edges Track & Field Timing Pulse width measurement Time delay Time basis Examples - Clocks Rectangle wave generator Use specific registers (see HC specific part) Creating a time delay ms delay to program an EEPROM ms at 2MHz $4E2 cycles (2,)

General Description of Main Timer Central element:6-bit free running counter Bit 5 - - - - - - Bit 8 $E TCNT Bit 7 - - - - - - Bit $F At reset counter starts from $ and counts up continuously When $FFFF is reached, counter rolls over to $ May be read at any time using a double-byte instruction like LDD or LDX Cannot be written or reset during operation Timer Prescaler Allows 4 clocking rates of the timer counter E-Clock rate divided by:, 4, 8, 6 At reset the default prescale factor is Must be set during the first 64 E-Clock cycles after reset

Changing the Prescaler Trade-off between timer resolution and timer range 7 6 5 4 TOI RTII PAOVI TMSK2 PAII PR PR $24 3 2 Bus Frequency (E Clock) Prescale Factor 4 8 6 Resolution (one count) 5 ns 2 µs 4 µs 8 µs 2 MHz Range (Overflow) 32.77 ms 3. ms 262. ms 524.3 ms PR PR Timer Overflow Timer Overflow Timer overflow flag (TOF) status bit is set each time the counter rolls over from $FFFF to $ TOF status bit can generate an automatic interrupt request by setting the timer overflow interrupt (TOI) enable bit Registers associated: TMSK2,TFLG2 b7 TMSK2 TOI $24 TFLG2 TOF $25

Timer Flags Clearing timer flags Load an accumulator with a mask that has a one in the bit(s) corresponding to the flag(s) to be cleared Then write this value to TFLG or TFLG2 E.g. LDAA #$8, STAA TFLG2 will clear TOF Or use BCLR instruction to clear the flag, the mask should have zeros in the bit positions corresponding to the flags to be cleared and ones in all other bits. (BCLR read->and with inversed mask->write back) E.g. BCLR TFLG2 #% Caution! Don t use BSET to clear flags because it could inadvertently clear one or more of the other flags in the register BSET: read->or with mask->write back Input Capture Used to measure signal period/frequency (capture successive edges with same polarity) Measure pulse width (capture successive edges with alternate polarity) Used as time reference for output compare

Input Capture Registers There are three timer input pins on Port A (Pins PA-PA2) Each input pin has a corresponding input capture register (6-bits each) When an edge is detected at a timer input pin, the current value of the free-running counter is stored in the corresponding input capture register Input Capture Registers (cont) TIC TIC2 TIC3 - - - - - Bit 5 - Bit 8 - - - - - - Bit 7 Bit - - - - - - Bit 5 Bit 8 - - - - - - Bit 7 Bit - - - - - - Bit 5 Bit 8 - - - - - - Bit 7 Bit $ $ $2 $3 $4 $5 Can be read at any time as a pair of 8-bit registers using instructions like LDD or LDX Cannot be written by software

Input Capture Registers (cont) Operate independently of each other While reading the data in an input capture register, a new input capture to that register will be inhibited for one bus cycle so that the new input capture will not replace the old data before it is read. Inhibited capture will be delayed but will not be lost Both input captures and output compares are referenced from the same counter, so software latencies do not affect the accuracy to time delay Timer Input Capture 4/ 5 Register

Input Edge-Detection Logic Used to select which edge of an input is detected 7 6 5 4 TCTL2 EDGB EDGA EDG2B EDG2A EDG3B EDG3A $2 3 2 Configuration Capture Disabled Capture on Rising Edge Only Capture on Falling Edge Only Capture on Any Edge EDGxB EDGxA Interrupt Generation Logic Input capture status flags are automatically set to one each time a selected edge is detected 7 6 5 4 3 2 TFLG OCF OC2F OC3F OC4F OC5F ICF IC2F IC3F $23 Input capture interrupt enable bits 7 6 5 4 TMSK OCI OC2I OC3I OC4I OC5I ICI IC2I IC3I $22 3 2

Measuring Long/Short Periods Long Periods: Use software to keep track of counter overflows in an 8-bit register Creates a 24-bit counter Stored time values as 3-byte numbers (see Ref. Manual.5) Short Periods: Measure as short as one timer count periods by connecting one signal to two IC pins. Other Uses of Input Capture Pins Can be used as general purpose input pins when the timer functions are not needed Can serve as flexible interrupt input pins Have some advantages over the IRQ pin See Ref. Manual section.5.7

Used for outputting waveforms to control actuators or is used to generate time delays for I/O functions Accomplished by comparing the contents of the free-running counter with the compare register. When a match occurs, an output is generated : Basic Concept 6 Bit Register Stores a Number -5 possible Registers to store this number: Register Name TOC TOC2 TOC3 TOC4 TOC5 Address $6 and $7 $8 and $9 $A and $B $C and $D $E and $F Comparator checks number against Free Running Counter (TCNT Register) -Really 5 comparators, one for each register -This is done in hardware, no processor time used When Counter matches TOCx Register, it triggers an event

What Event is triggered? Three Possibilities: Change the status of one or several Port A pins Set a Flag in TFLG Register Cause an Interrupt Changing Port A Pin status with s 2 to 5: Each compare controls a SINGLE PIN: 2 3 4 5 PA6 PA5 PA4 PA3

Changing Port A Pin status with (cont) s 2 to 5: TCTL Register Controls How Each Pin Changes OM2 OL2 OM3 OL3 OM4 OL4 OM5 OL5 TCTL $2 OMx OLx Configuration OCx Does Not Affect Pin (OC Still May) Toggle Ocx Pin on Successful Clear Ocx Pin on Successful Set Ocx Pin on Successsful Changing Port A Pin status with (cont) : Causes 5 Port A pins to change simultaneously (PA3-PA7) Has priority over OC2-OC5 OCM Register determines which Port A Pins will be Controlled by PA7 PA6 PA5 PA4 PA3 OCM7 OCM6 OCM5 OCM4 OCM3 OCM $C OCD Register sets value to be written to Port A pins selected in OCM OCD7 OCD6 OCD5 OCD4 OCD3 OCD $D

Setting a Flag with When is successful it sets the corresponding Flag in TFLG Control Register: OCF OC2F OC3F OC4F OC5F ICF ICF ICF TFLG $23 2 3 4 5 Software must constantly poll TFLG register to check for flags ** bits are cleared using the methods described earlier Causing an Interrupt with compare will cause an interrupt when the corresponding bit in TMSK is set: OCI OC2I OC3I OC4I OC5I ICF ICF ICF TMSK $22 2 3 4 5

Forced If you need to change the state of a Port A Pin BEFORE output compare occurs Use Forced software triggers compare to occur and Pin A will change state accordingly Write a to force an output compare. Writing a zero will have no effect Forced output will not cause the status bits to be set, therefore, no interrupt CFORC FOC FOC2 FOC3 FOC4 FOC5 $B 2 3 4 5 Example program (input Capture)

Example program (input Capture) Example program (input Capture)

Example program (input Capture) Period Measurement Example Code FIRST EQU $D DEFINE A 2-BYTE LOCATION TO STORE FIRST EDGE PERIOD EQU $D2 DEFINE A 2-BYTE LOCATION TO STORE PERIOD ORG $C LDX #$ LDAA #$ STAA $2 EDGE DETECTION FOR IC SET TO RISING EDGES LDAA #$4 STAA $23 CLEARS ANY OLD FLAGS FROM ICF LOOP BRCLR $23,X #$4 LOOP LOOP HERE UNTIL FIRST RISING EDGE IS DETECTED LDD $ READ TIME OF FIRST CAPTURE STD FIRST STORE FIRST CAPTURE VALUE LDAA #$4 STAA $23 CLEAR THE ICF FLAG BEFORE NEXT EDGE LOOP2 BRCLR $23,X #$4 LOOP2 LOOP HERE UNTIL NEXT RISING EDGE IS DETECTED LDD $ READ TIME OF SECOND CAPTURE SUBD FIRST FIND THE TIME DIFFERENCE BEWTEEN EDGES STD PERIOD STORE THE RESULT AS THE PERIOD :

Real-Time Interrupt Generates hardware interrupts at a fixed rate Free-running counter cannot be interrupted One of four rates- software selected One flag- set at the user determined rate Flag must be cleared after it is used, especially when using interrupts or a system lock up will occur. RTI Registers TMSK2 $24 Real-Time Interrupt Enable TFLG2 $25 Real-Time Interrupt Flag PACTL $26 Real-Time Interrupt Rate Selects B6 RTII B6 RTIF B RTR B RTR

Real-Time Interrupt Rate Selects For 8MHz Crystal Frequency (2MHz E Clock) RTR RTR E/2 3 Divided By Nominal RTI Rate 4. ms 2 8.9 ms 4 6.38 ms 8 32.77 ms RTI Example: Oven Control Example:Using a 33 ms RTI interrupt, the slave board should measure the oven temperature and save the value in a global variable. It should turn the heater on if the oven temperature is below the set point, and turn the heater off if the oven temperature is above the set point.

Pulse Accumulator Overview 8-bit Counter Incremented by edge on pin Used to measure duration of pulse number of events Key Things to Know Can be read or written at any time 2 Modes Event Counter Gated Time Accumulation PAI Pin: Port A Pin 7 Registers

Pulse Accumulator Associated Registers TMSK2 TOI RTII PAOVI PAII PR PR $24 TFLG2 TOF RTIF PAOVF PAIF $25 PACTL DDRA7 PAEN PAMOD PEDGE DDRA3 I4/O5 RTR RTR $26 b7 b PACNT $27 DDRA7: =input, =output. (normally configured as input when PA is used) PAEN: =PA disabled, =PA enabled PAMOD: =event counter, =gated time accumulation PEDGE event counter: =PA responds to falling edges, = rising edge gated time: =inhibit gate level is zero, =inhibit gate level is one PAOVI, PAOVF: PA overflow interrupt enable and flag PAII, PAIF: PA input edge interrupt enable and flag Pulse Accumulator Event Counting Mode Events must be translated into rising/falling edges on PAI to be counted PAMOD=, counts active edge of PAI Can cause interrupts after N events writing N s 2 s compliment to PACNT Can count more than 256 events by tracking the number of overflows. Example: a work piece counter on an assembly line can be realized using a light emitter/detector pair.

Event Counting Mode PAMOD= Counts Active Edge of PAI pin PA7/ PAI/ OC 8-BIT COUNTER PACNT Example: (PACNT=;PAEN=;PEDGE=) PAI PACNT Value 2 3 4 Pulse Accumulator Gate Time Accumulation Mode PACNT increments every 64 th E-clock cycle when PAI pin is active. PAMOD=, PEDGE controls the inhibiting PAI pin level Can be used to accumulate the total time the pin was active over a series of pulses A common use is to measure pulse width (easier than using IC) Interrupt function: Overflow interrupt is useful in generating signals longer than the 8- bit counter range PAI edge interrupt is useful for signaling the end of a timing period

Gated Time Accumulation Mode PAMOD= Free-running E-clock divided by 64 Subject to PAI pin being active E/64 CLOCK (from Main Timer) Clock PA7/ PAI/ OC AND 8-BIT COUNTER PACNT Gated Time Example PACNT=;PAEN=;PEDGE= PEDGE= means inhibit gate is (inhibit counting when PAI is ) E/64 PAI PACNT Value 2 3 4 5 6

Pulse Accumulator Example: Generate interrupt at specified time Using gated time accumulation (PAMOD=) to set pulse accumulator to interrupt after 5ms Calculate time for one E/64 cycle Divide delay by time for one E/64 cycle Take 2 s complement and store in PACNT When input goes to active level, counter will increment until overflow Pulse Width Measurement Common use of Gated mode Measure duration of single pulses Easier than with Input Capture Counter is zero before pulse starts Pulse time is directly read after rising edge of pulse (need starting and ending count for input capture)

Assembly Code: Initialization to Count Negative Edges LDAA #BIT54HI STAA TFLG2 /*Clear previous interrupts*/ LDAA TMSK2 ORAA #BIT54HI /*Enable pulse accumulator interrupts*/ STAA TMSK2 LDAA PACTL ANDA #BIT7_4LO /*BIT7_4LO = % */ ORAA #BIT6HI STAA PACTL /*Select Event,Falling Edge,DDRA7- Input*/ References. M68HC E Series Technical Data 2. M68HC Reference Manual 3. Introduction to Mechatronics and Measurement Systems David G. Alciatore, Michael b. Histand 4. Software and Hardware Engineering Motorola M68HC Frederick M. Cady Questions?