Published on

1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  2. 2. WHAT IS TIMER? <ul><li>In general, timer is nothing but a process of time being or time based operation. </li></ul><ul><li>When coming to microcontroller, timer is a set of registers together doing the same time being operations. </li></ul><ul><li>The difference is, in microcontroller the time being operation was depends on crystal oscillator we used in microcontroller. </li></ul>
  3. 3. Timers in 89C51 <ul><li>AT89c51 equipped with 2 timers, both of which may be controlled, set, read and configure individually. </li></ul><ul><li>They are called as timer 0 and timer 1. </li></ul>
  4. 4. Functions of timers <ul><li>There are three general functions the timers in 89C51 have </li></ul><ul><ul><li>Keeping time and calculating the amount of the time between the events </li></ul></ul><ul><ul><li>Counting the event themselves </li></ul></ul><ul><ul><li>Generating baud rate for serial communication. </li></ul></ul>
  5. 5. Measuring Time <ul><li>This is one of the primary work of the timers </li></ul><ul><li>Another one is counting the events </li></ul><ul><li>The meaning of the measuring the time is “measuring the interval time between two events”. </li></ul><ul><li>Therefore it can also called as “interval timers” . </li></ul>
  6. 6. Time required to do the process? <ul><li>Since we already explained that timer was running under the frequency of microcontroller’s crystal oscillator and the atmel has 12 Tcycles for each machine cycle. </li></ul><ul><li>When timer is in interval timer mode and correctly configured,it will increment by 1 for every machine cycle. </li></ul><ul><li>Thus running timer will be incremented </li></ul><ul><li>11,059,200 / 12 = 921,583 times. </li></ul>
  7. 7. Timer’s SFR <ul><li>As we mentioned earlier, in 8051 we have two timers </li></ul><ul><li>One is timer0 and another is timer1. </li></ul><ul><li>These two timers shares 2 SFRs </li></ul><ul><ul><li>TCON timer control </li></ul></ul><ul><ul><li>TMOD timer mode select </li></ul></ul><ul><li>Also these two timers have their own dedicated registers for sole purpose </li></ul><ul><ul><li>TL0 and TH0 for timer0 </li></ul></ul><ul><ul><li>TL1 and TH1 for timer1 </li></ul></ul>
  8. 8. TMOD SFR operation <ul><li>First we will discuss about TMOD.. </li></ul><ul><li>Each and every bit of the this mode will give an information to the microcontroller, how to run the timers. </li></ul><ul><li>The MSB 4 bits(4 through 7) are allocated for timer 1 </li></ul><ul><li>The LSB 4 bits(0 through 3) are allocated for timer 0 </li></ul><ul><li>Each 4 bits holds the information about the operation of timer </li></ul>
  9. 9. Mode 0 – 13 bit timer <ul><li>This is just a relic for microcontroller, which never used in any operation. </li></ul><ul><li>But for our knowledge, It is a13 bit mode, that means the TLx will count 0 to 31 and reset to 0 and increment 1 to THx, THx will increment like this upto 255. </li></ul><ul><li>Totally 13 bits are used and its limitation of data is 8192 values only. </li></ul><ul><li>If you set a 13-bit mode, it will overflow after 8192 machine cycle. </li></ul>
  10. 10. Mode 1 – 16 bit timer <ul><li>It is similar to mode 0 except it uses all 16 bits. </li></ul><ul><li>Therefore TLx increment from 0 to 255,when it reaches 255 it resets TLx and increment THx by 1. </li></ul><ul><li>Since 16 bits are used in this mode, 65,536 distinct values can be accessed using this mode. </li></ul><ul><li>When 65,536 machine cycles are over, the timer will be overflow in the microcontroller and reset to 0. </li></ul>
  11. 11. Mode 2 – auto reload timer <ul><li>It is an 8 bit auto reload mode. </li></ul><ul><li>When the timer is in 8 bit auto reload mode, THx holds the reload value and TLx is the timer itself here. </li></ul><ul><li>TLx starts counting and reaches 255. </li></ul><ul><li>When it reaches 255, instead of resetting to 0, it loads the value stored in THx. </li></ul><ul><li>That’s why it is called as 8 – bit Auto reload mode. </li></ul>
  12. 12. Mode 3 split timer <ul><li>When this mode is activated, the timer will split itself into two timers. </li></ul><ul><li>For example, if this mode is used in timer0 then timer0 splits into two 8 bit timer, i.e., TL0 is timer0 and TH0 is timer1. </li></ul><ul><li>All bits tied up to timer1 will tied up with TH0 now. </li></ul><ul><li>TL0 and TH0 increment to 255 and resets to 0 individually. </li></ul>
  13. 13. TCON SFR <ul><li>This SFR is located in 0x88. </li></ul><ul><li>In the 8 bits of this SFR only 4 bits of MSB required to be set to run the timer </li></ul><ul><li>Those are </li></ul><ul><ul><ul><ul><li>TF1 TR1 TF0 TR0 </li></ul></ul></ul></ul><ul><li>This TCON is bit addressable, therefore if you want to set any particular bit, then it is easy to do it without disturbing other bits. </li></ul>
  14. 14. Initializing the timer <ul><li>The first thing to be decided while initializing the timer is selecting the mode of operation. </li></ul><ul><li>For 16-bit you have to select mode 1 </li></ul><ul><li>For 8-bit auto reload mode you have to select mode 2 </li></ul><ul><li>This is depends on your application or use of timer in you system. </li></ul>
  15. 15. Reading the values of timer <ul><li>There are three methods using this timers </li></ul><ul><ul><li>Read the TL and TH values as 16- bit value </li></ul></ul><ul><ul><li>Read the TL and TH as separate 8 bit values </li></ul></ul><ul><ul><li>Calculate weather the timer is overflowed or not. </li></ul></ul>
  16. 16. Detection of timer overflow <ul><li>It is very easy to check the timer overflow rather than the exact value of timer. </li></ul><ul><li>Whenever the timer reset to 0 from a highest value the TFx in the TCON SFR will be set. </li></ul><ul><li>Therefore if timer 0 get overflowed then TF0 will be set </li></ul><ul><li>If timer 1 get overflowed then TF1 will be set </li></ul>
  17. 17. Second purpose of timer <ul><li>The second purpose of the timer is event counting </li></ul><ul><li>There are two methods in event counting. </li></ul><ul><ul><li>Counting the length of the event(eg., how many hours the tube light glown today) </li></ul></ul><ul><ul><li>Counting the number of occurrence of that event(eg., how many cars has passed this way) </li></ul></ul><ul><li>Depends upon the purpose the method of usage varies. </li></ul>
  18. 18. Assignments <ul><li>Use timer in a delay process </li></ul><ul><li>Use timer for counting purpose </li></ul><ul><li>Generate a delay of 1 second </li></ul><ul><li>Generate a square wave of 1 Khz. </li></ul><ul><li>Generate a square wave using timer 0 generate a saw tooth wave using timer 1 at the same time </li></ul>