Problem with ASM IRQ using FSR0 on PIC18F252
I have a 6 digit counter routine incorporated as an ASM IRQ on a PIC18F252 under MEL PicBasic Pro. It utilizes in-direct addressing of a 6 byte array to update and store the counter's count. The problem is that the part of the routine that is supposed to clear a digit as it rolls over from 9 doesn't always work. Here is the partial code showing only the UP counting module:
Code:
DEFINE INTHAND myint
Ecount var byte[6] bankA
fsave var word bankA system
loopcount var byte
Goto Start ' jump past interrupt routine
;================================================
asm
myint
; save the FSR value because it gets changed below
movf Low FSR0, W
movwf fsave
movf High FSR0, W
movwf fsave+1
;-------------------------------------------------------
;polling and calling routine for counter
;-------------------------------------------------------
; (code not shown)
;-------------------------------------------------------
;6 digit count up module - each entry increments counter
;-------------------------------------------------------
countup
clrf _loopcount
;set base address of array
movlw Low _Ecount
movwf FSR0L
movlw High _Ecount
movwf FSR0H
inc_loop
movlw d'9'
subwf INDF0,W
btfsc STATUS, Z ; Have we hit top for this digit?
goto nextdigit ; Yes, go to next!
incf INDF0,F ; else keep incrementing it, and...
goto restore ; leave!
nextdigit
clrf POSTINC0 ; (clear INDF and increment FSR)
incf _loopcount,F
movlw d'6'
subwf _loopcount,W
btfss STATUS, Z ; Have we checked all 6 digits?
goto inc_loop ; No go to next!
;restore registers
restore
movf fsave, W
movwf Low FSR0
movf fsave+1, W
movwf High FSR0
retfie FAST
endasm
;================================================
Start:
;-------------------------------------------------------
;PBP interrupt init and counter display
;-------------------------------------------------------
; (code not shown)
End
The problem when it manifests is that a given digit will continue to increment beyond the number 9. It is as if the array byte pointed to by the FSR has changed momentarily, thereby missing the check for zero after subtracting 9.
Is code generated by PBP able to interfere with the in-direct addressing? The reason I ask this is, that I originally coded the counter routine without using FSR and instead used Ecount+1, Ecount+2, ect. to access the array. I achieved reliable counting using this method, although at the cost of considerably more code.
The problem is very intermittent with the FSR routine. So this too tends to point to outside influences causing the glitch. Has anyone else encountered such a problem when using SR's and interrupts under PBP?
using the code at a pic 18f452
I have tried to use the code on a 18f452 - but it dont works... At the beginnig there were many error messages from the Compiler.
Therefore I´ve done the following modifications:
1.changed the rrf instructions to rrcf
2.changed the rlf instructions to rrcf
3.at "enc_exit" I changed
"bsf _AUTOdispNEW ; flag that encoder value has changed"
to
"bsf _AUTOdispNEW,0 ; flag that encoder value has changed"
4. I defined the following Variables:
TMR1ON VAR BIT
TMR1IF Var BIT
TMR1IE VAR BIT
TMR1IP VAR BIT
IPEN VAR BIT
TMR1ON = T1CON.0
TMR1IF = PIR1.0
TMR1IE = PIE1.0
TMR1IP = IPR1.0
IPEN = RCON.7
Now it compiles well, but do not work :-(
To tell the truth I have no expirience with assembler but I have to decode the quadencoder and with PBP I´m loosing counts.
Thanks in advance
Jan