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

    This appears to be working correctly. Are there any problems going this route?
    Of course this isn't all the code, just the part that is relevant.
    Code:
    DEFINE INTHAND Direction 
    
    ASM
    Direction
    ENDASM
      If PIR1.2 = 1 then
        goto RPMASM
      endif
      
      If PIR2.1 = 1 then
        goto ClockCount
      endif
    return  
    
    RPMASM: 
    ASM
    CCP_INT
      BTFSS CCP1CON,0      ; capture from rising edge?
      BRA Fall             ; no .. goto falling edge
      MOVFF CCPR1L, TS    ; get low capture byte into T1
      MOVFF CCPR1H, TS+1   ; get high capture byte into T1
      BRA IntExit          ; outta here
    Fall
      MOVFF CCPR1L, PW     ; get low capture byte into PW
      MOVFF CCPR1H, PW+1   ; get high capture byte into PW
      BSF CF,0             ; indicate last capture
    IntExit
      BTG CCP1CON,0        ; toggle between rising/falling edge captures
      BCF PIR1,2           ; clear capture interrupt flag bit
      RETFIE FAST          ; return/restore W, STATUS and BSR
    ENDASM
    
    ClockCount:   ' Note: this is being handled as an ASM interrupt
    @ INT_START
    @ RELOAD_TIMER                    ; Reload TIMER1
      R0save = R0                     ; Save 2 PBP system vars that are used during
      R1save = R1                     ; the interrupt
      R4save = R4
        Ticks = Ticks + 1
        if Ticks = 1000 then
           Ticks = Ticks-1000
           Seconds = Seconds + 1
           SecondsChanged = 1
           if Seconds = 60 then
              Minutes = Minutes + 1
              MinutesChanged = 1
              Seconds = 0
           endif
           if Minutes = 60 then
              Hours = Hours + 1
              HoursChanged = 1
              Minutes = 0
           endif
           if Hours = 24 then
              Days = Days + 1
              DaysChanged = 1
              Hours = 0
           endif
        endif
      R4 = R4save                     ; Restore the PBP system vars
      R1 = R1save
      R0 = R0save
    @ INT_RETURN                      ; Restore context and return from interrupt

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


    Did you find this post helpful? Yes | No

    Default

    You don't need the bit tests in Direction since you have CCP_INT (or Direction) set as a high-priority interrupt, and you have ClockCount set as a low-priority interrupt.

    Direction will be jumped to automatically when the CCP interrupt fires. ClockCount will be jumped to automatically when the TMR3 interrupt fires. Note that your low-priority interrupt can be interrupted by the high-priority one.
    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