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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/15/04 00:25
Read: times


 
#75930 - RE: Stuck on the event timer
Responding to: ???'s previous message
Glenn, after reading your first post on 8052 timers - the timers,serial ports,analog to digital converters etc are essetially separate pieces of hardware - they do their own thing. These are connectedto the cpu through two mechanisms - registers and interrupts. Registers allow the cpu (via your code) to start/stop, read the value, check status etc. Interrupts are like raising you hand in class for the teacher's attention - these are used by the timers etc to get the attention of the cpu that something has occured - for the timers this may be an overflow or a capture or compare event, for the serial port (uart) this may be a character has been received or one has been sent. Because we have multiple devices, we have multiply interrupts - thus one or many interrupts may occur at the same time. This brings in the concept of priority - the 8051 has a fixed priority scheme with a means of boosting a device's priority via the IP register. At a given point in time, only one device has the highest priority.
After reset, the cpu sits in a loop of FETCH and EXECUTE. Fetch is to get the next instruction, EXECUTE is to ...erm execute the instruction (do the work!). Interrupts are sampled before the cpu does a FETCH. If the interrupts are enabled (setb EA and the other bits in the IP register) and there is an interrupt current (the highest priority if there is multiple interrupts pending), the cpu will jump to the interrupt vector and start fetching and executing your interrupt code. Now, if a higher priority interrupt comes along, it will interrupt your interrupt code (that's a mouthful) and start fetching and executing the higher priority interrupt code. What happens if there's too many high priority interrupts and a lower priority interrupt never gets serviced? Too bad! You must take this possibility into account and design around it. The time between the device(uart,timer etc) signalling an interrupt and the cpu servicing the interrupt is called the 'interrupt latency' - if you only have one interrupt enabled the latency is 1 instruction worst case (the interrupt might occur just after the instruction has been fetched). The longest instruction in a 8051 is the mul or div at 4 cycles (~4uS @ 12MHz).
Hopefully this fills in the picture for you so you can re-read the tutorials and make better sense of it all.

Also, back to your problem - depending of your requirements, you may not need to use a number of timers for your task. If you only want to time ,at say, 1mS increments, you can set up a timer to interrupt at 1mS time intervals and your code implements the counting or timestamping of the events. For example, I'm doing a lap timer for my gokart - I don't need to time it to microseconds, in fact to milliseconds is probably a little overkill, but I'm doing it to milliseconds. I have one hardware timer set to interrupt every millisecond where my code increments a 4 byte tick counter (32 bits). Elsewhere in my code, an input is sampled and if true, the current tick counter is copied to another 4 bytes. When I get another input, it subtracts the saved tick count from the current tick count to get the elapsed time (thus my lap time)in milliseconds.





List of 8 messages in thread
TopicAuthorDate
Stuck on the event timer            01/01/70 00:00      
   RE: Stuck on the event timer            01/01/70 00:00      
      RE: Stuck on the event timer            01/01/70 00:00      
         RE: Stuck on the event timer            01/01/70 00:00      
   RE: Stuck on the event timer            01/01/70 00:00      
   RE: Stuck on the event timer            01/01/70 00:00      
      RE: Stuck on the event timer            01/01/70 00:00      
         RE: Stuck on the event timer            01/01/70 00:00      

Back to Subject List