Yes the chg_sample is cleared in the AD routine.
The bcf PCLATH,3 is put because those routines are in page 0
AD_conv_chg
bcf STATUS, RP1
bsf STATUS, RP0 ;bank 1
movlw b'10000101' ;RA0,RA1 analog input, Vref+,Vref- internal
movwf ADCON1
bcf STATUS,RP0 ;bank 0
movlw b'11001001' ;A/D module on, conversion clock RC, channel selected 1
movwf ADCON0
bsf ADCON0,2 ;start conversion
;wait for the conversion to end
btfsc ADCON0,2
goto $-1
movf ADRESH,W
andlw 0x03 ;clear upper 6 bits of ADRESH to make sure
movwf NumH
movwf adresH2_tmp
bsf STATUS, RP0 ;bank 1
movf ADRESL,W
bcf STATUS, RP0 ;bank 0
movwf NumL
movwf adresL2_tmp
bcf PCLATH,3
call Convert ;these lines are used to see the value of the A/D result
movlw 0x0A
bcf PCLATH,3
call LCD_Line2W
movf Hund,W
bcf PCLATH,3
call LCD_CharD
movf Tens,W
bcf PCLATH,3
call LCD_CharD
movf Ones,W
bcf PCLATH,3
call LCD_CharD
res_compare
;here the result is compared with a previously result
banksel adresH3_tmp
movf adresH3_tmp,W ;Xhi
banksel adresH2_tmp
subwf adresH2_tmp,W ;Yhi
btfss STATUS,Z
goto res_16
banksel adresL3_tmp
movf adresL3_tmp,W ;Xlo
banksel adresL2_tmp
subwf adresL2_tmp,W ;Ylo
res_16
;if X<=Y then STATUS,C=1,and store the result in adresH3_tmp, and andresL3_tmp
btfss STATUS,C
goto ad2_3
movlw 0x09
bcf PCLATH,3
call LCD_Line2W
movlw 'X' ;these are here to see if compare works and it does
bcf PCLATH,3
call LCD_Char
bsf PCLATH,3
goto ad2_1
ad2_3
movlw 0x09
bcf PCLATH,3
call LCD_Line2W
movlw '<'
bcf PCLATH,3
call LCD_Char
bsf PCLATH,3
bcf INTCON,T0IE ;disable timer0 int
goto ad2_2
ad2_1
banksel adresL2_tmp
movf adresL2_tmp,W
banksel adresL3_tmp
movwf adresL3_tmp
banksel adresH2_tmp
movf adresH2_tmp,W
banksel adresH3_tmp
movwf adresH3_tmp
ad2_2
bcf STATUS,RP0
bcf STATUS,RP1
clrf chg_sample
return
The chg_sample flag is no longer needed if the routine is called from isr, but as i said before it dosen't really work when is called from isr