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:
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.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
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?




Bookmarks