problem with asm interrupt


Closed Thread
Results 1 to 6 of 6
  1. #1
    servo260's Avatar
    servo260 Guest

    Default problem with asm interrupt

    Hi,

    I'm trying to use asm interrupts in pbp but I have the following problem:

    the interrupt works fine, but the main program works at "half" if that makes sense, it only run a part of the main program while doing the interrupt.

    here is the simple code i'm using to test it:

    define osc 20


    clear

    pulsos var word

    x var word

    num var byte

    wsave var byte $20 system
    ssave var byte bank0 system
    psave var byte bank0 system



    TRISA = %11111111 ; configura el puerto A como salida

    TRISB = %10000000 ; configura los puertos B0-6 como salida



    goto start ; salta al programa principal antes que la interrupcion



    define INTHAND display ; indica cual es la interrupcion







    start:

    option_reg = %00000111

    intcon = %10100000


    main:

    x = 123

    pause 500

    x = 321

    pause 500

    goto main


    asm
    display movwf wsave ; display rutine
    swapf STATUS, W
    clrf STATUS
    movwf ssave
    movf PCLATH, W
    movwf psave
    endasm

    num = x dig 0

    portb = num

    high portb.4

    pauseus 50

    low portb.4

    num = x dig 1

    portb = num

    high portb.5

    pauseus 50

    low portb.5

    num = x dig 2

    portb = num

    high portb.6

    pauseus 50

    low portb.6

    asm
    bcf INTCON, 1

    movf psave, W
    movwf PCLATH
    swapf ssave, W
    movwf STATUS
    swapf wsave, F
    swapf wsave, W

    retfie
    endasm


    the problem is I only get to see the 123.



    If someone knows how to solve this please help me.

    Thanks.

  2. #2
    servo260's Avatar
    servo260 Guest


    Did you find this post helpful? Yes | No

    Default

    I have change the bcf INTCON.1 to INCON.2 but it is still not working.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    At 20MHz with a TMR0 prescaler of 1:256 you only have 13mS before TOIF will be set again, and generate the next interrupt.

    You're using 500mS delays in main with a 13mS TMR0 interrupt time. Try a delay time shorter than your interrupt time, or save & restore the registers used to hold the delay value, or insert your long delay within the body of the interrupt routine.

    You can delay inside the interrupt routine as long as you like before the RETFIE, but I would reload TMR0 with 0 before resetting TOIF.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    servo260's Avatar
    servo260 Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks, though, it is still not eorking.
    How do I save & restore the registers used to hold the delay value? ; what do I have to save in order to continue whatever thing the program was doing?

    I'm new with pics and pbp.

  5. #5
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    You're using Basic statements in your Assembler interrupt. That's a big nono unless you save and restore PBPs workingregisters. Looking at the compiled code it seems that R0 through 3 is used. Try adding ......

    r0save = R0
    r1save = R1
    r2save = R2
    r3save = R3

    ...... directly after your first ASM block, and ........

    R0 = r0save
    R1 = r1save
    R2 = r2save
    R3 = r3save

    .... right before your second ASM block.

    You should also declare your new variables at the top of your program .......

    r0save VAR WORD bank0
    r1save VAR WORD bank0
    r2save VAR WORD bank0
    r3save VAR WORD bank0

    /Ingvar

  6. #6
    servo260's Avatar
    servo260 Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks, everithing is working fine.

Similar Threads

  1. problem using GOSUB under interrupt
    By fobya71 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 5th March 2010, 19:52
  2. 18F2480 asm interrupt
    By Richard Storie in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th March 2009, 19:40
  3. Problem with Interrupt on PIC18F4620 PORTB
    By rookie in forum Off Topic
    Replies: 1
    Last Post: - 22nd March 2007, 01:34
  4. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  5. Interrupt stack overflow problem with Resume {label}
    By Yuantu Huang in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd May 2005, 01:17

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