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

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


    Did you find this post helpful? Yes | No

    Default

    I've already ordered you the 4431. Sorry I placed the order before I knew you needed
    or wanted 3. But I'm still holding the at cost offer open if you want this one even
    if/when Darrel proves me wrong - which he does way too often...;o)

    These really are some cool PICs'.

    If you don't mind my asking - what boards are you using? Surely you're not de-soldering
    and replacing TQFP package types!
    Regards,

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

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Yea I will take a couple of the PICS no matter the outcome here. One way or another I want to get it working right. I need to use DT's elapsed time file and also interrupt rpm at the same time. So I can't go back to the 877A unless there is another approach.

    Desoldering the TQFP's is pretty easy. Not something I want to do often but when needed I have the technique down.

    Thanks to both of you on helping me get this sorted out too.

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


    Did you find this post helpful? Yes | No

    Default

    Proteus Rules.

    Here's what I found.
    After the capture was made, and the math completed, the result is displayed with a SEROUT2 to the LCD.

    But at 9600 baud, by the time it gets around to displaying CCPR1L and CCPR1H, multiple captures have taken place without Timer1 being cleared.

    If you use this line instead, you get the same numbers on both chips and they are the right ones.

    Code:
    SEROUT2 LCD,84, [Prefix,CursorPS,20,"RPM ",dec5 RPM, " ", DEC5 period]
    <object id='stUkhdQ01IR19bR15YXVpZVFJV' width='425' height='344' type='application/x-shockwave-flash' data='http://www.screentoaster.com/swf/STPlayer.swf' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0'><param name='movie' value='http://www.screentoaster.com/swf/STPlayer.swf'/><param name='allowFullScreen' value='true'/><param name='allowScriptAccess' value='always'/><param name='flashvars' value='video=stUkhdQ01IR19bR15YXVpZVFJV'/></object><div style='width: 425px; text-align: right;'><a href='http://www.screentoaster.com/'>Capture your screen in seconds</a></div>

    My SEROUT2 was a little different ...
    SEROUT2 LCD,84, ["RPM ",dec5 RPM, " ", DEC CCPR1H<<8+CCPR1L," ",DEC period," Ovr:",BIN1 Overflow,13,10]

    The small pulse I measured was the time to do the math.
    The big pulse was the time for SEROUT2.
    The original SEROUT2 was shorter, and around 20mS.
    <br>
    Last edited by Darrel Taylor; - 29th January 2010 at 04:32. Reason: more more more
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Nope...

    Lets say we had ten thousand captures after this;
    Code:
    Loop:
    TMR1H = 0    'Clear 8-bit register                              
    TMR1L = 0    'Clear 8-bit register
    capture = 0  'Clear Timer
    'SEROUT2 LCD,84, [Prefix,CursorPS,0,"Capture ", dec Capture," ",DEC Period]
    Start:
          If Capture = 0 then
             Goto Start
          endif
    
          T1CON.0=1
          Capture = 0 
          
    CaptureLoop:
      If Capture = 0 then 
        'SEROUT2 LCD,84, [Prefix,CursorPS,0,"Dont Capture ", dec Capture," ",DEC Period]
        Goto CaptureLoop
      endif
    T1Con.0=0  
    period.LowByte=CCPR1L
    period.HighByte=CCPR1H
    They would all be zero since TMR1 was disabled after the T1CON.0=0.
    Once period = CCPR1L & CPR1H it's a done deal until the next capture,
    and Timer1 is re-enabled.

    Capture works wether or not Timer1 is enabled. It just returns 0 if it's off.

    Yet - I may be missing something...
    Last edited by Bruce; - 29th January 2010 at 05:20.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    Yup...

    But that's a very interesting point.

    In the 4620 program it does turn off the timer at that point.
    But the 877A program does not.

    And you can even see the difference in the simulation.
    The 4620 always has the same values for CCPR1L:H and period (+1?), but the 877A doesn't.

    4620
    Code:
          T1CON.0=1
          Capture = 0 
          
    CaptureLoop:
    If Capture = 0 then 
      Goto CaptureLoop
    endif
    T1Con.0=0  
    period.LowByte=CCPR1L
    period.HighByte=CCPR1H
    
    RPM = 10000
    877A
    Code:
     T1CON.0 = 1             ' Start the Timer
     capture = 0             ' Reset  the capture flag
     
    CaptureLoop:
    IF capture = 0 Then 
      goto CaptureLoop	' Wait here until captured
    endif
    ; nada  
    period.lowbyte = CCPR1L		' Store the captured value in
    period.highbyte = CCPR1H	' period variable
    
    RPM = 10000
    And when a Timer is turned off, it retains the last value in the TMR?L:H registers.
    <br>
    DT

  7. #7


    Did you find this post helpful? Yes | No

    Default

    With all that in mind, what do I need to change from the last code I posted to get RPM correct?

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


    Did you find this post helpful? Yes | No

    Default

    Hey Darrel,

    Disabling TMR1 after the event has zero affect on the value that CCPR1l & CCPR1H record at the time of the event. The value in Timer1 is captured immediatley on event.

    Can you recommend something for the OP that wiil fix it?

    If you can -- he gets the free PIC, and I'll send you a six-pack of your favorite BEER...

    FYI: Disabling the timer after the capture event has zero effect on the value captured by the hardware catpure module.

    Remember ... It's done in hardware
    Last edited by Bruce; - 29th January 2010 at 06:06. Reason: FYI
    Regards,

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

  9. #9
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default

    Darrel, help me understand here...

    I thought that Proteus dealt with many versions of compilers except PBP.

    Are you just running the already compiled program and reverse troubleshooting in your head? I imagine that watching the registers would let you know where you are at and if you could transpose between the two, it would work.

    Care to elaborate on how you use it to help you?
    Bo

  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 boroko View Post
    I thought that Proteus dealt with many versions of compilers except PBP.
    Currently, you can only simulate the .hex files directly in Proteus.
    No single stepping through the program.

    But you can use it as a debugger in MPLAB where you can single step and watch variables in PBP.
    It's too slow for me that way though. It simulates in "Real-Time" when not animating.

    It's like real hardware is sitting in front of you, only you can't create Smoke or Fry your chips.
    I'm getting hooked on it.

    It's just so nice not to have to build a breadboard to test things.
    20 minutes, and you can draw it on the computer.

    Plus, with the Logic Analyzer, O-Scope, I2C debugger etc.
    It saves thousands on test equipment.

    And my cats can't play with the wires.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    Are you using the free or full version?
    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