Programming Timers
Prerequisites for Programming Timers? <ul><li>What are the prerequisites to program the timer?? </li></ul><ul><ul><li>Firs...
Step 1 <ul><li>As I said earlier first step is to collect data regarding which timer and which mode.. </li></ul><ul><li>On...
Step 2  <ul><li>After selecting the mode then we have to give some time as input.. </li></ul><ul><li>Here time means value...
Step 2 contd. <ul><li>For Eg., if you want a 50 ms time period means </li></ul><ul><li>Calculate the number of times the m...
Step 3 <ul><li>This is obviously to start the timer to count. </li></ul><ul><li>To start the timer TR should be enabled. <...
Step 4 <ul><li>It is depend upon the user’s application </li></ul><ul><li>Weather it is required to watch the values of ti...
Step 4 contd. <ul><li>Next one is reading the timer values itself. </li></ul><ul><li>This scenario will takes place only w...
Step 5 <ul><li>After reading the value or checking the timer overflow it is necessary to reset the timer overflow to reche...
Work outs <ul><li>Write a program to use timer 0 </li></ul><ul><li>Write a program to use timer 1 </li></ul>
Upcoming SlideShare
Loading in …5
×

Programming timers

1,694 views

Published on

Published in: Technology
1 Comment
0 Likes
Statistics
Notes
  • SUPERRRRRRRRBBBBBBBBBBBBBB TNKS ALOOOT
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total views
1,694
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
69
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Programming timers

  1. 1. Programming Timers
  2. 2. Prerequisites for Programming Timers? <ul><li>What are the prerequisites to program the timer?? </li></ul><ul><ul><li>First we need to conclude which timer and which mode we are going to use. </li></ul></ul><ul><ul><li>Then the calculation of time comes to next priority </li></ul></ul><ul><ul><li>Before programming timer, you must obtain complete knowledge in timer concept </li></ul></ul><ul><ul><li>If you are half way in the concept, then finish that first. </li></ul></ul>
  3. 3. Step 1 <ul><li>As I said earlier first step is to collect data regarding which timer and which mode.. </li></ul><ul><li>Once finished then give required value for TMOD to select the timer you want </li></ul><ul><li>Eg., for selecting timer 0 and mode 2 your TMOD value should be 0x02 </li></ul><ul><li>Gate C/T M1 M0 Gate C/T M1 M0 </li></ul><ul><li> 0 0 0 0 0 0 1 0 -mode 2 </li></ul><ul><li>C/T & Gate should be zero to select timer </li></ul><ul><li>M1 & M0 is you option to select the mode you want </li></ul>
  4. 4. Step 2 <ul><li>After selecting the mode then we have to give some time as input.. </li></ul><ul><li>Here time means values to be counted. </li></ul><ul><li>We have already seen that one machine cycle can run in 1.085uS </li></ul><ul><li>Timers incrementing the value by 1 which also required 1 machine cycle. By knowing this we can obtain any time we want to have by giving the initial values for timer </li></ul><ul><li>i.e., TL and TH value are the initials for timers. It starts counting from that values only. </li></ul>
  5. 5. Step 2 contd. <ul><li>For Eg., if you want a 50 ms time period means </li></ul><ul><li>Calculate the number of times the machine cycle to be executed to get the 50 ms time. </li></ul><ul><ul><ul><li>I machine cycle = 1.085us </li></ul></ul></ul><ul><ul><ul><li>For 50 ms 50 m / 1.085 u = 46,082 times one machine cycle </li></ul></ul></ul><ul><li>Since timer only increment the value of TL and TH from 0 to 65,536 </li></ul><ul><ul><ul><li>Maximum value = FF FF(65,536) </li></ul></ul></ul><ul><ul><ul><li>Required value = 46,082 </li></ul></ul></ul><ul><ul><ul><li>Therefore values for TL and TH = 65,536 - 46,082 = 19454 </li></ul></ul></ul><ul><ul><ul><li>In hex 4BFE therefore for TL = 0xFE; </li></ul></ul></ul><ul><ul><ul><li>and for TH = 0x 4B; </li></ul></ul></ul>
  6. 6. Step 3 <ul><li>This is obviously to start the timer to count. </li></ul><ul><li>To start the timer TR should be enabled. </li></ul><ul><li>Since TR is located in TCON there are two ways to enable it </li></ul><ul><ul><ul><li>By giving the particular value to TCON to enable TR </li></ul></ul></ul><ul><ul><ul><li>By enabling the TR using bit manipulation. </li></ul></ul></ul><ul><li>Eg., TR0=1; </li></ul>
  7. 7. Step 4 <ul><li>It is depend upon the user’s application </li></ul><ul><li>Weather it is required to watch the values of timer or the timer overflow. </li></ul><ul><li>For the timer overflow it is required to watch the value of TF0 and TF1 which are located in TCON register </li></ul><ul><li>If TF0 is enabled then timer 0 is getting overflowed. </li></ul><ul><li>If TF1 is enabled then timer 1 is getting overflowed </li></ul>
  8. 8. Step 4 contd. <ul><li>Next one is reading the timer values itself. </li></ul><ul><li>This scenario will takes place only when working with counter and auto reload mode.. </li></ul><ul><li>Since the value of TH is automatically reloaded in TL by getting TL when the event happened the no of times it happened can be calculated and displayed in LCD. </li></ul><ul><li>You can check the timer overflow using while like this.. </li></ul><ul><li>Eg., </li></ul><ul><ul><ul><ul><li>while(TF0 == 0); </li></ul></ul></ul></ul>
  9. 9. Step 5 <ul><li>After reading the value or checking the timer overflow it is necessary to reset the timer overflow to recheck again </li></ul><ul><li>Therefore this is the step which we have to reset the timer run and timer overflow flag. </li></ul><ul><li>This step is necessary only there is a need to redo all operation again and again, i.e., a while loop program </li></ul><ul><li>If you have to check only once it is not a necessary option, still it is Important to reset the register bits. </li></ul><ul><ul><ul><ul><li>Eg., TF0=0; </li></ul></ul></ul></ul><ul><ul><ul><ul><li>TR0=0; </li></ul></ul></ul></ul>
  10. 10. Work outs <ul><li>Write a program to use timer 0 </li></ul><ul><li>Write a program to use timer 1 </li></ul>

×