Interrupt RPM and Taylors Elapsed time on 18F4620


Closed Thread
Results 1 to 40 of 71

Hybrid View

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

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

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


    Did you find this post helpful? Yes | No

    Default

    Using the Full version.

    The free version doesn't let you draw your own circuits.
    <br>
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Thanks for the help on getting the RPM working right.

    Next question, when I want to incorporate this into other code how do I keep it from taking up as much time as just measuring the pulse width with Pulsin? I can't have it in the little CaptureLoop routine waiting for the next rpm pulse.

    Looking through the spec sheet on the 4620, I see CCP1IE (PIE1.2). If I enable that bit, will I get an interrupt on each cylinder fire? I know there is a way to start and stop timer1 based on the cylinder firing and not just looping for the cylinder firing.

    Here is what I am working on assuming that is the right path to take. I haven't worked with interrupts much so I am sure I need more work.
    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 
    Counter         var     word
    Detect          var     bit
    LCD             VAR     PortC.6    'LCD output
    
     
    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 = %00000110  ; Capture mode, every rising edge 0101 , Fourth 0110
    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
    PIE1.2=1      'Enables the CCP1 interrupt
    
    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
    Detect = 0
    
    ON Interrupt goto Measure_Time
    
    Loop:
      Counter = Counter + 1
      SEROUT2 LCD,84, [Prefix,CursorPS,0,dec5 Counter]
      SEROUT2 LCD,84, [Prefix,CursorPS,20,"RPM ",dec5 RPM, " ", #Detect]
    goto loop
    
    Disable
    Measure_Time:
    SEROUT2 LCD,84, [Prefix,CursorPS,40,"Int ",dec5 RPM]
    If Detect = 0  then
      T1CON.0=1
      detect = 1
      capture = 0
    endif
    
    If Detect = 1  then
      T1CON.0=0
      detect = 0 
      period.LowByte=CCPR1L
      period.HighByte=CCPR1H
      capture = 0
      TMR1H = 0
      TMR1L = 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)
    endif
    Enable
    return
    [HTML][/HTML]

  5. #5
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Thanks for the link. The thing is though I don't want to go into a loop waiting for the tach pulse. I want to be able to do it by interrupt so I can be doing other things in between pulses and on the pulse go start/stop the timer.

  7. #7
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Look at post #9. This is its main loop:
    Code:
    Main:
      ' do other stuff here as required
      IF CF.0 THEN         ' figure out & print result only after last capture
        PW = PW-T1         ' High pulse width = PW-T1
        CF.0 = 0           ' clear flag bit
        HSEROUT [DEC PW,"uS High",13,10]
      ENDIF
      
      GOTO Main

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