16F1827 interrupt hosed


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: 16F1827 interrupt hosed

    Very strange...I did what you suggested but it only prolonged the end result. I am seeing two things when the interrupt crashes....either it hoses the main loop and the interrupt oscillates at a high frequency of 235 Khz or it completely stops and main keeps going with its toggle. This is what I added to the ISR.

    Code:
    asm
    ; Save W, STATUS and PCLATH registers, if not done previously
    myint   
            ; retfie auto-restores w, status, bsr, fsr and pclath
      
      bcf   BSR,0
      bcf   T1CON,TMR1ON ; stop timer 1
      bcf   PIR1,TMR1IF  ; clear over flow flag
      movlw 0xEF         ; load timer for 16,535 * 2 prescaler interrupt on 16 bit timer
      movwf TMR1H        ; load high byte
      movlw 0xEF         
      movwf TMR1L        ; load low byte
      bsf   T1CON,TMR1ON ; re-enable timer 1
      movlw 0x02
      xorwf PORTB,f      ; toggle RB1
      retfie             ; Return from interrupt
            
    endasm

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: 16F1827 interrupt hosed

    Try bsr=0. There maybe more bank select bit then just 1.Like this:
    Code:
    Myint
    Bsr=0
    asm
    Rest of isr
    OR
    Code:
    myint
    asm
    clrf bsr
    rest of isr
    Last edited by cncmachineguy; - 18th October 2011 at 05:43.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: 16F1827 interrupt hosed

    here is what I think is happening:
    When the INT is called, the state of the BSR is unknown. If the main program is doing something that requires bsr to be other then 0, when you enter the ISR you can't manipulate the things in the ISR because the wrong bank is selected.

    When you added the BCF BSR,0 - This almost fixed it but not quite. When it stays in the ISR that is because you can't clear the flag (acting on wrong reg, NOT PIR) so the INT just fires forever. My guess is when you think the main is running without INT, that may be not true, it may be that you just aren't toggling the output so you think the ISR has not fired.

    The easiest way I know of to troubleshoot this is using MPLAB SIM inside of MPLAB. put a breakpoint at the first line of the ISR, then when it fires you can single step through while watching reg's like port b and even better BSR!
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: 16F1827 interrupt hosed

    Thanks for your help! I will try your suggestion. I did notice one thing before leaving the office last night, when I remove the ADC from main everything works well. When I rerun the test using ADC enabled it screws things up. Do I need to also do something with T1CON like select a bank of memory that it can write to that is common across banks? some how I think writing to values to the timer is somehow not being read out of the correct bank at some point after the interrupt is enabled upon exit....just my guess.

    Nick

  5. #5
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: 16F1827 interrupt hosed

    BSR will be restored when you exit the ISR. That chip auto saves and restores W,PC,Status, BSR, I think. So no need to worry about it from the Main point of view. I have not checked the banks you are using in the ISR, but I am thinking since it works sometimes they may be all in BANK 0. Could be the ADC is whats creating the NON bank 0 setting in the BSR.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: 16F1827 interrupt hosed

    Bert,

    Thanks for the help. I used your suggestion in conjunction with BANKSEL T1CON at the start of the ISR after the ASM tag. It all works now!!!

    Nick

  7. #7
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: 16F1827 interrupt hosed

    do you understand why? sounds like you do. BTW DT_INT takes care of BSR for you I think. I am being pushed towards using them and prolly will end up there. Just an FYI.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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