PDA

View Full Version : Very Trouble with 8722 Interrupt



smarino
- 4th March 2009, 14:29
In many case (but random) when PIC18F8722 go to IRQ handler, some Ram variables changes their value with dramatic conseguence in the flow of process. This is the source of IRQ :
'************************************************* *********
' Assembly language INTERRUPT handler
Asm
GlbInt
;^^^^^
; Save the state of critical registers
;************************************************* *************************************************
; Select How Interrupt Occur
MOVWF wsave ; wsave is W
MOVFF STATUS, ssave ; ssave is STATUS
MOVFF FSR0, fsave ; fsave is BSR
MOVFF FSR1, fsave1
MOVFF FSR2, fsave2
MOVFF BSR, bsave
;
RXF btfsc _RC1IF
call _RxIRQ ; Routine Interrupt EUSART1 Receiver
;
T0F btfsc _TMR0IF
call _timer0IRQ ; Routine Interrupt Timer0
;
T1F btfsc _TMR1IF
call _timer1IRQ ; Routine Interrupt Timer1
;
;************************************************* *************************************************
; Restore
finished
;
MOVFF bsave, BSR
MOVFF fsave2, FSR2
MOVFF fsave1, FSR1
MOVFF fsave, FSR0 ; Restore BSR
MOVFF ssave, STATUS ; Restore STATUS
MOVF wsave, W ; Restore WREG
RETFIE
;
EndAsm
'
asm
'************************************************* ********
' Those the IRQ variables :
'************************************************* ***************
'Interrupt used variables
wsave var byte $100 system ' Saves W
ssave var byte $101 system ' Saves STATUS
fsave var word $102 system ' Saves FSR0
fsave1 var word $104 system
fsave2 var word $106 system
bsave var word $108 system

Can I make something ???? Thank's so much. Pheraps isn't valid save stack routine for this MCU. I'ved copy this for a 16f877 MCU and adaptate to 18f8722.

Sorry for language.

Acetronics2
- 4th March 2009, 15:10
Hi,

I'm not a 18F Specialist ...

but smells Some Banking issues ... ???

Alain

Darrel Taylor
- 5th March 2009, 02:43
The constants FSR0, FSR1 and FSR2, are only for use with the LFSR (Load File Select Register) opcode.
They equate to 0, 1 and 2 respectively.
Using them with MOVFF, causes it to save/restore the memory at locations 0, 1 and 2, which are normally PBP's system variables.

On 18F's, the FSR's have 12-bit addresses, so it takes 2-bytes to hold each one.
For FSR0, the actual values are in FSR0L and FSR0H. If you are saving them, you need to save both.

But you only need to save the FSR's if they are also used by the interrupt handler. If you're handler doesn't use them ... it's just waisting time.
 
The MOVWF opcode, requires that the BANK be set first, but you can't set the bank at that point, because the BSR register hasn't been saved yet.
Use MOVFF WREG, wsave instead.
 
If you are using High Priority interrupts? Then you don't need to save WREG, STATUS or BSR. They are automatically saved by the CPU when the interrupt occurs.
Then use RETFIE 1 (FAST return).
 
You are calling routines with underscores in front of them.
You aren't calling BASIC code from an ASM interrupt are you?

smarino
- 5th March 2009, 09:38
Well then I must only use a RETFIE FAST and no "PUSH/POP" anythings in IRQ routine.
as :




' Assembly language INTERRUPT handler
Asm
GlbInt
;
;
RXF btfsc _RC1IF
call _RxIRQ ; Routine Interrupt EUSART1 Receiver (in basic code)
;
T0F btfsc _TMR0IF
call _timer0IRQ ; Routine Interrupt Timer0 (in basic code)
;
T1F btfsc _TMR1IF
call _timer1IRQ ; Routine Interrupt Timer1 (in basic code)
;
;************************************************* *************************************************
; Restore

RETFIE FAST
;
EndAsm


Is possible getback any confirm or suggestion ?
Thank'you very much.

Darrel Taylor
- 5th March 2009, 09:48
Is possible getback any confirm or suggestion ?
Since you are trying to call BASIC language routines from an ASM interrupt ... there is only one thing I can recommend....

DT_INTS-18
http://darreltaylor.com/DT_INTS-18/home.html
<br>