Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/12/04 17:58
Read: times


 
#75853 - RE: 8052 - Timer2
Responding to: ???'s previous message
Been there, seen that, learned to cope with that. NO missing clock cycles with manual reload.

The trick is the timer keeps running after the interrupt. The timer keeps running even while interrupt is disabled!
As long as you don't touch LSB, and perform your update of MSB within 256 cycles since the overflow, no clocks are lost. What is lost is the setting accuracy - you can update only MSB.

On 12MHZ clock, you need 2400h cycles for 0.01s pulse. So you need to set your clock to 10000h-2400h=DC00h. You do so before setting TR. But in the reload routine, you just update the MSB with DCh, you don't touch LSB. Right when the new tick started, it contained 00 as you wanted it to be right then, it was the MSB that was wrong and you fixed it just now (because you knew it will remain in the same state for another 200 or so cycles, so by updating it you don't break anything). You don't know what the LSB contains right now, but you know it's the correct value and that's all you care about.

Now what if you want to update LSB as well? You can still do it by performing some maths on it.
Say, you want to update it to X. So you take its current value Y, add X, add number (Z) of clocks required to perform the update you are performing right now (make sure no other interrupts kick in, so i.e. the interrupt is highest priority) and write it. If overflown, add 1 to MSB "manually" unless the timer was within Z from overflow, in this case it has increased MSB by itself already. It shouldn't have been, the operation shouldn't take more than 15 cycles and you shouldn't be further from LSB=00 than another 15 cycles or so. (unless you allowed other interrupts in the meantime.)

You can even delay the update by almost whole clock overflow time. Just add the value to MSB instead of overwriting it (and watch LSB for overflow)


List of 19 messages in thread
TopicAuthorDate
8052 - Timer2            01/01/70 00:00      
   RE: 8052 - Timer2            01/01/70 00:00      
      RE: 8052 - Timer2            01/01/70 00:00      
   RE: 8052 - Timer2            01/01/70 00:00      
      RE: 8052 - Timer2            01/01/70 00:00      
         RE: 8052 - Timer2            01/01/70 00:00      
         RE: 8052 - Timer2            01/01/70 00:00      
      RE: 8052 - Timer2            01/01/70 00:00      
         RE: 8052 - Timer2            01/01/70 00:00      
   RE: 8052 - Timer2            01/01/70 00:00      
      RE: 8052 - Timer2            01/01/70 00:00      
         RE: 8052 - Timer2            01/01/70 00:00      
            RE: 8052 - Timer2            01/01/70 00:00      
               RE: 8052 - Timer2            01/01/70 00:00      
                  RE: 8052 - Timer2            01/01/70 00:00      
                     RE: 8052 - Timer2            01/01/70 00:00      
                        RE: 8052 - Timer2            01/01/70 00:00      
                           RE: 8052 - Timer2            01/01/70 00:00      
                  RE: 8052 - Timer2            01/01/70 00:00      

Back to Subject List