Upload
job-owens
View
220
Download
2
Embed Size (px)
Citation preview
Introduction
Anthony Wingo……………A brief look back in time
Carlos Alzate……………....555 chip and applications
Jim Kitchen………………..HC11 and timing functions
A look at how the timer has evolved.
Provides earliest evidence of day and night seperation
Had to be made for specific latitudes
Sundial from about 16th century B.C.
The sundial works fine, if it is used on an unclouded day.
A look at how the timer has evolved.
Sundial from about 16th century B.C.
The clepsydra was an improvement over the sundial. This device could be used during the day or night.
Adjustments could be made to account for seasonal changes.Could be used only to measure pre-determined periods of time.
Clepsydra from about 15th century B.C.
Astrolabe from about 2nd century A.D.
Has ability to find and measure time
Based on map constructed by Hipparchus around 150 B.C.
Helped in construction of sundials.
Candle Clock from about 9th century A.D.
Inserting a nail at a pre-determined location, the candle clock could be used as a timer.
Imagine interfacing this idea with the HC11.
Hour Glass came probably from Europe before the 14th century.
The medium flowed from one end through a passage that is 10 times larger than the medium particles.
Sailors used the hour glass to calculate speed at sea.
Weight driven clock from 1270s and probably Europe.
Time of invention as well as inventor is still unknown.
Spring driven clock from around 15th century A.D.
Bringing the tower clocks into homes.
Prone to inaccuracy due to the mainspring
Pendulum Clock by Christiaan Huygens in 1656
First clock to count seconds.
Galileo started the idea but died before implementing it.
Accuracy was increased to a loss of only a few seconds per day.
Cesium atomic clockBritain's National Lab 1955
Most accurate of any time-keeping device described.
Not very portable or cost efficient in small projects
Accuracy of 2 nanoseconds/day or 1 second per 1,400,000 years.
555 Timer
• What is the 555 Timer
• 555 schematic
• Pin Configurations
• Monostable Mode
• Astable Mode
What is the 555 Timer?
• Integrated Circuit
• Transistors, Diodes, Resistors
• Designed and invented in 1970 by Hans R. Camezind
Monostable Characteristics
• Generates a single pulse of a fixed time duration each time it receives an input trigger pulse
• Length of pulse depends on when the capacitor reaches 66.6% V
• Length of pulse is given by:
CRt p 1.1
Monostable Applications
• Turning a circuit or external component on / off for a specific length of time
• Generate delays
• Multiple pulses can be used to time and sequence other related applications
Animation
http://www.williamson-labs.com/480_555.htm
Astable Characteristics• Outputs continuous stream of pulses
• Triggers from previous output pulse
• Frequency of series of pulses
2
21
693.0
693.0
1
high stayspin output heduration t
RCt
RRC
t
ttf
l
h
lh
Astable Applications
• Create an accurate clock signal
• Modulate transmitters such as ultrasonic and IR transmitters
• Turn on / off actuator at set intervals for a fixed duration
HC11 Timer Functions• Port A• Main Timer• Measuring Long Times
– Prescaler– 24-bit time
• Inputs– Input Capture– Pulse Accumulator
• Outputs– Output Compare– Real Time Interrupts
Port A
PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0Port A $1000
OC1 OC1 OC1 OC1 OC1
PAI OC2 OC3 OC4OC5/ IC4 IC1 IC2 IC3
DDRA7 PAEN RTR0PACTL $1026PAMOD PEDGE DDRA3 I4/O5 RTR1
01234567
•PA7 direction is changed by setting DDRA7
•PA3 direction and function is changed by setting DDRA3 and I4/O5
Main Timer
• The HC11 Timer is a 16-bit read-only register
• Rolls over (overflows) from $FFFF to $0000 every 0.5μs*216 = 32.768ms
Bit 15 - Bit 8
Bit 7 Bit 0TCNT
$100F
$100E- - - - -
- - - - - -
Main Timer
• When the main timer overflows, the TOF flag is set
• If the TOI bit is set, an overflow will also generate an interrupt
TOF RTIF 0TFLG2 $1025PAOVF PAIF 0 0 0
01234567
TOI RTII PR0TMSK2 $1024PAOVI PAII 0 0 PR1
01234567
Measuring Long Times: Prescaler
• The prescaler will slow down the increments of the main timer, allowing for recording of longer time intervals
• E-Clock rate is divided by: 1, 4, 8, or 16 – Default prescale factor is 1– Must be set during the first 64 E-Clock cycles
after reset
• Trade-off between resolution and time between overflows
Measuring Long Times: Prescaler
TOI RTII PR0TMSK2 $1024PAOVI PAII 0 0 PR1
01234567
Prescale Factor
E Clock = 2MHz
PR1 PR0Resolution
(one count)
Range
(Overflow)
Frequency
(Overflow)
1
4
8
16
0.5 s
2.0 s
4.0 s
8.0 s
32.77 ms
131.1 ms
262.1 ms
524.3 ms
30.5 Hz
7.63 Hz
3.82 Hz
1.91 Hz
0
0
1
1
0
1
0
1
•Prescaler is set with bits PR1 and PR0
Measuring Long Times: 24-bit time
• 24-bit time can be used to extend the range of the timer
• Accomplished by storing the # of overflows that have occurred in a memory location
• Store and compare 24-bit times: increases the range from 32.8 ms to 8.4 s
• Better resolution than prescaler, but harder to implement
Measuring Long Times: 24-bit time
• If you only need to measure one long time, store the timer reading at t1 (16-bit), and reset the # of overflows counter
• When the final time is recorded, calculate the time elapsed by:
t = (t2 – t1) + (# of overflows)*216
Important Note
• In almost all timer functions, several common things happen– A flag is set (must be cleared by user)– An interrupt can be generated (optional)– An event happens, dependent on the function
being used
Inputs: Input Capture• Used to record the clock time when an edge is detected
on one of the input pins• The time is stored in a register (read-only) by storing the
contents of the free-running counter in the input capture registers (16-bits)
Bit 15 - Bit 8
Bit 7 Bit 0TIC1
$1011
$1010
Bit 15 Bit 8
Bit 7 Bit 0TIC2
$1013
$1012
Bit 15 Bit 8
Bit 7 Bit 0TIC3
$1015
$1014
- - - - -
- -- - - -
- - - - - -
- -- - - -
- - - - - -
- -- - - -
Inputs: Input Capture
Configuration EDGxB EDGxACapture Disabled 0 0
Capture on Rising Edge Only 0 1
Capture on Falling Edge Only 1 0
Capture on Any Edge 1 1
EDG3ATCTL2 $1021
01234567
EDG3BEDG2AEDG2BEDG1AEDG1BEDG4AEDG4B
• Which edge to capture on can be configured with the TCTL2 register
Inputs: Input Capture
• Flags are set when a capture is made
• Interrupts can be generated if the mask bits are set
OC1F OC2F IC3FTFLG1 $1023OC3F OC4F OC5F IC1F IC2F
01234567
OC1I OC2I IC3ITMSK1 $1022OC3I OC4I OC5I IC1I IC2I
01234567
Inputs: Pulse Accumulator
• The pulse accumulator is an 8-bit counter (read and writeable)
• It will count the # of pulses coming into PA7 when configured to do so
• It can also be used to measure the pulse width
Inputs: Pulse Accumulator
• PACNT $1027– 8 Bit PA Count
• PACTL $1026– Data Direction for PA7 Pin– PA Enable – PA Mode– PA Edge
B7 B0
B6 B5
PA EN
PA
MODPA
EDGE
B4
DDR A7
B7
Inputs: Pulse Accumulator
• TFLG2 $1025– PA Overflow Flag – PA Input Edge Flag
• TMSK2 $1024– PA Overflow Interrupt Enable– PA Input Edge Interrupt
Enable
PA
OVF
PA
IF
B4 B5
PA
OVI
PA
II
B4 B5
Inputs
• Applications:– User input (buttons, etc.)– Counting events (products on an assembly
line with pulse accumulator)– Length of input (how long a button is held)
• Morse Code
Outputs: Output Compare
•Output compare lets you change an output pin when the main timer matches a specified time
•Along with the output pin, output compare will set a flag, and optionally generate an interrupt
•The comparison is done in hardware – basically free computing time
Register Name TOC1 TOC2 TOC3 TOC4 TOC5
Address $1016 and $1017 $1018 and $1019 $101A and $101B $101C and $101D $101E and $101F
Outputs: Output Compare•For Output Compare 2-5, Each Compare Register controls a single pin
•TCTL1 register determines how each pin changes when the comparison matches
Output Compare 2 PA6Output Compare 3 PA5Output Compare 4 PA4Output Compare 5 PA3
OM2 OL2 OM3 OL3 OM4 OL4 OM5 OL5 $1020
OMx OLx Pin Configuration
0 0 Do nothing to pin
0 1 Toggle pin on match
1 0 Clear pin on match
1 1 Set pin on match
TCTL1
Outputs: Output Compare
Output Compare 1:•Causes 5 Port A pins to change simultaneously (PA3-PA7)
•Notice PA3-PA6 are also used by Output Compares 2-5
OC1M7 OC1M6 OC1M5 OC1M4 OC1M3 0 0 0
OC1M Register determines which Port A Pins will be Controlled by Output Compare 1
OC1D7 OC1D6 OC1D5 OC1D4 OC1D3 0 0 0
OC1D Register sets value to be written to Port A pins selected in OC1M
PA7 PA6 PA5 PA4 PA3OC1M$100C
OC1D$100D
Outputs: Output Compare•When Output Compare is successful it sets corresponding Flag in TFLG1 Control Register:
OC1F OC2F OC3F OC4F OC5F IC1F IC1F IC1FTFLG1$1023
Output Compare
1
Output Compare
2
Output Compare
3
Output Compare
4
Output Compare
5
OC1I OC2I OC3I OC4I OC5I IC1F IC1F IC1FTMSK1$1022
Output Compare
1
Output Compare
2
Output Compare
3
Output Compare
4
Output Compare
5
•It can also generate an interrupt if the appropriate mask bits are set
Outputs: Real-Time Interrupt
• Similar to the prescalar concept• Generates hardware interrupts at one of
four fixed rates• Sets a flag at each interrupt• Easier to use than generating output
comparisons each time• Limited to only 4 specific rates
Outputs: Real-Time Interrupt
• TMSK2 $1024– Real-Time Interrupt
Enable
• TFLG2 $1025– Real-Time Interrupt
Flag
• PACTL $1026– Real-Time Interrupt
Rate Selects
RTII
B6
RTIF
B6
B0
RTR0RTR1
B1
Outputs: Real-Time Interrupts
For 8MHz Crystal Frequency (2MHz E Clock)
RTR1 RTR0 E/213 Divided By RTI Rate RTI Frequency
0 0 1 4.10 ms 244 Hz
0 1 2 8.19 ms 122 Hz
1 0 4 16.38 ms 61.0 Hz
1 1 8 32.77 ms 30.5 Hz
Outputs
• Applications:– Pulse Width Modulation with Output
Compares– Create a delay, but use the wait productively
• Read the clock time• Create an output compare with an offset
– Drive a stepper motor with RTI
References/ Acknowledgements
• http://www.briticanna.com/clockworks• http://www.me.gatech.edu/mechatronics_lab/• http://www.uoguelph.ca/~antoon/gadgets/
555/555.html• http://www.electronics-tutorials.com/devices/
555.htm• http://www.williamson-labs.com/480_555.htm• The “Crazy J” Groups Timer Slides• M68HC11 Reference Manual