Download Timers

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Pulse-width modulation wikipedia , lookup

Solar micro-inverter wikipedia , lookup

Buck converter wikipedia , lookup

Schmitt trigger wikipedia , lookup

Integrating ADC wikipedia , lookup

Power electronics wikipedia , lookup

Switched-mode power supply wikipedia , lookup

Flip-flop (electronics) wikipedia , lookup

Time-to-digital converter wikipedia , lookup

Metadyne wikipedia , lookup

Immunity-aware programming wikipedia , lookup

Opto-isolator wikipedia , lookup

Transcript
ME4447
INTRODUCTION TO MECHATRONICS
Timers
Anthony Wingo
Carlos Alzate
Jim Kitchen
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.
Sundial from about 16th century B.C.
Provides earliest evidence of day and night seperation
Had to be made for specific latitudes
A look at how the timer
has evolved.
Sundial from about 16th century B.C.
The sundial works fine, if it is used on an unclouded day.
Clepsydra from about 15th 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.
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.
Quartz watch
Marrison and Horton in 1927
Quartz to be discussed later in the 555 section.
Cesium atomic clock
Britain's National Lab 1955
Most accurate of any time-keeping device described.
Accuracy of 2 nanoseconds/day or 1 second per 1,400,000 years.
Not very portable or cost efficient in small projects
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
Pin Configurations
Monostable Mode
Monostable Output Voltage
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:
t p  1.1 R C
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
Astable Mode
Astable Output Voltage
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
1
f 
t h  tl
t h  duration the output pin stays high
 0.693 C R1  R2 
tl  0.693 C R2
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
Fast Fact:
Of 64 Register on the HC11,
29 are used for timing functions
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
OC1
Port A
OC1
OC1
OC1
OC1
IC1
IC2
IC3
PA2
PA1
PA0
PAI
OC2
OC3
OC4
OC5/
IC4
PA7
PA6
PA5
PA4
PA3
$1000
•PA7 direction is changed by setting DDRA7
•PA3 direction and function is changed by setting DDRA3 and I4/O5
7
PACTL
6
5
4
3
2
1
0
DDRA7 PAEN PAMOD PEDGE DDRA3 I4/O5 RTR1 RTR0
$1026
Main Timer
• The HC11 Timer is a 16-bit read-only register
Bit 15
-
-
-
-
-
-
Bit 8
Bit 7
-
-
-
-
-
-
Bit 0
TCNT
$100E
$100F
• Rolls over (overflows) from $FFFF to $0000
every 0.5μs*216 = 32.768ms
Main Timer
• When the main timer overflows, the TOF flag is
set
7
TFLG2
TOF
6
5
4
RTIF PAOVF PAIF
3
2
1
0
0
0
0
0
$1025
• If the TOI bit is set, an overflow will also
generate an interrupt
7
TMSK2
TOI
6
5
4
RTII PAOVI PAII
3
2
1
0
0
0
PR1
PR0
$1024
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
•Prescaler is set with bits PR1 and PR0
7
TMSK2
TOI
6
5
4
RTII PAOVI PAII
3
2
0
0
1
0
PR1 PR0
$1024
E Clock = 2MHz
Prescale
Factor
1
4
8
16
Resolution
(one count)
Range
(Overflow)
Frequency
(Overflow)
0.5 ms
2.0 ms
4.0 ms
8.0 ms
32.77 ms
131.1 ms
262.1 ms
524.3 ms
30.5 Hz
7.63 Hz
3.82 Hz
1.91 Hz
PR1
PR0
0
0
1
1
0
1
0
1
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 0
Bit 15
-
-
-
-
-
-
Bit 8
$1012
Bit 7
-
-
-
-
-
-
Bit 0
$1013
Bit 15
-
-
-
-
-
-
Bit 8
Bit 7
-
-
-
-
-
-
Bit 0
$1014
$1015
TIC1
TIC2
TIC3
$1010
$1011
Inputs: Input Capture
• Which edge to capture on can be configured with
the TCTL2 register
7
TCTL2
6
5
4
3
2
1
0
EDG4B EDG4A EDG1B EDG1A EDG2B EDG2A EDG3B EDG3A
Configuration
EDGxB EDGxA
Capture Disabled
0
0
Capture on Rising Edge Only
0
1
Capture on Falling Edge Only
1
0
Capture on Any Edge
1
1
$1021
Inputs: Input Capture
• Flags are set when a capture is made
7
TFLG1
6
5
4
3
2
1
0
OC1F OC2F OC3F OC4F OC5F IC1F IC2F IC3F
$1023
• Interrupts can be generated if the mask bits are
set
7
TMSK1
6
5
4
3
2
1
0
OC1I OC2I OC3I OC4I OC5I IC1I IC2I IC3I
$1022
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
B7
B0
– 8 Bit PA Count
• PACTL $1026
–
–
–
–
Data Direction for PA7 Pin
PA Enable
B7
PA Mode
DDR
A7
PA Edge
B6
B5
B4
PA EN
PA
MOD
PA
EDGE
Inputs: Pulse Accumulator
• TFLG2 $1025
– PA Overflow Flag
– PA Input Edge Flag
B5
B4
PA
OVF
PA
IF
B5
B4
PA
OVI
PA
II
• TMSK2 $1024
– PA Overflow Interrupt Enable
– PA Input Edge Interrupt
Enable
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
Register Name
TOC1
TOC2
TOC3
TOC4
TOC5
Address
$1016 and $1017 $1018 and $1019 $101A and $101B $101C and $101D $101E and $101F
•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
Outputs: Output Compare
•For Output Compare 2-5, Each Compare Register
controls a single pin
Output Compare 2
Output Compare 3
Output Compare 4
Output Compare 5
PA6
PA5
PA4
PA3
•TCTL1 register determines how each pin changes
when the comparison matches
TCTL1 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
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
OC1M Register determines which Port A Pins will be Controlled
by Output Compare 1
OC1D Register sets
value to be written
to Port A pins
selected in OC1M
PA7
PA6
PA5
PA4
PA3
OC1M7
OC1M6
OC1M5
OC1M4
OC1M3
0
0
0
OC1M
$100C
OC1D7
OC1D6
OC1D5
OC1D4
OC1D3
0
0
0
OC1D
$100D
Outputs: Output Compare
•When Output Compare is successful it sets corresponding
Flag in TFLG1 Control Register:
OC1F OC2F OC3F OC4F OC5F
Output
Compare
1
IC1F
IC1F
IC1F
TFLG1
$1023
Output
Output Output
Output
Compare Compare Compare Compare
2
3
4
5
•It can also generate an interrupt if the appropriate mask bits are
set
OC1I OC2I OC3I
Output
Compare
1
OC4I OC5I
Output
Output Output
Output
Compare Compare Compare Compare
2
3
4
5
IC1F
IC1F
IC1F
TMSK1
$1022
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
B6
RTII
B6
RTIF
B1
B0
RTR1 RTR0
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/55
5.html
• http://www.electronicstutorials.com/devices/555.htm
• http://www.williamson-labs.com/480_555.htm
• The “Crazy J” Groups Timer Slides
• M68HC11 Reference Manual