still on 16f18877, can't enter interrupt

Author
__angelo__
Starting Member
  • Total Posts : 56
  • Reward points : 0
  • Joined: 2010/12/02 02:39:25
  • Location: 0
  • Status: online
2018/11/08 04:37:23 (permalink)
0

still on 16f18877, can't enter interrupt

Hi all,
still on porting asm code from 16f877 to 18877.
The interrupt (after brief rework on PIR/PIE registers) seems
never entered.
 
 ; preparing timer 2 for interrupt based scheduling

 banksel T2CON
 clrf T2CON ; stop timer assign 1:1 post and prescaler
 clrf TMR2 ; clear timer
 banksel PIR4
 bcf PIR4,TMR2IF ; clear overflow flag
 movlw t2match ; get match value
 banksel PR2 ; turn to page 2
 movwf PR2 ; set matchregister
 banksel PIE4
 bsf PIE4,TMR2IE ; allow timer2 interrupt
 banksel T2CON ; go back to page 1
 bsf T2CON,TMR2ON ; start timer

; Interrupts start
 bsf INTCON,PEIE ; enable peripheral int
 bsf INTCON,GIE ; allow ints in general

aab:
 clrwdt
 goto aab
 
 
 
 
 
 
    org     04h   
 
 
 
 
interrupt
    movwf    w_save
    swapf    STATUS,w
    movwf    status_save

    clrf    INTCON
    pagesel    square
    call    square
 
 
 
 
 
 
 
 
 
 
 
square:
    bcf    INTCON,GIE
    banksel    PORTD
    movlw    0
    movwf    TRISD
    banksel    ANSELD
    movlw    0
    movwf    ANSELD
    banksel    PORTD
sqloop:
    movlw    0xff
    movwf    PORTD
    nop
    nop
    nop
    movlw    0
    movwf    PORTD
    nop
    nop
    nop
    clrwdt
    goto    sqloop
    return

 
In the interrupt routine (at 4) i am just toggling PORTD (after proper ANSEL/TRIS setup).
But seems i never enter.
 
 
 
 
post edited by __angelo__ - 2018/11/08 04:42:15

o/ Angelo
 
#1

9 Replies Related Threads

    vloki
    Jo, alla!
    • Total Posts : 6784
    • Reward points : 0
    • Joined: 2007/10/15 00:51:49
    • Location: Germany
    • Status: offline
    Re: still on 16f18877, can't enter interrupt 2018/11/08 05:13:51 (permalink)
    +1 (1)
    What do you mean with "seem never entered"?
    Don't you use your PICkit as a debugger to see exactly whats going on???

    Uffbasse !
    #2
    pcbbc
    Super Member
    • Total Posts : 459
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: online
    Re: still on 16f18877, can't enter interrupt 2018/11/08 05:19:35 (permalink)
    +1 (1)
    My PIC assembly is fairly rusty, but where is your reset vector initialisation:
        org    0x00
        goto    start
    Seems without this that all bar your first two initialisation instructions will be overwritten by your ISR at 0x0004.
     
    And why does the interrupt routine call square, and then when the square routine returns, why does it tail call square again, and why does in not end with a RETFIE instruction, restore status, etc?
     
    I cannot see how this code was ever functional on 16f877, unless you have severely mutilated it during porting, or posting it here.
    #3
    __angelo__
    Starting Member
    • Total Posts : 56
    • Reward points : 0
    • Joined: 2010/12/02 02:39:25
    • Location: 0
    • Status: online
    Re: still on 16f18877, can't enter interrupt 2018/11/08 07:59:40 (permalink)
    0
    Hi,
    the code was truncated without returning from interrupt, just to generate a square wave, continuously.
     
    I solved it.
    Reason was a missing
     
        movlw    2
        banksel    T2CLKCON
        movwf    T2CLKCON
     
    in the timer setup ...  T2CLKCON is in fact not existing in 16f877.
     
    thanks and regards,
    angelo

    o/ Angelo
     
    #4
    qhb
    Superb Member
    • Total Posts : 7543
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: still on 16f18877, can't enter interrupt 2018/11/08 12:13:16 (permalink)
    +2 (2)
    Also note, you do NOT need the "context save" and "context restore" code in the ISR any more.
    (i.e. saving W and STATUS to temporary variables)
    PIC16F1xxx chips now do that for you in hardware.
    #5
    jack@kksound
    code tags!
    • Total Posts : 2842
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: still on 16f18877, can't enter interrupt 2018/11/08 12:16:19 (permalink)
    +1 (1)
    To the OP: Section 7.5 Automatic Context Saving of the datasheet discusses this in detail.
    #6
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2745
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: online
    Re: still on 16f18877, can't enter interrupt 2018/11/08 15:27:48 (permalink)
    0
    goto    sqloop
    Looks like an infinate loop.
     
    There should be a return from interrupt instruction at the end. RETFIE[/code]

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #7
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2745
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: online
    Re: still on 16f18877, can't enter interrupt 2018/11/08 15:36:06 (permalink)
    0
    You should have said that from the beginning.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #8
    mpgmike
    Starting Member
    • Total Posts : 36
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: offline
    Re: still on 16f18877, can't enter interrupt 2018/11/08 16:13:06 (permalink)
    0
    Should we assume you got the issue under control now?
    #9
    __angelo__
    Starting Member
    • Total Posts : 56
    • Reward points : 0
    • Joined: 2010/12/02 02:39:25
    • Location: 0
    • Status: online
    Re: still on 16f18877, can't enter interrupt 2018/11/10 11:55:33 (permalink)
    0
    Yes thank, i was looping in an infinite square wave.
    All solved, as reported.
    And thanks for the context save info !

    o/ Angelo
     
    #10
    Jump to:
    © 2018 APG vNext Commercial Version 4.5