OK, so I'm getting somewhere now...
I've setup the code to use the CCP1 register to scan the pulses and return the time back in uS.
What I can't seem to figure out yet is whether I've got the prescaler etc. right.
My code has the following lines....
CCP1CON = %00000110
T1CON = %00010001
Does that look about right for the settings that Darrel suggested. 2:1 prescaler and measuring 4 rising edges?
So does this look right to calculate the RPM? (Sorry for being so dumb, but this sort of math really bakes my noodle!!)
dummy = period * 2
RPM = (dummy*60)/100
The only problem I can see is that this is going over the 65535 limit. Can I use the DIV32 command to make this work properly and read the value correctly?
For example, at 6000rpm period is approx. 4989uS, which puts dummy to 9978 so rpm should work out (9978*60)/100=5986.8 very close to 6000rpm so not bad.
BUT 9978*60=598680 - just a bit over the 65535 limit :o(
Can anyone suggest a better way to to the math as this will become much worse to calculate at lower rpm due to the increased uS per RPM time.
And yes, I do feel a bit of a fool asking these questions, but it is my first time programming a PIC :o)
Cheers
Leigh
Bookmarks