Interrupt RPM and Taylors Elapsed time on 18F4620


Closed Thread
Results 1 to 40 of 71

Hybrid View

  1. #1


    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

  2. #2
    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

  3. #3


    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.

  4. #4
    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

  5. #5


    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.?.

  6. #6
    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

  7. #7


    Did you find this post helpful? Yes | No

    Default

    I usually go through Mouser but I would rather spend money with you. Do you want to Paypal the freight? My paypal acct is [email protected].

    I need a 44 pin TQFP

    Shipping is
    xBase
    506 Park St
    Sterling CO 80751

    Hell with your 719 area code you can't be far anyway.
    Thanks
    Toby

  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

  13. #13


    Did you find this post helpful? Yes | No

    Default Free beer appreciated

    Here is what I have now. I have set it up for every rising pulse and changed the math because when I incorporate this into my other code, waiting for four pulses delays alot of events.

    Its still off with the output RPM numbers by the same percentage.
    Code:
    DEFINE OSC 20
    Prefix          con     $FE           ' needed before each command
    LcdCls          CON     $51           ' clear LCD (use PAUSE 5 after)
    CursorPS        con     $45           'Cursor Position
    Capture         VAR     PIR1.2		    ' CCP1 capture flag CCP1IF
    Overflow        VAR     PIR1.0	    	' Timer1 overflow flag TMR1IF:
    RPM             var     word
    period          var     Word
    TotalTime       var     word      'Holds seconds and tics 
    
    LCD             VAR     PortC.6    'LCD output
    Gate1           Var     PortC.1
    Gate2           var     PortD.1
    Gate3           var     PortD.2
    Gate4           var     PortD.3
    Gate5           var     PortD.6
    Gate6           var     PortD.7
    Gate7           var     PortD.5
    Gate8           var     PortD.4
    WOT             var     PortB.0
     
    ADCON0 =0       'A/D Off
    ADCON1.3=1      'All AN channels digital
    ADCON1.2=1      '''
    ADCON1.1=1      '''
    ADCON1.0=1      '''
    TRISE.0=1       'EO input
    TRISE.1=1       'E1 input
    CCP1CON = %00000101  ; Capture mode, every rising edge 0101 
    T1CON.7=1     'enable timer  16 bit `   
    T1CON.6=1     'Timer1 OSC
    T1CON.5=1     '1:4 prescaler
    T1CON.4=0     '1:4 prescaler
    T1CON.3=0     'Timer1 OSC off
    T1CON.2=0     'sychro clock
    T1CON.1=0     'internal clock
    T1CON.0=0     'stop timer
    
    pause 10
    SEROUT2 LCD,84, [Prefix, LcdCls]
    
    Include "modedefs.bas"	' Mode definitions for Serout
    SEROUT2 LCD,84, [Prefix,CursorPS,0,"RPM test"]
    pause 500
    
    TMR1H = 0    'Clear 8-bit register                              
    TMR1L = 0    'Clear 8-bit register
    capture = 0  'Clear Timer
    
    Calc_RPM_Timer:
    TMR1H = 0    'Clear 8-bit register                              
    TMR1L = 0    'Clear 8-bit register
    capture = 0  'Clear Timer
    
    StartRPM:
      If Capture = 0 then
         Goto StartRPM
      endif
    
      T1CON.0=1
      Capture = 0 
          
    CaptureLoop:
      If Capture = 0 then 
        Goto CaptureLoop
      endif
    T1Con.0=0  
    period.LowByte=CCPR1L
    period.HighByte=CCPR1H
    
    TMR1H = 0
    TMR1L = 0
    Capture = 0
    Overflow = 0 
    
    RPM = 10000
    RPM = RPM * RPM ' 100,000,000
    RPM = DIV32 period ' 100,000,000 / RevCount
    RPM = RPM * 60 ' Per minute
    RPM = DIV32 1600
    RPM = (RPM*5)
    
    SEROUT2 LCD,84, [Prefix,CursorPS,20,"RPM ",dec5 RPM]
    goto Calc_RPM_Timer 
    return

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