Problem with ASM IRQ using FSR0 on PIC18F252


Results 1 to 11 of 11

Threaded View

  1. #1
    mytekcontrols's Avatar
    mytekcontrols Guest

    Question 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?
    Last edited by mytekcontrols; - 14th June 2005 at 01:56.

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  2. PBP, ASM and LST files
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th January 2010, 13:43
  3. Problem using ASM instruction
    By ewandeur in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd April 2008, 15:26
  4. pic18f252 hserout problem
    By edysan in forum Serial
    Replies: 4
    Last Post: - 16th June 2006, 20:46
  5. problem with asm interrupt
    By servo260 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 20th December 2004, 17:02

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts