Hello Xyvind, I've had exactly the same problem when worked with digital thermometer TMP03. It had about 30 Hz output and pulse width and period should have been measured both. Your problem lies in TMR0 overflow when it is not detected. See, what happens on INT interrupt, if your code goes to nex_chk_1 and TMR0 overflows at this moment, before you read TMR0... You will get error of about 256. After filtering it reduces to 5-6 bits, I guess. This code may help: BANK0 ;set bank here btfss INTCON,T0IF ;Timer interrupt? goto nex_chk_1 incf TIMER,f ;Yes, increasing high byte bcf INTCON,T0IF ;Clearing timer interrupt nex_chk_1 btfss INTCON, INTF goto end_handler movf TMR0, w ;read TMR0 register btfsc INTCON, T0IF ;check for overflow movlw 255 ;correct low byte ;(reduces error to a couple of lsb's) clrf TMR0 ;clear TMR0 immediately movwf TIMER_STR ;store low byte movf TIMER, w movwf TIMER_STR+1 ;Saving TIMER in high byte clrf TIMER bsf STAT,0 ;Sets a status bit to indicate that a new ;count value is ready end_handler bcf INTCON, T0IF bcf INTCON, INTIF Bye, Nikolai On Monday, February 07, 2000 Xyvind Kaurstad wrote: > Ok, guys. > I'm having some trouble, and I can't get it figured out. > I'm building a device that's sampling the RPM of an engine. > The incoming signal is therefore in the range of max 350 Hz, and it > is connected to RB0. > I need to accurately count the time *between* pulses, to get a number > that is inversely proportional to the RPM. > The TMR0 and the external interrupt is used. (16F84) > I've programmed the TMR0 to run with a prescaler of 1:2, so the TMR0 > frequency should be 1.25 MHz. > I want to have a 16 bit counter, so in the interrupt routine I > increment a register for each TMR0 interrupt. This is the high byte > of my counter. > When the external interrupt occurs, I read both the TMR0 and this > register. Together they are transferred to another 16 bit variable > that is used by the rest of the code. Then the TMR0 and the high byte > register is cleared, and I exit the ISR. > What troubles me is that I get a lot of jitter on my count value. > A lot more than I would expect. The latency of the TMR0 interrupt > should not bother me, since in the part of the ISR that handles this > I just increment the high byte and then exits. The TMR0 itself is not > tampered with. > The latency that I get when the external interrupt occurs will cause > a little bit of jitter, since I'm reading the TMR0, but it shouldn't > be more than a couple of bits, especially since the TMR0 is running > at half the instruction cycle. > Any good hints? > I don't have the code here, but I can post that later if necessary. > _______________________________________________ > Xyvind Kaurstad, oyvind@safetel.no > Safetel AS > P.B. 405, N-4067 Stavanger, Norway > Tel: +47 51 81 78 80 (Switchboard) > +47 51 81 78 82 (Office) > +47 51 81 78 93 (Fax)