+ All Categories
Home > Documents > Timer_S05

Timer_S05

Date post: 03-Jun-2018
Category:
Upload: ramanaidu1
View: 219 times
Download: 0 times
Share this document with a friend
52
Timers ME4447 INTRODUCTION TO MECHATRONICS Anthony Wingo Carlos Alzate Jim Kitchen
Transcript
Page 1: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 1/52

Timers

ME4447

INTRODUCTION TO MECHATRONICS

Anthony Wingo

Carlos Alzate

Jim Kitchen

Page 2: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 2/52

Page 3: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 3/52

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.

Page 4: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 4/52

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.

Page 5: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 5/52

Page 6: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 6/52

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.

Page 7: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 7/52

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.

Page 8: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 8/52

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.

Page 9: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 9/52

Weight driven clock from 1270s and probably Europe.

Time of invention as well as inventor is still unknown.

Page 10: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 10/52

Spring driven clock from around 15th century A.D.

Bringing the tower clocks into homes.

Prone to inaccuracy due to the mainspring

Page 11: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 11/52

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.

Page 12: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 12/52

Page 13: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 13/52

Cesium atomic clock

Britain'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.

Page 14: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 14/52

555 Timer

• What is the 555 Timer

• 555 schematic• Pin Configurations

• Monostable Mode

•  Astable Mode

Page 15: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 15/52

What is the 555 Timer?

• Integrated Circuit

• Transistors, Diodes, Resistors

• Designed and invented in 1970 by HansR. Camezind

Page 16: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 16/52

Page 17: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 17/52

Pin Configurations

Page 18: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 18/52

Monostable Mode

Page 19: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 19/52

Monostable Output Voltage

Page 20: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 20/52

Monostable Characteristics

• Generates a single pulse of a fixed timeduration each time it receives an inputtrigger pulse

• Length of pulse depends on when thecapacitor reaches 66.6% V

• Length of pulse is given by:

C  Rt  p 1.1

Page 21: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 21/52

Monostable Applications

• Turning a circuit or external componenton / off for a specific length of time

• Generate delays

• Multiple pulses can be used to time andsequence other related applications

Page 22: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 22/52

 Astable Mode

Page 23: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 23/52

 Astable Output Voltage

Page 24: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 24/52

 Animation

http://www.williamson-labs.com/480_555.htm 

Page 25: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 25/52

 Astable Characteristics

• Outputs continuous stream of pulses• Triggers from previous output pulse

• Frequency of series of pulses

2

21

693.0

693.0 

1

highstays pinoutputheduration t

 RC t 

 R RC t 

t t  f  

h

l h

Page 26: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 26/52

 Astable Applications

• Create an accurate clock signal

• Modulate transmitters such as ultrasonicand IR transmitters

• Turn on / off actuator at set intervals for afixed duration

Page 27: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 27/52

HC11 Timer Functions

Fast Fact:Of 64 Register on the HC11,

29 are used for timing functions

Page 28: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 28/52

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

Page 29: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 29/52

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

Page 30: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 30/52

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- - - - -

- - - - - -

Page 31: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 31/52

Main Timer

• When the main timer overflows, the TOF flag isset

• If the TOI bit is set, an overflow will alsogenerate an interrupt

TOF RTIF 0TFLG2 $1025PAOVF PAIF 0 0 0

01234567

TOI RTII PR0TMSK2 $1024PAOVI PAII 0 0 PR1

01234567

Page 32: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 32/52

Measuring Long Times: Prescaler

• The prescaler will slow down theincrements of the main timer, allowing forrecording 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 cyclesafter reset

• Trade-off between resolution and timebetween overflows

Page 33: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 33/52

Measuring Long Times: Prescaler

TOI RTII PR0TMSK2 $1024PAOVI PAII 0 0 PR1

01234567

PrescaleFactor

E Clock = 2MHz

PR1 PR0Resolution

(one count)

Range

(Overflow)

Frequency

(Overflow)

1

4

8

16

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

0

0

1

1

0

1

0

1

•Prescaler is set with bits PR1 and PR0

Page 34: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 34/52

Measuring Long Times: 24-bit time

• 24-bit time can be used to extend therange of the timer

•  Accomplished by storing the # of overflowsthat have occurred in a memory location

• Store and compare 24-bit times: increasesthe range from 32.8 ms to 8.4 s

• Better resolution than prescaler, butharder to implement

Page 35: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 35/52

Page 36: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 36/52

Important Note

• In almost all timer functions, severalcommon things happen

 – A flag is set (must be cleared by user)

 – An interrupt can be generated (optional)

 – An event happens, dependent on the functionbeing used

Page 37: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 37/52

Inputs: Input Capture

• Used to record the clock time when an edge is detectedon one of the input pins

• The time is stored in a register (read-only) by storing thecontents of the free-running counter in the input captureregisters (16-bits)

Bit 15 - Bit 8

Bit 7 Bit 0

TIC1$1011

$1010

Bit 15 Bit 8

Bit 7 Bit 0

TIC2$1013$1012

Bit 15 Bit 8

Bit 7 Bit 0

TIC3

$1015

$1014

- - - - -

- -- - - -

- - - - - -

- -- - - -

- - - - - -

- -- - - -

Page 38: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 38/52

Inputs: Input Capture

Configuration EDGxB EDGxA

Capture Disabled 0 0Capture 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 withthe TCTL2 register

Page 39: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 39/52

Inputs: Input Capture

• Flags are set when a capture is made

• Interrupts can be generated if the mask bits are

set

OC1F OC2F IC3F

TFLG1 $1023OC3F OC4F OC5F IC1F IC2F

01234567

OC1I OC2I IC3ITMSK1 $1022OC3I OC4I OC5I IC1I IC2I

01234567

Page 40: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 40/52

Inputs: Pulse Accumulator

• The pulse accumulator is an 8-bit counter(read and writeable)

• It will count the # of pulses coming intoPA7 when configured to do so

• It can also be used to measure the pulsewidth

Page 41: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 41/52

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 ENPA

MOD

PAEDGE

B4

DDR A7

B7

Page 42: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 42/52

Inputs: Pulse Accumulator

• TFLG2 $1025 – PA Overflow Flag

 – PA Input Edge Flag

• TMSK2 $1024 – PA Overflow Interrupt Enable

 – PA Input Edge InterruptEnable

PA

OVF

PA

IF

B4B5

PA

OVI

PA

II

B4B5

Page 43: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 43/52

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

Page 44: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 44/52

Page 45: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 45/52

Outputs: Output Compare

•For Output Compare 2-5, Each Compare Registercontrols a single pin

•TCTL1 register determines how each pin changes

when the comparison matches

Output Compare 2 PA6

Output Compare 3 PA5

Output Compare 4 PA4

Output 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

Page 46: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 46/52

Page 47: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 47/52

Outputs: Output Compare

•When Output Compare is successful it sets correspondingFlag in TFLG1 Control Register:

OC1F OC2F OC3F OC4F OC5F IC1F IC1F IC1FTFLG1

$1023

OutputCompare

1

OutputCompare

2

OutputCompare

3

OutputCompare

4

OutputCompare

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

Page 48: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 48/52

Outputs: Real-Time Interrupt

• Similar to the prescalar concept

• Generates hardware interrupts at one offour fixed rates

• Sets a flag at each interrupt• Easier to use than generating output

comparisons each time

• Limited to only 4 specific rates

Page 49: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 49/52

Outputs: Real-Time Interrupt

• TMSK2 $1024

 – Real-Time InterruptEnable

• TFLG2 $1025

 – Real-Time InterruptFlag

• PACTL $1026 – Real-Time Interrupt

Rate Selects

RTII

B6

RTIF

B6

B0

RTR0RTR1

B1

Page 50: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 50/52

Outputs: Real-Time Interrupts

For 8MHz Crystal Frequency

(2MHz E Clock)

RTR1 RTR0 E/2

13

 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

Page 51: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 51/52

Outputs

•  Applications:

 – Pulse Width Modulation with OutputCompares

 – 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

Page 52: Timer_S05

8/12/2019 Timer_S05

http://slidepdf.com/reader/full/timers05 52/52

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.electronics-

tutorials.com/devices/555.htm

• http://www.williamson-labs.com/480_555.htm• The “Crazy J” Groups Timer Slides 

• M68HC11 Reference Manual