Interrupt RPM and Taylors Elapsed time on 18F4620


Closed Thread
Results 1 to 40 of 71

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Are your result figures correct? It shows the exact same result on the 877A for 6000
    and 8000 RPM!

    What do you get with something like this on both versions?
    Code:
    period.lowbyte = CCPR1L		' Store the captured value in
    period.highbyte = CCPR1H	' period variable
    
    SEROUT2 LCD,84, [Prefix,CursorPS,20,dec5 period]
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2


    Did you find this post helpful? Yes | No

    Default Period info

    RPM and period numbers per chip
    Rpm 4620 877a
    5000 15090 14999
    6000 12575 12499
    7000 10777 10712
    8000 9430 9373
    9000 8383 8331
    10000 7545 7499

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Do you have another 18F type besides a 4620 you can test this on?

    That would tell you if it's a hardware bug on the 4620. This part has
    a massive list of errata & odd problems with ECCP, Timer1, Timer3,
    and more.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4


    Did you find this post helpful? Yes | No

    Default

    I might have a 4520 floating around. Can you suggest a part number that will work with the boards I already have made? I will order it today if you have a suggestion.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    A 4520 should drop right in, but this one also has a boat-load of errata for CCP, timer, and
    a bunch more. I would test it if you already have one before buying another PIC.

    The 18F4431 is my own personal favorite, and I also like the older 18F452. The drop-in
    replacement (your 4520) for the 452 has way too many bugs.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Thanks it looks like a couple different config flags need to be changed to go with the 4431. The pinout appears to be the same.?.

  7. #7
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    It's the same pinout. It also has a lot of extra features.

    But - I would try that 4520 if you can find it.

    Where are you getting your PICs from? I have samples, and would be
    more than willing to shoot you an 18F4431 if you cover postage.
    Last edited by Bruce; - 28th January 2010 at 22:08.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Tobias View Post
    RPM and period numbers per chip
    Rpm 4620 877a
    5000 15090 14999
    6000 12575 12499
    7000 10777 10712
    8000 9430 9373
    9000 8383 8331
    10000 7545 7499
    I think you need to clear the timer sooner. (Immediately after capture).

    The program goes through the whole conversion to RPM with multiplications and DIV32's before clearing the timer.

    The 18F's multiply faster because they have a hardware multiplier.
    So it clears the timer quicker and ends up with bigger numbers.

    The 4620 numbers are closer to reality, but it's still wrong.

    Clear the timer immediately after a capture and both chips should read the same numbers (or really close).

    hth,
    DT

  9. #9
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    Code:
    Start:
          If Capture = 0 then ' ignores 1st capture
             Goto Start
          endif
    
          T1CON.0=1
          Capture = 0 
          
    CaptureLoop:
    If Capture = 0 then 
      Goto CaptureLoop
    endif
    T1Con.0=0  
    period.LowByte=CCPR1L
    period.HighByte=CCPR1H
    With both PICs running at 20MHz, CCPR1L & CCPR1H should have the same values - since
    it's all done in hardware with the capture module capturing the value of timer1 after the
    4 rising edges.

    And the value being captured is before the multiply.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    With both PICs running at 20MHz, CCPR1L & CCPR1H should have the same values - since it's all done in hardware with the capture module capturing the value of timer1 after the
    4 rising edges.
    Yes the captured value is stored in CCPR1L:H, but the CCP module does not clear Timer1. You have to do that. And it's not being cleared until after the math.

    Then it goes back up to Loop: and clears it again, without any reference to the incoming signal. (actually, it is referenced to the last capture plus math time).

    If you only clear it once, immediately after the capture, then it will be ready for the next capture.

    The first capture is always wrong, and must be discarded.
    Code:
    Loop:
    TMR1H = 0    'Clear 8-bit register                              
    TMR1L = 0    'Clear 8-bit register
    capture = 0  'Clear Timer
    Start:
          If Capture = 0 then
             Goto Start
          endif
    
          T1CON.0=1
          Capture = 0 
          
    CaptureLoop:
    If Capture = 0 then 
      Goto CaptureLoop
    endif
    T1Con.0=0  
    period.LowByte=CCPR1L
    period.HighByte=CCPR1H
    
    RPM = 10000
    RPM = RPM * RPM ' 100,000,000
    RPM = DIV32 period ' 100,000,000 / RevCount
    RPM = RPM * 60 ' Per minute
    RPM = DIV32 400
    RPM = (RPM*5)
    
    SEROUT2 LCD,84, [Prefix,CursorPS,20,"RPM ",dec5 RPM, " ", DEC CCPR1L, " ", dec CCPR1H]
      
    Gosub ClearTimer1
     
    Goto Loop
    Added: I guess if Timer1 was Stopped in the ClearTimer1 routine (or at Loop: ), what you have would work better, but it will only capture every other 4-pulses. (8-pulses total)
    Last edited by Darrel Taylor; - 28th January 2010 at 23:08. Reason: Added
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Oi vey,
    I just saw ...

    T1Con.0=0

    Ignore what I just said, and I'm off to proteus to make sure before I open my mouth again.

    DT

  12. #12
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Cool. If I'm wrong, he gets a free PIC & you get the eBeer....

    Like I said before, there could indeed be a timing difference between these points;
    Code:
          T1CON.0=1
          Capture = 0
    That would for sure be the cause.
    Last edited by Bruce; - 29th January 2010 at 00:15.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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