Hi Richard, At 13:08 20/02/97 -0800, you wrote: >I'm in the process of designing/building an anemometer. To measure >the speed of the wind, I'm going to be counting the number of >revolutions the shaft makes. > >My question is: can I just a timing loop approach to counting the >number of revoultions or should I use a timing interrupt from a >real-time clock? > >In other words, would this appoarch give me acceptable results: > For i = 1 to NumberOfLoops > if revolution detected then > NoOfRevs = NoOfRevs + 1 > endif > next i > >where I have computed the amount of time it takes to do the loop. Or >would I be better off if I do something like: > > wait for timing interrupt > while no timing interrupt detected > if revolution detected then > NoOfRevs = NoOfRevs + 1 > wend a far neater method is the following, using two timers in your PIC: One of the timers is preloaded / prescaled such that it will generate an interrupt every ms. (input = OSC) This is your system's heartbeat. Then to measure the number of revolutions, you start a counter that counts the pulses read from the shaft (e.g. TMR1 in a 'C64). Depending on the pulse frequency and the accuracy, you let it count for a certain time and read it out. The time is of course a multiple of the ms heartbeat. The ms depends on your OSC frequency. To give you an example, using a 2.4576 MHz Xtal and some presacling, I get a 5 ms heartbeat. The interrupt routine counts the heartbeats and every 200 beats (1 sec), it stops + reads the 16 bit TMR1, writes it to some variable and clears the TMR1 and starts it again. Your main program only has to read the variable whenever it wants. Jeroen > >Thanks in advance for you comments/suggestions/ideas, > > >Richard Rosenheim >rrose@accessnv.com > > +---------------------------------------------------------------------+ | Jeroen Ommering Cordless Systems Development | | Ericsson Business Mobile Networks BV | | Institutenweg 25 | | P.O. Box 645, 7500 AP Enschede Tel: +31 53 45 05 420 | | The Netherlands Fax: +31 53 45 05 148 | | | | E-mail: Jeroen.Ommering@emn.ericsson.se | +---------------------------------------------------------------------+