Beruflich Dokumente
Kultur Dokumente
Slide 1
Outline
Introduction
What is a timer? How does it work? Types
Introduction to Timers
Slide 3
Introduction
What is a timer?
A timer is an integrated circuit that uses an oscillator measure elapsed time or count/time an external event
What is an oscillator?
Oscillators are used to generate a signal that can regenerate and sustain itself Usually made of quartz crystal
ME 6405, Timers Lecture, S. Hutcherson, P. Michel, M. Slide 4
Introduction
How Does It Work?
Applying a direct current to the crystal causes it to vibrate The oscillators frequency is determined by the thickness and cut of the quartz The frequency can also be set by using ME 6405, Timers Lecture, S. Hutcherson, P. Michel, M. combinations of
Metallic electrodes
Slide 5
Timers
An external capacitor is used to determine the off-on time intervals of the output pulses for all IC timers The time required for the capacitor to charge to 63.7% of the applied voltage is the time
= R C
Slide 6
Example:
R = 1M C = 1 F = 1,000,000 ME 6405, Timers Lecture, S. Hutcherson, P. Michel, M. 0.000001
Slide 7
Timer Types
Also Known As: Multivibrator
Multivibrators are a class of circuits that are designed to produce square waves or pulses.
Slide 10
Slide 11
Slide 12
t2 R2+ R2 D= = t R2+ 2 2 R
Slide 15
Pin 2 Trigger
Input to the lower comparator and is used to set the latch which causes the output to go high Triggering happens when the voltage level is taken from above to below a voltage level of 1/3 V+
ME 6405, Timers Lecture, S. Hutcherson, P. Michel, M. Slide 17
Pin 4 Reset
Used to reset the latch and return the output to a low state The reset voltage threshold is 0.7V+, and ME 6405, Timers Lecture, S. Hutcherson, P. Michel, M. Slide 18 a sink current of 0.1mA
Pin 6 Threshold
Input into the upper comparator Used to reset the latch, which drives the output low
ME 6405, Timers Lecture, S. Hutcherson, P. Michel, M. Slide 19
Pin 8 V+
The positive supply voltage terminal to the 555 timer IC ME 6405, Timers Lecture, S. Hutcherson, P. Michel, M. Slide 20
Slide 24
Slide 25
Main Timer
16-bit free running counter
TCN T
Bit 15 Bit 7
Bit 8 Bit 0
$10 $10 0E 0F
It is a read only register using a double-byte instruction like LDD or LDX It is cleared on reset and count up continuously When $FFFF is reached, counter rolls over to $0000 ME 6405, Timers Lecture, S. Hutcherson, P. Michel, M. Slide 26
Counter Prescaler
Allows 4 clocking rates Bus Frequency of the timer counter (E Clock) PR PR E-Clock rate divided Presc 2 MHz aler 1 0 by: 1, 4, 8, 16 Resolutio Range n At reset the default (Overflow (one ) 1 500 ns 32.77 0 0 prescale factor is 1 count) ms 2 s 1 0 Must be set during the 4 131.1 8 4 s 1 0 first 64 E-Clock cycles ms 16 8 s 1 1 after reset 262.1
ms 524.3 ms
ME 6405, Timers Lecture, S. Hutcherson, P. Michel, M. Slide 28
Input Capture
Used to record the time an event occurs When an edge is detected at a timer input pin, the current value of the free-running counter is stored in the corresponding 16-bit input capture register
ME 6405, Timers Lecture, S. Hutcherson, P. Michel, M. Slide 29
Can be read at any time by a pair of 8bits registers Not affected by reset
Use Time Control Register (TCTTL2) to tell which edges you want to capture
7 6 5 4 3 2 1 0 EDG4B EDG4A EDG1B EDG1A EDG2B EDG2A EDG3B EDG3A
TCTL 2
$1021
Configuration
Capture Disabled Capture on Rising Edge Only Capture on Falling Edge Only Capture on Any Edge
EDGxB EDGxA
0 0 1 1 0 1 0 1
Slide 31
Input capture status flags are automatically set to one each time a selected 7 6 5 detected 1 0 edge is 4 3 2
TMS K1
7 6 5 4 3 2 1 0 OC1IOC2IOC3IOC4IOC5IIC1IIC2IIC3I
$1022
Slide 32
Output Compare
There are 5 output compare registers: TOC 1 TOC 2 TOC 3
Bit 15 Bit 7 Bit 15 Bit 7 Bit 15 Bit 7 Bit 15 Bit 7
Bit 8 Bit 0 Bit 8 Bit 0 Bit 8 Bit 0 Bit 8 Bit 0 Bit 8 Bit 0
$101 $101 6 7 $101 $101 8 9 $101 $101 A B $101 $101 C D $101 $101 E F Slide 33
Output capture status flags are automatically set to one each time the number stored in one of the compare registers is the same as the value of the main timer 6 5 4 3 2 1 0 7
TFLG 1
Output TMSK
When a successful output compare occurs, pin actions on OC2-OC5 of Port A can OC1 OC1 OC1 OC1 OC1 OC1M be done: $100C
M7 M6 M5 M4 M3
OC1D
OC1 D7
OC1 D6
OC1 D5
OC1 D4
OC1 D3
$100D
OM OL 5 5
TCTL1 OM OL
2 2
OMx OLx 2 2 2 2 2 2 2 2
OM OL 3 3
OM OL 4 4
$1020
Configuration OCx Does Not Affect Pin (OC2Still May) Toggle Ocx Pin on Successful Compare Clear Ocx Pin on Successful Compare Set Ocx Pin on Successsful Compare
Slide 35
Forced Output
If you need to change state of Port A Pin BEFORE output compare occurs use the Time Compare Force Register
FOC 1 FOC 2 FOC 3 FOC 4 FOC 5 0 0 0 CFOR C $100 B
Output Output Output Output Output Compa Compa Compa Compa Compa re 1 re 2 re 3 re 4 re 5
Slide 36
Real-Time Interrupt
Generates hardware interrupts at a fixed B1 B0 periodic rate with: RTR RTR $1026 PACTL
RTR1 RTR0 E/213 Divided By 0 0 1 1 0 1 0 1 1 2 4 8 Nominal RTI Rate 4.10 ms 8.19 ms 16.38 ms 32.77 ms
Slide 37
TMSK2 $1024
Real-Time Interrupt Enable
B6
RTII
TFLG2 $1025
Real-Time Interrupt Flag
B6
RTIF
Slide 38
Pulse Accumulator
8-bit Counter 2 operating modes
Event counting mode Gated time accumulation mode
Slide 39
Registers
PACNT $1027
8 Bit PA Count
B7 B0
PACTL $1026
Data Direction for PA7 Pin B7 PA Enable DDR A7 PA Mode PA Edge
B6 PA EN B5 PA MOD B4 PA EDG E
Slide 40
TFLG2 $1025
PA Overflow Flag PA Input Edge Flag
B4 B5 PA OVF PA IF
TMSK2 $1024
PA Overflow Interrupt Enable PA Input Edge Interrupt Enable
B5 PA OVI
B4 PA II
Slide 41
Slide 42
Applications of Timers
Timers are used for a variety of applications in many situations Required for any application requiring real-time control Can be used for both input and output timing Often multiple timers are needed for the various functions required for real-time control Timers are basically everywhere you look: watches, household appliances, ME 6405, Timers Lecture, S. Hutcherson, P. Michel, M. Slide 43 manufacturing systems, basically
Applications of Timers
Pulse Width Modulation (PWM) is a very common method of generating an analog signal
Requires the use of timers as well as interrupts Can be used to run DC motors
The OC1 system is unique and should not be used as the other output compare systems
Slide 46
Example: Generate a 1KHz square wave form signal with a 40% duty cycle (width of high pulse is 40% of total period). A flowchart of the procedure is shown at left
Taken from: H. Huang, MC68HC11:AnIntroduction
Set OC2 pin to high Set OC2 action to toggle Clear OC2F flag start OC2 output compare with a delay of 400 s no OC2F = 1? yes Clear OC2F flag Start OC2 output compare with a delay of 600 s OC2F = 1? yes
no
Slide 48
$40 $BF
high
; ; ; ; ; ; ; ; ; ; : ; ;
set OC2 pint to high clear OC2F flag select output compare action to be toggle start an OC2 operation which toggles the OC2 pin with a delay of 800 E clock cycles wait until OC2F is set to 1 clear OC2F flag start another OC2 operation which toggles the OC2 pin with a delay of 1200 E cycles
Slide 49
Original code taken from: H. Huang, MC68HC11:AnIntroduction Modified for the Axiom CME-11E9-EVBU
It can be seen with more modification, a varying duty cycle can be used, such as one that generates a sine wave
Slide 50
Slide 51
Slide 52
Slide 53
References
van Roon, Tony. 555 Timer Tutorial. http://www.uoguelph.ca/~antoon/ga dgets/555/555.html Huang, Han. MC68HC11:An Introduction Spasov, Peter. Microcontroller Technology: The 68HC11
ME 6405, Timers Lecture, S. Hutcherson, P. Michel, M. Slide 54