Searching \ for 'Mysterious Timer0 dropout problem' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/timers.htm?key=time
Search entire site for: 'Mysterious Timer0 dropout problem'.

Truncated match.
PICList Thread
'Mysterious Timer0 dropout problem'
1997\03\11@084822 by Rick Kozak

flavicon
face
I'm using a 16C74 to do a project where I get the sanitized version of a
real world signal as the input to RB0 (external interrupt). Because this
signal can be noisy, I can receive several edges from one event. To filter
out the extraneous pulses, I decided to disable the external interrupt and
run timer0 for one cycle at maximum scale (gives me a 32msec window where I
can ignore edges). In the interrupt handler for timer0, I turn it off, and
make INTE=1 again. (I'm using timer1 and timer2 for other things already).

Now this setup works ... most of the time. Every once in a while (probably
15 - 20 seconds), I miss a timer0 interrupt. Which means that I never
reenable RB0, and miss a bunch of legitimate edges. My data collection
routine runs every 8 seconds so when it notices that no edges have been
detected since the last time, it reinitializes and I carry on. However, it
would be better if this didn't happen at all.

Has anybody else ran into this kind of thing? Any suggestions as to what I
could try? I could just allow all interrupts and filter them after the
fact, but I'd rather just not process the interrupt in the first place.

thx
rick

1997\03\11@093212 by myke predko

flavicon
face
Rick Kozac wrote:

>I'm using a 16C74 to do a project where I get the sanitized version of a
>real world signal as the input to RB0 (external interrupt). Because this
>signal can be noisy, I can receive several edges from one event. To filter
>out the extraneous pulses, I decided to disable the external interrupt and
>run timer0 for one cycle at maximum scale (gives me a 32msec window where I
>can ignore edges). In the interrupt handler for timer0, I turn it off, and
>make INTE=1 again. (I'm using timer1 and timer2 for other things already).
>
>Now this setup works ... most of the time. Every once in a while (probably
>15 - 20 seconds), I miss a timer0 interrupt. Which means that I never
>reenable RB0, and miss a bunch of legitimate edges. My data collection
>routine runs every 8 seconds so when it notices that no edges have been
>detected since the last time, it reinitializes and I carry on. However, it
>would be better if this didn't happen at all.
>
>Has anybody else ran into this kind of thing? Any suggestions as to what I
>could try? I could just allow all interrupts and filter them after the
>fact, but I'd rather just not process the interrupt in the first place.

This sounds like a button debounce routine.

To debounce a button without interrupts, I use:

ButtonPress

 btfsc  PORTB, 0               ;  Wait for Button to go Low
  goto  $ - 1

 clrf   TMR0                   ;  Reset the Timer to wait for a Stable I/P
 bcf    INTCON, T0IF

ButtonWait

 btfsc  PORTB, 0               ;  Is the Timer Still Low?
  goto  ButtonPress            ;   No - Wait for it to Go Low Again
 btfss  INTCON, T0IF           ;  Has the Timer Timed Out?
  goto  ButtonWait             ;   No, Keep Polling the Line

That's it.  It can be easily modified for Interrupts.

ie:

Int                             ;  Have an Interrupt

 movwf  _w                     ;  Save the Context Registers
 movf   STATUS, w
 movwf  _status

 btfss  INTCON, T0IF           ;  Do we Have a Timer Interrupt?
  goto  Int_Button             ;   No - Handle the Button Press

 bcf    INTCON, T0IF           ;  Reset and Disable the Timer Interrupt
 bcf    INTCON, T0IE

;  #### - Set a Flag to Indicate that the Noise has stopped

 goto   IntEnd

Int_Button                      ;  Button Pressed, Start Timer

 bcf    INTCON, RBIF           ;  Reset the Button Interrupt

 clrf   TMR0                   ;  Reset the Debounce Timer
 bsf    INTCON, T0IE           ;  Enable and Reset the Timer Interrupts
 bcf    INTCON, TOIF

IntEnd

 movf   _status, w             ;  Restore the Context Registers
 movwf  STATUS
 swapf  _w
 swapf  _w, w

 retfie

.                               ;  Mainline Code
:

 movlw  0x080 + ( 1 << RBIE )  ;  Enable RB Interrupt
 movwf  INTCON

;  #### - Poll on the Button Pressed Flag


The interrupt routine is a bit more complex, but allows you to wait for a
button press in the background.

Good Luck,

myke

"Some people say that foreign cars handle best, while others say domestic.
For my money, nothing handles as well as a rental car." - P.J. O'Rourke

1997\03\11@100301 by Andy Kunz

flavicon
face
It looks like you're trying to measure a pulse width or time between edges.

I like to use the Capture (CCP) for this.

Basic idea:

Set up capture for falling edge trigger.
Loop
       if a falling edge was captured
               clear falling edge captured flag
               process edge
       endif
       if a rising edge was captured
               clear rising edge captured flag
               process edge
       endif
Endloop (forever)

On interrupt:
save all registers
if this was a falling edge (I keep a bit variable to tell me what I'm
looking at)
       if the edge is still down (it's been about 20uS by the time I get here..
.)
               record time of the edge (Timer1)
               set to capture rising edge
               flag that we are capturing rising edge now
               flag that a falling edge was captured
       else
               nothing - ignore this edge as pulse was too short
       endif
else (it was a rising edge)
       if edge is still high
               record time of edge, or Timer1 - stored (falling) edge
               set to capture falling edge
               flag that we are capturing falling edge now
               flag that a rising edge was captured
       else
               nothing
       endif
endif
clear interrupt flag
restore registers
retfie



At 08:52 AM 3/11/97 -0500, you wrote:
{Quote hidden}

==================================================================
Andy Kunz - Montana Design - 409 S 6th St - Phillipsburg, NJ 08865
         Hardware & Software for Industry & R/C Hobbies
       "Go fast, turn right, and keep the wet side down!"
==================================================================

1997\03\11@123550 by sdattalo

face
flavicon
face
Rick Kozak wrote:
>
>                                                             Because this
> signal can be noisy, I can receive several edges from one event. To filter
> out the extraneous pulses, I decided to disable the external interrupt and
> run timer0 for one cycle at maximum scale (gives me a 32msec window where I
> can ignore edges).

Rick,

Take a look at my debouncing routine:

http://www.interstice.com/~sdattalo/technical/software/pic/debounce.html


Scott

More... (looser matching)
- Last day of these posts
- In 1997 , 1998 only
- Today
- New search...