16F877@4Mhz calculate Pulsin to RPM


Closed Thread
Results 1 to 25 of 25

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Leigh,

    From your two values of 165 and 168, I calculate that the engine was running at 4504 RPM. So, the following formula may be what your looking for.
    Code:
    Pulse_High  Var  word
    Pulse_Low   Var  word
    Pulse_Total Var  Word
    RPM         Var  Word
    
    Pulse_High = 165
    Pulse_Low  = 168
    
    Pulse_Total = Pulse_High + Pulse_Low
    RPM = 1000
    RPM = RPM * RPM           ' Preload internal registers with 1,000,000
    RPM = DIV32 Pulse_Total   ' 1,000,000 / Pulse_Total
    RPM = RPM * 60            ' Per minute
    RPM = Div32 40            ' 4 pulses per rev
    
    lcdout $FE,1,dec RPM
    In normal math it might look like this:
    (1,000,000/(Pulse_High+Pulse_Low))*60/40

    A better way to take the measurements might be to use the Capture mode of the CCP module. Set the prescaler to 2:1 and have it count 4 rising edges of the input and then generate an interrupt. The Timer value would contain 1/2 the number of uS it takes for 1 revolution, which should be fairly easy to convert to RPM. This way, the processor can continue doing other things while it's taking the measurement. This should work from 500-10,000 RPM

    That's a bit more complicated, but may be worth looking into.

    HTH,
       Darrel
    Last edited by Darrel Taylor; - 18th April 2004 at 22:05.

  2. #2
    Join Date
    Jun 2013
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: 16F877@4Mhz calculate Pulsin to RPM

    Hi Darrel Taylor

    You said the ccp should work from 500 - 10,000 rpm. Please kindly advice how to measure rpm 0-10,000 rpm by use ccp module on [email protected] you have source code please show me. Thank you.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: 16F877@4Mhz calculate Pulsin to RPM

    You'll need to count the timer overflows and use them as the high word of the period after a capture.
    Then change all the math, because the values will be larger than 16-bits.

    Since you are using an 877A, you won't have the luxury of using LONG variables.
    DT

  4. #4
    Join Date
    Jun 2013
    Posts
    2


    Did you find this post helpful? Yes | No

    Wink Re: 16F877@4Mhz calculate Pulsin to RPM

    Thank you for your advice but i still not clear please kindly show example about your advice above. For my program show as below
    PIC16F877A

    DEFINE OSC 4
    Define LCD_DREG PORTD
    Define LCD_DBIT 4
    Define LCD_RSREG PORTE
    Define LCD_RSBIT 2
    Define LCD_EREG PORTD
    Define LCD_EBIT 1


    Low PORTE.2
    PIE1.2=1

    Symbol Capture = PIR1.2 ' CCP1 capture flag
    T1 VAR WORD ' 1st capture value
    PW VAR WORD ' 2nd capture value & ultimately final pulse width



    intermediate VAR WORD
    Dummyvar VAR WORD


    rpm VAR WORD

    TRISC.2 = 1 ' CCP1 input pin (Capture input)
    INTCON = 0 ' Interrupts off

    ReLoad:
    CCP1CON = %00000101 ' Capture mode, 4capture on rising edge
    T1CON = 0 ' TMR1 prescale=1, clock=Fosc/4, TMR1=off (200nS per count @20MHz)
    TMR1H = 0 ' Clear high byte of TMR1 counter
    TMR1L = 0 ' Clear low byte
    T1CON.0 = 1 ' Turn TMR1 on here


    Capture = 0 ' Clear capture int flag bit
    While (!Capture) ' Wait here until capture on rising edge
    Wend

    ' Rising edge detected / stuff Timer1 value in T1
    T1.HighByte = CCPR1H
    T1.LowByte = CCPR1L

    CCP1CON = %00000100 ' Configure capture for falling edge now
    Capture = 0 ' Clear capture interrupt flag bit

    While !Capture ' While here until capture on falling edge
    Wend

    ' Falling edge detected / stuff Timer1 value in PW
    PW.HighByte = CCPR1H
    PW.LowByte = CCPR1L

    PW = PW-T1 ' High pulse width = PW-T1


    intermediate = 60 * 1000 / 4 ' Compulsory !!!
    ' ( no "intermediate CON xxx" allowed )


    ' Disable interrupts ... if some used !!!


    Dummyvar = 1000 * intermediate


    rpm = DIV32 PW


    ' re-enable interrupts allowed
    lcdout $fe,1,"TCH",$fe,$84,DEC RPM

    GOTO ReLoad

    END

Similar Threads

  1. Interrupt RPM and Taylors Elapsed time on 18F4620
    By Tobias in forum mel PIC BASIC Pro
    Replies: 70
    Last Post: - 3rd February 2010, 16:12
  2. Slow code needs a tune up
    By Tobias in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th January 2010, 15:05
  3. Pulsin vs. Interrupt RPM measurement
    By Tobias in forum General
    Replies: 1
    Last Post: - 31st December 2009, 01:29
  4. 16f877A and tmr1 external crystal question
    By comwarrior in forum General
    Replies: 3
    Last Post: - 13th July 2009, 00:40
  5. RPM - DIV32 Problem
    By davewanna in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 11th April 2008, 04:33

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts