You could use the internal timer of the PIC to measure the time between pulses. I have done something similar to measure the frequency of an AC supply.
You dont need to use interrupts either just a loop waiting for your input signal. In fact not using interrupts might be better. You could sort out your calculations and displaying the result without worrying about being interrupted.Code:define OSC 40 INCLUDE "DT_INTS-18.bas" ' Base Interrupt System INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts 'set up timer T0CON = %00000001 '1/4 prescale fosc/4 not running (40MHz) TMR0H = 0 ;Clear registers TMR0L = 0 ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler INT0_INT, _ZERO, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM @ INT_ENABLE INT0_INT ; enable external (INT) interrupts goto start ZERO: 'we have just detected zero cross signal. 'first job is to sort out the timer @ bcf T0CON,TMR0ON ; Switch off timer period.lowbyte = TMR0L 'Record Result period.highbyte = TMR0H @ clrf TMR0H ; Reset registers to zero @ clrf TMR0L @ bsf T0CON,TMR0ON ;Start timer period = (period / 5) * 2 'Gives period value in microseconds @ INT_RETURN start: 'wait for interrupt to happen goto start END
You would need to set up the timer to give a useable range. I use the "PIC Timer Calculator" to do this, it makes things much easier.
You may need more than one pulse per revolution to give results at low wind speeds.
You may need to use the timer interrupt to flag if the timer has overflowed (got to 65535 & started counting again from zero) otherwise in very low winds you may not get a pulse before overflow, & the results would be wrong. If you get a timer overflow interrupt then you can say that the wind speed is zero.
http://pic-timer-calculator.software.informer.com/
http://darreltaylor.com/DT_INTS-18/home.html
Ofcourse this is all more complicated than using pulsein. But It is sometimes good to play around with more complex answers. It is the only way to learn new things. One month ago I knew nothing about using timers or Interrupts. Now it is second nature, and I wonder how I managed to get by without them.
Regards
Bob.




Bookmarks