Measuring RPM of a motor using a Pic?

Thread Starter

spinnaker

Joined Oct 29, 2009
7,835
What is the best way to measure the RPM of a motor using a Pic?

I already have the sensor working and I can count the number of times the motor rotates. What I am trying to figure is the best way to turn that into RPM.

Best I can figure is to set a timer for a given period. When that period expires, determine the RPM and reset the counter.

Is there a better way?
 

MaxHeadRoom

Joined Jul 18, 2013
20,866
I have used a slot photo sensor and the retro-reflective sort.
I started with this principle and expanded it.
I used the CCP capture input.
I have the code for this version also.
Max.
 

Attachments

Thread Starter

spinnaker

Joined Oct 29, 2009
7,835
Thanks Max. I was thinking CCP but I was not sure. Any chance that code is in C? If so could you post the relevant portion?

Or can you point me to what I should be reading in the datasheet (just in general).
 

Picbuster

Joined Dec 2, 2013
1,007
The simplest way: connect sensor to interrupt line and measure number of pulses between the int's.

//---------------- PULSE RECEIVED

if (INT1IF)

{
INT1IF=0;
Timerflag=!Timerflag;
}


// run tmro fast as possible

If (!Timerflag)
{
speed++;
}
Else
{
Rp=speed;
Speed=0;
}

In main
calculate from Rp and tmr0 the rpm. and take your time look once a second or so to calculate.
 

MaxHeadRoom

Joined Jul 18, 2013
20,866
Any chance that code is in C? If so could you post the relevant portion?

Or can you point me to what I should be reading in the datasheet (just in general).
Sorry, I pgm in Assembly and the code is in it.
The pic sheet usually gives an example of Capture, the advantage of using a 32khz xtal as in the example is that the timer roll over is exactly 1 sec. or fractions of.
As shown in the example code.
Max.
'
 

ScottWang

Joined Aug 23, 2012
6,909
The industrial will using the encoder to be the input sensor, you can set the timer counting to 3 seconds and the numbers of counter of encoder will be the base number Num_Encoder, the rpm = Num_Encoder * 20.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,835
Sorry, I pgm in Assembly and the code is in it.
The pic sheet usually gives an example of Capture, the advantage of using a 32khz xtal as in the example is that the timer roll over is exactly 1 sec. or fractions of.
As shown in the example code.
Max.
'
I have a 16MHZ xtal for the mcu clock. But I have a 32k xtal for the RTC. Guess I need to look at the datasheet to see if that can be leveraged.
 
Top