Page 1 of 1

pulse counter

Posted: Thu Aug 30, 2012 10:20 am
by nuwan5213
dear all,

im going to build pulse counter ,the pulse taken to pic from machine pully.
machine pully speed is 5500rpm.
that means nearly 90 pulses for the second.! can we do that with pic16f877f runing 20 mhz crystal cct.
also i want to intergrate keypad and l c d too.
any experianse before starting to build project is appriciate.
please adv :? ise me.
thanks.
best regards,
nuwan chinthaka.

Re: pulse counter

Posted: Thu Aug 30, 2012 10:30 am
by Enamul
Hi,
im going to build pulse counter ,the pulse taken to pic from machine pully.
You can easily use Frequency counter example included in V4 example folder..90 pulses per second can easily be measured using that program..If you can't find that please let me know. I have made an interrupt version of the Freq counter you use that one as well. This program is with LCD which shows the count value..so you get your LCD there.
http://www.matrixmultimedia.com/mmforum ... 46&t=11075

If you can tell us what you would like to do using keypad we can help you to add that in the frequency counter..

Re: pulse counter

Posted: Sun Sep 02, 2012 1:00 pm
by nuwan5213
dear emmanual,

can you give me little explanation of that flowcode.

thanks.
nuwan chinthaka

Re: pulse counter

Posted: Sun Sep 02, 2012 5:38 pm
by Enamul
Hi,
The interrupt version of the frequency counter was in FCV5 which I have converted to FCV4 for you. Here is some explanation of the program:
Variables:
You will see four variables declared in the program. Two of them are byte count and update_display and two are int freq and Display_Freq. freq variable is used for accumulating number of input pulses in one second whereas Display_Freq is used to display that number of pulse in display.

Update_display variable is used to update display data. If update_display =1 only then display will be re-written and you will see this variable is initialized 0 outside the loop and set to 1 in TMR_INT macro after 1 s which is cleared again after displaying in LCD.

Count variable is used to count number of TMR0 interrupt which ultimately helps to measure 1 s. If you look at the properties of TMR0 interrupt (double click on TMR0 enable icon), you will see interrupt frequency is 75 and if you look at TMR_INT macro you will see we have incremented count and looking for count to be 75. So count is initialized before loop and and cleared after 1 s completion.

Interrupts:
I have used here two interrupts as you see. One is TMR0 interrupt for measuring 1 s. The other is RB0INT which is used to detect every input pulse for counting. If you double click RB0INT enable macro and enter into properties you can see we only detects rising edge of pulses but you can change that to falling edge..that's doesn't matter as long as you are using rectangular pulses.

RBOINT calls Read_input macro where I have Freq = Freq+1 which means each time this macro will be called Freq will be increased. In other word it's counting number of pulses until it cleared in TMR_INT macro after 1 s.

Before loop and after 1 s we have cleared tmr0 register using c code to ensure that when program starts 1 s it's really close to 1 s as this register keeping the track of time with count variable.

Main
In main, the always true loop waits for update_display to be set to display number into LCD and then reset freq variable for next 1 s and clear update_display to avoid writing display continuously in between one sec.

Hope that clear now. :)