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

    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

  2. #2
    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!

  3. #3


    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

  4. #4
    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!

  5. #5


    Did you find this post helpful? Yes | No

    Question Re: 16F1827 interrupt hosed

    I am seeing something strange.....It seems I can not read my ADC's or run anything in main when my interrupt is enabled. What my code is supposed to do is output a 1.5ms pulse every 16ms for "home" position on 4 servo's in the interrupt. At any time an ADC value on 5 ADC's is above a threshold I want to stop the interrupt and run the scaled up ADC values to run my servo's in real time. What am I missing?

    Code:
     
    ASM
        __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
        __config _CONFIG2, _PLLEN_OFF & _LVP_OFF & _LVP_OFF & _STVREN_OFF
            
    ENDASM
    DEFINE OSC 8  
        
     ;Define ADCIN parameters
     
      DEFINE ADC_BITS 8   ' Set number of bits in result
      DEFINE ADC_CLOCK 4   ' Set clock source, look on data sheet for chart
      DEFINE ADC_SAMPLEUS 500   ' Set sampling time in uS 
      
      DEFINE  INTHAND myint                   ' Setup interrupt handler
       
    ;*******************************************************************************
    ;*******************************************************************************
    ; System hardware configuration
    ;*******************************************************************************
    ;*******************************************************************************
            OSCCON = %01110000   ' bit.7 =32MHz internal
            ANSELA = %00000001   ' all digital. A/D disabled
            ANSELB = %00000000
            TRISB =  %00000000    ' set port directions 0 = output, 1 = input
            TRISA =  %00000001
            ADCON0 = %00000111  ' Set PORTA digital 1, analog 0
            ADCON1 = %01000000
             
            
    ;*******************************************************************************
    ; Program variables 
    ;*******************************************************************************
            ADCVAL      var     byte   bank0   
            ADCVAL2     var     byte   bank0  
            ADCVAL3     var     byte   bank0   
            ADCVAL4     var     byte   bank0   
            ADCVAL5     var     byte   bank0   
            
            
    ;*******************************************************************************        
    ; Program constants
    ;*******************************************************************************
            centM       con     1500        ;motor stop
            forM        con     2000        ;motor forward
            revM        con     1000        ;motor reverse
            
     
    
    ;******************************************************************************* 
    ; Power on initialization to known port states   
    ;*******************************************************************************
          
    PowerOn_init: 
            PortA = 0             ' force low to avoid glitches 
            POrtB = 0
            PIR1 = 0              ' clear TMR1 int flag
            PIE1 =   %00000001    ' TMR1 int enabled
            INTCON = %11000000    ' global & peripheral ints enabled
            T1CON =  %00010001    ' TMR1 1:2 prescale, timer1 on
    
    ;*******************************************************************************
    ;*******************************************************************************
     goto mainloop
    asm
    ; Save W, STATUS and PCLATH registers, if not done previously
    myint   
            ; retfie auto-restores w, status, bsr, fsr and pclath
      BANKSEL T1CON 
      clrf  BSR
      bcf   T1CON,TMR1ON ; stop timer 1
      bcf   PIR1,TMR1IF  ; clear over flow flag
      movlw 0xBF         ; load timer for 16,535 * 2 prescaler interrupt on 16 bit timer
      movwf TMR1H        ; load high byte
      movlw 0xFF         
      movwf TMR1L        ; load low byte
      
      call  _home
      
      bsf   T1CON,TMR1ON ; re-enable timer 1
     
    ;  movlw 0x02
    ;  xorwf PORTB,f      ; toggle RB1
      retfie             ; Return from interrupt
            
    endasm
    home:
         if adcval < 4 and adcval2 < 4 and adcval3 <4 and adcval4 < 4 and adcval5 < 4 then
         PORTB = %00001111
           pauseus 1500
         PORTB = %00000000
         endif
    return
        
     
    mainloop:
        call readADC  
        call spin
    '    call forward
    '    call back
    '    call left
    '    call right
        pause 15
        goto mainloop
    
     readADC: 
          adcin 0, adcval   
          ADCIN 1, adcval2
          adcin 2, adcval3
          adcin 3, adcval4
          adcin 4, adcval5
          return
          
          
     spin:
         if adcval > 4 then 
           LATB = %00001111
                pauseus 6*(adcval) + 900
           LATB = %00000000
         endif     
         return
         
                           
     forward: 
         if adcval2 > 4 then
           LATB = %00001100
                pauseus 6*(adcval) + 900
           LATB = %00000000
           LATB = %00000011
                pauseus 6*(adcval) + 900
           LATB = %00000000
         endif
         return
        
     back: 
         if adcval3 > 4 then
           LATB = %00000011
                pauseus 6*(adcval) + 900
           LATB = %00000000
           LATB = %00001100
                pauseus 6*(adcval) + 900
           LATB = %00000000
         endif
        return
        
     left:
         if adcval4 > 4 then
           LATB = %00000101
                pauseus 6*(adcval) + 900
           LATB = %00000000
           LATB = %00001100
                pauseus 6*(adcval) + 900
           LATB = %00001010
         endif
        return
     
     right:
        if adcval5 > 4 then
           LATB = %00001010
                pauseus 6*(adcval) + 900
           LATB = %00000000
           LATB = %00000101
                pauseus 6*(adcval) + 900
           LATB = %00001010
        endif
        return

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: 16F1827 interrupt hosed

    Try changing

    call readADC
    call spin

    to

    GOSUB readADC
    GOSUB spin

    From the manual:
    CALL
    CALL Label
    Execute the assembly language subroutine named Label.
    GOSUB is normally used to execute a PICBASIC PRO™ subroutine. The main difference between GOSUB and CALL is that with CALL, Label=s existence is not checked until assembly time. Using CALL, a Label in an assembly language section can be accessed that is otherwise inaccessible to PBP.
    See the section on assembly language programming for more information on CALL.

    CALL pass ' Execute assembly language subroutine named _pass
    Dave
    Always wear safety glasses while programming.

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: 16F1827 interrupt hosed

    Hello Dave,

    I changed the calls to subs and still nothing runs in main while the interrupt is enabled. I can't even get a simple portb.0 set / reset to give me anything on the I/O.

    Nick
    Last edited by Macgman2000; - 19th October 2011 at 19:41.

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