1 / 52

Timers

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.

devaki
Télécharger la présentation

Timers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ME4447 INTRODUCTION TO MECHATRONICS Timers Anthony Wingo Carlos Alzate Jim Kitchen

  2. Introduction Anthony Wingo……………A brief look back in time Carlos Alzate……………....555 chip and applications Jim Kitchen………………..HC11 and timing functions

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

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

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

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

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

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

  9. Weight driven clock from 1270s and probably Europe. Time of invention as well as inventor is still unknown.

  10. Spring driven clock from around 15th century A.D. Bringing the tower clocks into homes. Prone to inaccuracy due to the mainspring

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

  12. Quartz watch Marrison and Horton in 1927 Quartz to be discussed later in the 555 section.

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

  14. 555 Timer • What is the 555 Timer • 555 schematic • Pin Configurations • Monostable Mode • Astable Mode

  15. What is the 555 Timer? • Integrated Circuit • Transistors, Diodes, Resistors • Designed and invented in 1970 by Hans R. Camezind

  16. Pin Configurations

  17. Monostable Mode

  18. Monostable Output Voltage

  19. 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:

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

  21. Astable Mode

  22. Astable Output Voltage

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

  24. Astable Characteristics • Outputs continuous stream of pulses • Triggers from previous output pulse • Frequency of series of pulses

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

  26. HC11 Timer Functions Fast Fact: Of 64 Register on the HC11, 29 are used for timing functions

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

  28. Port A Port A $1000 • PA7 direction is changed by setting DDRA7 • PA3 direction and function is changed by setting DDRA3 and I4/O5 7 6 5 4 3 2 1 0 $1026 PACTL DDRA7 PAEN PAMOD PEDGE DDRA3 I4/O5 RTR1 RTR0

  29. 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 $100E TCNT $100F Bit 7 - - - - - - Bit 0

  30. 7 6 5 4 3 2 1 0 TFLG2 TOF RTIF PAOVF PAIF 0 0 0 0 $1025 7 6 5 4 3 2 1 0 TMSK2 TOI RTII PAOVI PAII 0 0 PR1 PR0 $1024 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

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

  32. 7 6 5 4 3 2 1 0 TMSK2 TOI RTII PAOVI PAII 0 0 PR1 PR0 $1024 Measuring Long Times: Prescaler • Prescaler is set with bits PR1 and PR0

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

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

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

  36. 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 $1010 TIC1 $1011 Bit 7 - - - - - - Bit 0 Bit 15 - - - - - - Bit 8 $1012 TIC2 $1013 Bit 7 - - - - - - Bit 0 Bit 15 - - - - - - Bit 8 $1014 TIC3 $1015 Bit 7 - - - - - - Bit 0

  37. 7 6 5 4 3 2 1 0 TCTL2 EDG4B EDG4A EDG1B EDG1A EDG2B EDG2A EDG3B EDG3A $1021 Inputs: Input Capture • Which edge to capture on can be configured with the TCTL2 register

  38. 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0 TMSK1 TFLG1 OC1F OC1I OC2F OC2I OC3I OC3F OC4I OC4F OC5F OC5I IC1I IC1F IC2I IC2F IC3F IC3I $1023 $1022 Inputs: Input Capture • Flags are set when a capture is made • Interrupts can be generated if the mask bits are set

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

  40. B7 B0 B7 B6 B5 B4 DDR A7 PA EN PA MOD PA EDGE Inputs: Pulse Accumulator • PACNT $1027 • 8 Bit PA Count • PACTL $1026 • Data Direction for PA7 Pin • PA Enable • PA Mode • PA Edge

  41. B5 B4 PA OVF PA IF B5 B4 PA OVI PA II Inputs: Pulse Accumulator • TFLG2 $1025 • PA Overflow Flag • PA Input Edge Flag • TMSK2 $1024 • PA Overflow Interrupt Enable • PA Input Edge Interrupt Enable

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

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

  44. Output Compare 2 PA6 Output Compare 3 PA5 Output Compare 4 PA4 Output Compare 5 PA3 OM2 OL2 OM3 OL3 OM4 OL4 OM5 OL5 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 TCTL1 $1020

  45. OC1M7 OC1D7 OC1M6 OC1D6 OC1D5 OC1M5 OC1M4 OC1D4 OC1M3 OC1D3 0 0 0 0 0 0 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 PA7 PA6 PA5 PA4 PA3 OC1M $100C OC1D Register sets value to be written to Port A pins selected in OC1M OC1D $100D

  46. TMSK1 $1022 TFLG1 $1023 OC1F OC1I OC2I OC2F OC3F OC3I OC4F OC4I OC5I OC5F IC1F IC1F IC1F IC1F IC1F IC1F Output Compare 1 Output Compare 1 Output Compare 2 Output Compare 2 Output Compare 3 Output Compare 3 Output Compare 4 Output Compare 4 Output Compare 5 Output Compare 5 Outputs: Output Compare • When Output Compare is successful it sets corresponding Flag in TFLG1 Control Register: • It can also generate an interrupt if the appropriate mask bits are set

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

  48. B6 RTII B6 RTIF B1 B0 RTR1 RTR0 Outputs: Real-Time Interrupt • TMSK2 $1024 • Real-Time Interrupt Enable • TFLG2 $1025 • Real-Time Interrupt Flag • PACTL $1026 • Real-Time Interrupt Rate Selects

  49. Outputs: Real-Time Interrupts For 8MHz Crystal Frequency (2MHz E Clock)

More Related