Measuring RPM of a motor using a Pic?

Discussion in 'Embedded Systems and Microcontrollers' started by spinnaker, Nov 26, 2015.

  1. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    991
    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?
     
  2. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
    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.
     
  3. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    991
    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).
     
  4. Picbuster

    Member

    Dec 2, 2013
    374
    50
    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.
     
  5. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
    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.
    '
     
  6. ScottWang

    Moderator

    Aug 23, 2012
    4,853
    767
    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.
     
  7. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    991
    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.
     
  8. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
    What is the pic type?
    Max.
     
  9. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    991
    18F26J53
     
  10. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
    Typically the 32Khz is across T1OSO and T1OSI. (TMR1).
    Max.
     
  11. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    991
    That is where it is.
     
Loading...