Priority Interrupt settings PIC18F4550, running three timers

Discussion in 'Embedded Systems and Microcontrollers' started by Vindhyachal Takniki, Apr 29, 2016.

  1. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    349
    6
    I am using PIC18F4550 with MPBALX IDE V2.26, Xc8 V1.32.

    I have to run three timers. I am using three timers. I have kept osc freq = 4Mhz, so that all timers have clock of 1Mhz.
    Timer0: Used for delay loops, one shot. Delay produced: 500us,1000us,10ms,50ms
    Timer1: General purpose timer. Run continuously, generate 10ms interrupts.
    Timer3: Generate configurable interrupt. Timer value varies from 50us-62500us.


    Timer3 is highest priority interrupt. It runs only when it is required otherwise off. If any other timer interrupt is being serviced, then they should be interrupted by this higher priority interrupt.
    So Timer3 should me made higher priority & other timers should be at lower priority
    In PIC18F4550 how to configure two interrupts with higher & lower priority.
    I have tried this but it didn't work.( http://www.xargs.com/pic/c-faq.html#c18isr )

    Then I have tried this: http://microchip.wikidot.com/faq:31
    Configured timer0 interrupt to lower priority & if isr have keyword "low_priority", then control never goes in it. However if I remove this keyword then control goes into isr.

    Now how to configure code for higher priority for timer3. Haven't added timer3 in yet

    Code (Text):
    1.  
    2.  
    3. void interrupt isr(void)
    4. {
    5. /* wait timer isr */
    6.     if(INTCONbits.TMR0IF)
    7.     {
    8.     /* stop timer */
    9.         T0CONbits.TMR0ON = 0U;
    10.         INTCONbits.TMR0IF = 0U;
    11.        
    12.         g_wait_timer_flag = 1U;
    13.     }
    14.  
    15. /* general timer isr */
    16.     if(PIR1bits.TMR1IF)
    17.     {
    18.     /* stop, reload & restart timer */
    19.         T1CONbits.TMR1ON = 0U;
    20.         PIR1bits.TMR1IF = 0U;
    21.         TMR1H = GEN_TIM_TH0;
    22.         TMR1L = GEN_TIM_TL0;
    23.         T1CONbits.TMR1ON = 1U;
    24.    
    25.         LATBbits.LATB1 = !LATBbits.LATB1;
    26.     }
    27.  
    28. } /* isr ends here */
    29.  
    30.  
    31.  
    32. void initialize_wait_timer(void)
    33. {
    34. /* T0CON */
    35.     T0CONbits.TMR0ON = 0U;   /* stop timer */
    36.     T0CONbits.T08BIT = 0U;   /* 16 bit */
    37.     T0CONbits.T0CS = 0U;     /* internal clock */
    38.     T0CONbits.T0SE = 0U;
    39.     T0CONbits.PSA = 1U;      /* PSA bypass */
    40.     T0CONbits.T0PS = 0U;     /* /2 */
    41.  
    42. /* clear timer counts */
    43.     TMR0H = 0U;               /* clear timer register */
    44.     TMR0L = 0U;
    45.  
    46. /* int settins */
    47.     INTCONbits.TMR0IF = 0U;   /* clear overflow flag */
    48.     INTCONbits.TMR0IE = 1U;   /* enable int */
    49.     INTCON2bits.TMR0IP = 0U;  /* low priority */
    50.     INTCONbits.GIE_GIEH = 1U; /* enable global bit */
    51.     INTCONbits.PEIE_GIEL = 1U;
    52.        
    53. /* write TL & TH value */
    54.     TMR0H = 0xFE;
    55.     TMR0L = 0x0c;
    56.  
    57.     T0CONbits.TMR0ON = 1U;    
    58.    
    59.     while( 0U ==  g_wait_timer_flag );
    60.        
    61. } /* function ends here */
    62.  
    63.  
    64.  
    65.  
    66. void initialize_general_timer(void)
    67. {
    68. /* T1CON */
    69.     T1CONbits.TMR1ON = 0U;   /* stop timer */
    70.     T1CONbits.RD16 = 1U;     /* one sixteen but write */
    71.     T1CONbits.T1RUN = 0U;
    72.     T1CONbits.T1CKPS = 0U;
    73.     T1CONbits.T1OSCEN = 0U;
    74.     T1CONbits.nT1SYNC = 1U;
    75.     T1CONbits.TMR1CS = 0U;
    76.    
    77. /* write tiemr counts */
    78.     TMR1H = GEN_TIM_TH0;
    79.     TMR1L = GEN_TIM_TL0;
    80.  
    81. /* int settins */
    82.     PIR1bits.TMR1IF = 0U;
    83.     PIE1bits.TMR1IE = 1U;
    84.     IPR1bits.TMR1IP = 0U;
    85.  
    86.     INTCONbits.GIE_GIEH = 1U; /* enable global bit */
    87.     INTCONbits.PEIE_GIEL = 1U;
    88.  
    89. /* start timer */
    90.     T1CONbits.TMR1ON = 1U;
    91.    
    92. } /* function ends here */
    93.  
    94.  
    95.  
    96.  
     
  2. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,908
    2,168
  3. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    349
    6
    tried this, even mentioned it in OP
     
  4. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,908
    2,168
    Yes, you did.:oops: Check to be sure the Priority interrupt enable flag (IPEN bit) is set for the chip you're using.
     
  5. dannyf

    Well-Known Member

    Sep 13, 2015
    1,809
    362
    Not sure what you meant by "higher priority".

    You can certainly process a given interrupt flag earlier in a non-vectored isr -> the chip will respond to that interrupt (slightly) faster.

    This particular chip can also process a two-priority interrupt request.

    Cannot help you without your telling us what you are trying to do.
     
  6. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    349
    6
    Thanks get it working
     
Loading...