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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/24/11 03:33
Read: times


 
#183858 - Still not understanding isr with tick
Responding to: ???'s previous message
Per Westermark said:
You have already been given a good answer.

In short:

With the current crystal, your timer can't be slowed down enough for 2Hz (i.e. 4 interrupts/second).

But you can configure the timer to produce interrupts at a higher frequency, and in the ISR use a software counter to decide that you toggle the pin every n interrupts.

So if you configure the timer for 10ms (which I think was the suggested frequency - complete with timer parameters - in a previous post), then you should toggle the pin every 25 interrupts. 25 * 10ms = 250ms. And 250 ms * 2 = 500 ms period time = 2 Hz frequency.

It is standard that software programs needs to use software counters internally, for the delays.

A 32-bit processor might be lucky enough to have 32-bit timers. But if ticking at 48MHz, such a timer would still be limited to 83 seconds, unless there is a prescaler.

Next thing - few processors have more than 4-8 timers. Many have 1 or 2. But a program may need to handle hundreds of time-controlled tasks internally. So every task can't have a dedicated hardware timer.

The solution? The one suggested above. Set up a timer ticking at 10ms. Every 100 tick (as counted with a variable in the ISR), one second will have passed. Every 60 seconds, a minute will have passed.

Suddenly, it becomes trivial to handle times way longer than a timer can span. Or to handle many more events than there are hardware timers.

With timers that can toggle output pins, it is often possible to make use of this hardware functionality even if the toggle frequency is slower than the timer period. This may be done by activating the pin-toggle function at the interrupt tick before the one where the pin should toggle. On next interrupt deactivate this feature again while waiting for time to prepare next toggle. Why do that, instead of manually toggling the pin in the ISR? Because the ISR has a little bit of jitter because of the interrupt response time in relation to other operations and currently processed instruction. Manually turning pin-toggle on/off can allow the pin to be toggled with zero jitter by the hardware. It's too long since I used the timer function of 8052 chips so it may not be applicable to them. But it is a good trick to remember if it is important to have very low jitter on the generated signal while still have longer periods than the timer can handle in a single delay.


Hi Per Westermark:


I spend about 7 days trying write isr with tick routine. And I still do not know how to do it. Is possible you can give a source code example even if its not used for my 2 Hz source code? I wrote page of what I was doing but when I pressed Preview Before posting it must timed out. So now I giving the short version of my problem.

Best regards,

Ralph Sac

List of 42 messages in thread
TopicAuthorDate
Need a little help with frequency            01/01/70 00:00      
   use 89c52            01/01/70 00:00      
   "formulae"            01/01/70 00:00      
   How to post legible source code - and text            01/01/70 00:00      
      Legible source code            01/01/70 00:00      
         Not the whole message!            01/01/70 00:00      
            Thanks Andy got little messed up            01/01/70 00:00      
               Already answered            01/01/70 00:00      
                  Still not understanding isr with tick            01/01/70 00:00      
                     use may use this code            01/01/70 00:00      
                        Thanks for time            01/01/70 00:00      
                        Rewrote Source Code for Metalink Assembler            01/01/70 00:00      
                           keil assembler            01/01/70 00:00      
                           No need for picture            01/01/70 00:00      
                     try            01/01/70 00:00      
                        the code above is a typical illustration of ...            01/01/70 00:00      
                           You are right            01/01/70 00:00      
                              never too old            01/01/70 00:00      
                                 Never too late to pick up a new trick            01/01/70 00:00      
                                    One good trick ...            01/01/70 00:00      
                                 Score -1            01/01/70 00:00      
                                    Learn one before Jumping head            01/01/70 00:00      
                                       Learning Assembler First            01/01/70 00:00      
                                          I wholehardely concur.            01/01/70 00:00      
                        Thanks also you for your time            01/01/70 00:00      
   Here's something to try ...            01/01/70 00:00      
   One suggession for higher frequency            01/01/70 00:00      
      Remember no fractional part for            01/01/70 00:00      
         Precise frequency            01/01/70 00:00      
      I did not know that            01/01/70 00:00      
         89c2051            01/01/70 00:00      
            When you wrote code            01/01/70 00:00      
               You normally always need to test - but may not need to debug            01/01/70 00:00      
               it was example            01/01/70 00:00      
                  Ok then if I            01/01/70 00:00      
                     try            01/01/70 00:00      
                     depends            01/01/70 00:00      
                     Testing Code            01/01/70 00:00      
                        In short            01/01/70 00:00      
                           someone said it better            01/01/70 00:00      
                              "Proven Product" Syndrome            01/01/70 00:00      
                     Did you ever look at that MIDE51 I previously mentioned?            01/01/70 00:00      

Back to Subject List