Hi all.
I have a problem with interrupt service on a PIC16F877A with 32768khz crystal
The thing is that i've set the timer0 on overflow interrupt and once at 10 seconds an A/D sample routine that is in page 1, must be called.
The problem is as follows:
If I set a flag in the isr and test that flag in the main then call the A/D routine, everything is ok,
but the thing is I don't want it to be like that, the A/D routine must be called from the isr
When the A/D routine is called from the isr the program locks or has a strange behaviour
here is an example of how it looks like
org 0x04
bcf INTCON,GIE
movwf w_safe ;given multiple banks, and no global memory
;you need to make a w_temp in each because you cannot change status prior to saving it.
swapf STATUS,W ;The swapf instruction, unlike the movf, affects NO status bits, which is why it is used here.
clrf STATUS ;point to bank 0 and clear all the flags
movwf status_safe
movf PCLATH,W ;save PCLath
movwf pclath_safe
clrf PCLATH ;assume that this ISR is in page 0
movf FSR,W
movwf fsr_safe
; ISR
;************************************************
btfss INTCON,T0IF
goto isr_1
bcf INTCON,T0IF
banksel tmr_cnt
incf tmr_cnt,F
movlw d'36'
subwf tmr_cnt,W
btfss STATUS,Z
goto isr_1
incf tmr_cnt2,F
clrf tmr_cnt
movlw d'10'
subwf tmr_cnt2,W
btfss STATUS,Z
goto isr_1
bsf chg_sample,0 ;sample it
clrf tmr_cnt2
pagesel AD_conv_chg ;when is called from here it's not working
call AD_conv_chg
isr_1
;***********************************************
movf fsr_safe,W
movwf FSR
;to complete the restore sequence.
movf pclath_safe,W
movwf PCLATH
swapf status_safe,W
movwf STATUS
swapf w_safe
swapf w_safe,W
retfie
Main
banksel chg_sample ;but it works like this
btfss chg_sample,0
goto m_1
pagesel AD_conv_chg
call AD_conv_chg
bcf PCLATH,3 ;main is in page 0
m_1
; rest of code
end
I have a problem with interrupt service on a PIC16F877A with 32768khz crystal
The thing is that i've set the timer0 on overflow interrupt and once at 10 seconds an A/D sample routine that is in page 1, must be called.
The problem is as follows:
If I set a flag in the isr and test that flag in the main then call the A/D routine, everything is ok,
but the thing is I don't want it to be like that, the A/D routine must be called from the isr
When the A/D routine is called from the isr the program locks or has a strange behaviour
here is an example of how it looks like
org 0x04
bcf INTCON,GIE
movwf w_safe ;given multiple banks, and no global memory
;you need to make a w_temp in each because you cannot change status prior to saving it.
swapf STATUS,W ;The swapf instruction, unlike the movf, affects NO status bits, which is why it is used here.
clrf STATUS ;point to bank 0 and clear all the flags
movwf status_safe
movf PCLATH,W ;save PCLath
movwf pclath_safe
clrf PCLATH ;assume that this ISR is in page 0
movf FSR,W
movwf fsr_safe
; ISR
;************************************************
btfss INTCON,T0IF
goto isr_1
bcf INTCON,T0IF
banksel tmr_cnt
incf tmr_cnt,F
movlw d'36'
subwf tmr_cnt,W
btfss STATUS,Z
goto isr_1
incf tmr_cnt2,F
clrf tmr_cnt
movlw d'10'
subwf tmr_cnt2,W
btfss STATUS,Z
goto isr_1
bsf chg_sample,0 ;sample it
clrf tmr_cnt2
pagesel AD_conv_chg ;when is called from here it's not working
call AD_conv_chg
isr_1
;***********************************************
movf fsr_safe,W
movwf FSR
;to complete the restore sequence.
movf pclath_safe,W
movwf PCLATH
swapf status_safe,W
movwf STATUS
swapf w_safe
swapf w_safe,W
retfie
Main
banksel chg_sample ;but it works like this
btfss chg_sample,0
goto m_1
pagesel AD_conv_chg
call AD_conv_chg
bcf PCLATH,3 ;main is in page 0
m_1
; rest of code
end