Capture loop exit


Closed Thread
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Capture loop exit

    Hi Shawn,
    As far as I can see you have two options, software and hardware.
    Use a timer interrupt (or poll the interrupt flag) to abort the wait loop OR use a software "timer" to abort the wait loop. If you, for whatever reason, don't want to increment a variable (software "timer") inside your waitloop then the only option left is hardware. I see no reason why you can't use TMR1 if you want to, just reset it when the trigger comes.

    I've never used the capture module though so I may be missing something.

    /Henrik.

  2. #2
    Join Date
    Apr 2007
    Location
    Pennsylvania, USA
    Posts
    158


    Did you find this post helpful? Yes | No

    Default Re: Capture loop exit

    Thanks Henrik,
    I was concerned that stopping the timer and restarting it would throw off the measurement, as I am sure it would. I tried it with just clearing the timer registers and tested it, and all seems good. Just checking for a timer overflow which if occurred will exit the capture routine.

    Code:
      TMR1H=0      'Clear 8-bit register                              
      TMR1L=0      'Clear 8-bit register
      T1CON.0=1    'starts timer  
      overflow=0   'Clear overflow bit
      capture=0    'Clear Timer
    Trash:
      If Capture = 0 then
         if overflow=1 then 
           rpm=0
           T1Con.0=0  
           return
           endif    
        Goto Trash          
      endif
      TMR1H=0      'Clear 8-bit register                              
      TMR1L=0      'Clear 8-bit register
      Capture=0    'waste first capture
      Overflow=0   'Clear overflow bit     
    CaptureLoop:
      If Capture = 0 then
         if overflow=1 then 
           rpm=0
           T1Con.0=0  
           return  
           endif  
        Goto CaptureLoop
      endif
    T1Con.0=0  
    period.LowByte=CCPR1L
    period.HighByte=CCPR1H
      TMR1H = 0
      TMR1L = 0
      Capture = 0
      Overflow = 0
    Shawn

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