Timer and Timershttp://dev.emcelettronica.com/print/518061 din 211.06.2008 21:45
Your Electronics Open Source
Home > Blog > allankliu's blog > Content
Timer and Timers
By allankliuCreated 10/06/2008 - 02:35
BLOG MicrocontrollersI was a marketing engineer for Philips microcontroller. To offer training courses for our customers isincluded in my job description. I still remember a good question from one of my customers. Itdemonstrates how our universities have misguided our students.The question is how to findextra timers in a complexapplication while a standardmicrocontroller usually hasonly two or three timers? Theanswer is simple. You have tocreate the additional timers insoftware. Yes, software timers.You will know that the timertakes a quite big area in thesilicon when you look at thesilicon picture and find thetimer part. This is a crosssection view of a Cypressmicrocontroller. The reasonwhy a microcontroller can nothave too many timers is that ittakes silicon space and money.BTW, have you saw a lot of real time timers in a computer? No, you can only see one real time timerwith a battery. All other timers are software timers implemented in software. After all, software timersshould be implemented in the system. But how to implement software timers with one hardwaretimer?First we should use the hardware timer as the base timer, which offers time base on every givenperiod. For example, the hardware timer can generate timer interrupt every 16ms. Then we canderivate software timers for 32ms, 64ms, 128ms, and 256ms. The software timer of a second can be4 interrupts of 256ms. You can adjust timer accuracy if you want. But above method is enough for anembedded system, since most of the applications do not require high accurate timers. If you want areal-time timer, please use a dedicated IC, instead of a software timer, because the external realtimer can offer higher accuracy with temperature compensation for crystal temperature drift. Andplease do not use the watch dog timer as your time base. Usually it is reserved to save the wholesystem in case the system is out of order.Here is a fraction of C source for your reference. You can create many timers provided you haveenough RAM. The design of software timers are: base timer, timer ISR, and application softwaretimers. The 0 of an application software timer stands for inactive and 1 stands for timeout, and anyother numbers stand for running of a software timer. The timers are count down counters.