Hi,
From the code bellow, I am expecting to have the DEBUG line running only when the variable "ReadFlag" is set and it does, so far so good.
But once it ran, I clear ReadFlag and it should become set again ONLY if I=10 and this should happen only after the Interrupt has ran 10 times right? Well it is not happening.

In my DEBUG line "I" shows up as 0,2,4,5 randomly
I am not using variable "I" anywhere else other than:
Code:
I VAR BYTE
I = 0
at the top of my program.


Can someone help me understand this?

Code:
Goto main 
    
Main:
    DO while readflag = 1 
        debug dec Fvalue," i=",dec i," R=",dec readflag,10,13  ; Display on terminal if ReadFlag = 1
        readflag = 0            ; do not update until the next 10 readings
        Fvalue = 0
    LOOP
goto main

'---[INT - interrupt handler]------Signal found at RB0, take a reading
SignalFound:
    T1CON.0 = 0                             ; Stop timer1
    i = i + 1                               
    FValue = TMR1H * 256 + TMR1L + fvalue   ; Add 10 readings to FValue
    if i = 10 then
        fvalue = fvalue / 10                ; get the average of one reading
        i = 0                               ; Reset counter
        ReadFlag = 1                        ; FValue is ready to read 
    endif        
    TMR1H = 21                              ; reset timer1 to 60mS
    TMR1L = 167
    T1CON.0 = 1                             ; Start timer1
@ INT_RETURN
Thanks

Mike