Connect with us

stuck in RPM measurement using pic 18f452

Discussion in 'Microcontrollers, Programming and IoT' started by ansari haris, Apr 1, 2014.

Scroll to continue with content
  1. ansari haris

    ansari haris

    1
    0
    Apr 1, 2014
    i simply want to measure rpm of a motor using simple infrared LED and photodiode. hardware is working fine but stuck in coding.can somebody please help me about coding
     
  2. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,271
    2,718
    Jan 21, 2010
    Count the pulses you receive in a second.
     
  3. gorgon

    gorgon

    603
    24
    Jun 6, 2011
    Or you can use the timer/ counter to count the ticks between the start-to-start flank of one or a number of pulses. Then calculate the elapsd time and divide it on a second. This is faster, and closer to realtime.
     
  4. Anish

    Anish

    46
    0
    Feb 5, 2011
    Use the CCP module in the PIC.
    Look for rising edge (interrupt), change edge, start timer,
    Look for falling edge (interrupt), change edge, stop timer.
    This way you can measure the width of a pulse. Then use the method told by gorgon to find the rpm
     
  5. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,271
    2,718
    Jan 21, 2010
    Actually you would look for the timing between two rising edges or two falling edges in most cases because it's not the length of the pulse, the time between them. The time "between" them is not actually the interval between pulses, but the interval between like events on the pulses (e.g. it may be the time between the starts of the pulses)
     
  6. gorgon

    gorgon

    603
    24
    Jun 6, 2011
    Normally there will be some jitter on the pulse train, and averaging the period time over some pulses will filter out the most prominent jitter.
    Don't use too many samples since changes in RPM will then be delayed. It depends on the quality of your measurement setup. If your program monitor the stability of the values, and they are good, you can reduce the sample interval, and speed up the update. It all depends of the dynamic of the motor and the RPM changes.

    As (*steve*) said measure the whole period as one sample.

    In short the procedure is simple.
    The timer system has a freerunning counter that can be read. You setup the interrupt service routine for interrupt at the positive or negative flank of your input, and log the counter at every interrupt. The value should be put into a small ringbuffer, and a new value flagged, or you can calculate the ticks directly. In your background program you process the values in the ringbuffer, and subtract the buffer value(n-1) from value(n). This gives you the number of counter ticks one period has lasted.
    You know how fast your counter are running, from your setup of the timer unit, and you can calculate the time(p) of the period. If you have one period/rotation, your RPM = 60/time(p)(in seconds). If your time(p)=0.01s (10ms) your RPM is 60/0.01=6000
     
    Last edited: Apr 9, 2014
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-