Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F877A as a frequncy counter

Status
Not open for further replies.

oodes

New Member
Hi,
I am working on a project and using a PIC16F877A to measure various weather patterns. I need to set up the CCP module in the capture mode. My anemometer is rotating at 1m/s or 1Hz. Problem is i need to use Timer1 , when i prescale my T1clk from the 19.6MHz rate i can get it down to around 600,000 (Fosc/4/8), but with my input frequency being as low as 1Hz i would require a count of 600,000 but my timer is only 16bit and can only count to 65,536
Any help guys?
 
Hi,
I am working on a project and using a PIC16F877A to measure various weather patterns. I need to set up the CCP module in the capture mode. My anemometer is rotating at 1m/s or 1Hz. Problem is i need to use Timer1 , when i prescale my T1clk from the 19.6MHz rate i can get it down to around 600,000 (Fosc/4/8), but with my input frequency being as low as 1Hz i would require a count of 600,000 but my timer is only 16bit and can only count to 65,536
Any help guys?

hi
Set Tmr1 to a known value, say 50,000, and count the Tmr1 roll overs into register, read the reg and Tmr1 for the Total count

EDIT:
If you are not sure how to do that, preload the Tmr1 with 50,000, set the Tmr1 interrupt enable, and increment a register every Tmr1 interrupts on over flow.
Reload the Tmr1 with 50000 and re-enable the Tmr1 interrupt at the interrupt
 
Last edited:
Hey,
Thanks for the response,i understand what ur saying about the rollovers but i think my problem is more than that, you will have to excuse me a little im quite new to the world of PICs. The spec for my anemomter is that 1 revolution = 1 Hz , so this can vary reaslitically up to about 50r/s or 50Hz max , how can i implement this on the CCP as my frequency will constantly be changing which in effect means i would have to be imputted new values each time into my ccpr1l & ccpr1h registers , obviously there is an easier method, am just not too sure on how to implement it. I found a method in "Embedded C programming and the MIcrochip PIC" . Which is determining the number of clock pulses (t1clk input, 614,400 =1.63uS) that would occur within my input frequency which say for argument is 4m/s or 4Hz which would be 0.25s frequncy , that would equate to a value of .25s/1.63uS=153374 needed to be on the ccpr1l&ccpr1h registers which again is not possible. Am i way off the mark here with this problem and am i approaching it from totally the wrong angle?
 
hi,
Have you considered using Tmr1's external clock input as a counter for the anemometer pulses ,and using another Timer to measure a 1sec period.???
 
I have an anemometer on the market.... It has four pulses per revolution... All I do is set up an interrupt on the INT pin... Wait for 1 second.. count the pulses received.. job done.
If you need to process anything else.. use any timer to give a 1 second (or even half a second ) timeout.
 
A good simple system is to use TMR2 to generate an interrupt every 100uS. Then just inc a 16bit variable in the interrupt (count the number of interrupts) between each input pulse.

If you use an 8MHz xtal you run TMR2 at 1:1 prescaler and a PR2 period of 200-1 (which is 200 counts, = 100uS).

That gives you a 16bit result which is a period in actual uS *100, with a resolution to 100uS (ie 10000 = 1 second, 10001 = 1.0001 second, 10002 = 1.0002 seconds etc).
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top