Menu

#100 Timer0 interrupt

None
closed
nobody
None
7
2022-04-15
2015-12-01
Diego
No

I am trying to use timer0 of a PIC18F97J60 Microcontroller. When the timer overflows I want to start an interrupt service routine. However, the routine I made is never called. I think it has to do with the interrupt number I used. I am using interrupt 1, but I guess it should be interrupt 0. However, if I use interrupt 0, I get following compile error:

**sdcc -mpic16 -p18f97j60 -L/usr/local/lib/pic16 -llibio18f97j60.lib -llibdev18f97j60.lib -llibc18f.a Objects/clock_freq_test.o Objects/LCDBlocking.o

**message: Using default linker script "/usr/local/share/gputils/lkr/18f97j60_g.lkr".

error: More absolute sections use same address: 0 -- "S_clock_freq_test_ivec_0x0_high_isr/ivec_0x0_high_isr", "S_crt0i_entry/entry"
**

So I basically have 2 questions:

  1. Do I need to use interrupt 0 for timer0 overflow interrupt ?
  2. If I do need to use interrupt 0, why am I getting this compile error when I use it and how can I solve it ? Is it maybe caused by the way I installed SDCC ? I first installend the newest version, but because this version didn't support type "long long", I installed an older SDCC version provided by my professor with also extra files to support this type. So I actually installed both and didn't remove the latest SDCC version. Do I have to remove it ? And if so, how can I do this ?

By the way, this is the important part of my code that I am trying to fix:

void high_isr (void) interrupt 0
{
LED1_IO = 0;
INTCONbits.T0IE = 0; //disable interrupt

if(INTCONbits.T0IF)
{
  LED2_IO ^= 1; //change state of red leds;
  INTCONbits.T0IF = 0;

  TMR0H = 0x00; //HIGH (0x10000-EXEC_FREQ/1000);
  TMR0L = 0x00; //LOW  (0x10000-EXEC_FREQ/1000);
  T0CONbits.TMR0ON = 0;  //disable timer0
  INTCONbits.T0IF = 0;
  INTCONbits.T0IE  = 1; //enable interrupt
  T0CONbits.TMR0ON = 1;  //enable timer0 
}

}

void main(void)
{
LED1_IO = 1;
LED2_IO = 0;
LED1_TRIS = 0; //configure 2nd led pin as output (red)
LED2_TRIS = 0; //configure 3rd led pin as output (red)

/* Timer 0 */
RCONbits.IPEN      = 1;

TMR0H = 0x00;
TMR0L = 0x00; 
T0CONbits.TMR0ON = 0;  //disable timer0
T0CONbits.T08BIT = 0;  //use timer0 16-bit counter
T0CONbits.T0CS   = 0;  //use timer0 instruction cycle clock
T0CONbits.PSA    = 1;  //disable timer0 prescaler
INTCONbits.T0IF  = 0;  //clear timer0 overflow bit
INTCONbits.T0IE  = 1; //enable interrupt
INTCON2bits.TMR0IP = 1; // set timer0 high priority
T0CONbits.TMR0ON = 1;  //enable timer0

while(1)
{ }

}

Related

Support Requests: #100

Discussion

  • Diego Herranz

    Diego Herranz - 2015-12-01

    Have a look at section "4.6.18.3 Signals" of the manual (
    http://sdcc.sourceforge.net/doc/sdccman.pdf). Theres a signal.h header to
    deal with interrupts.

    Cheers,
    Diego

    On 1 December 2015 at 22:38, Diego sdiegocc@users.sf.net wrote:


    Status: open
    Group:
    Created: Tue Dec 01, 2015 10:38 PM UTC by Diego
    Last Updated: Tue Dec 01, 2015 10:38 PM UTC
    Owner: nobody

    I am trying to use timer0 of a PIC18F97J60 Microcontroller. When the timer
    overflows I want to start an interrupt service routine. However, the
    routine I made is never called. I think it has to do with the interrupt
    number I used. I am using interrupt 1, but I guess it should be interrupt
    0. However, if I use interrupt 0, I get following compile error:

    **sdcc -mpic16 -p18f97j60 -L/usr/local/lib/pic16 -llibio18f97j60.lib
    -llibdev18f97j60.lib -llibc18f.a Objects/clock_freq_test.o
    Objects/LCDBlocking.o

    **message: Using default linker script
    "/usr/local/share/gputils/lkr/18f97j60_g.lkr".

    error: More absolute sections use same address: 0 --
    "S_clock_freq_test_ivec_0x0_high_isr/ivec_0x0_high_isr",
    "S_crt0i_entry/entry"

    **

    So I basically have 2 questions:

    1. Do I need to use interrupt 0 for timer0 overflow interrupt ?
    2. If I do need to use interrupt 0, why am I getting this compile
      error when I use it and how can I solve it ? Is it maybe caused by the way
      I installed SDCC ? I first installend the newest version, but because this
      version didn't support type "long long", I installed an older SDCC version
      provided by my professor with also extra files to support this type. So I
      actually installed both and didn't remove the latest SDCC version. Do I
      have to remove it ? And if so, how can I do this ?

    By the way, this is the important part of my code that I am trying to fix:

    void high_isr (void) interrupt 0
    {
    LED1_IO = 0;
    INTCONbits.T0IE = 0; //disable interrupt

    if(INTCONbits.T0IF)
    {
    LED2_IO ^= 1; //change state of red leds;
    INTCONbits.T0IF = 0;

    TMR0H = 0x00; //HIGH (0x10000-EXEC_FREQ/1000);
    TMR0L = 0x00; //LOW (0x10000-EXEC_FREQ/1000);
    T0CONbits.TMR0ON = 0; //disable timer0
    INTCONbits.T0IF = 0;
    INTCONbits.T0IE = 1; //enable interrupt
    T0CONbits.TMR0ON = 1; //enable timer0
    }

    }

    void main(void)
    {
    LED1_IO = 1;
    LED2_IO = 0;
    LED1_TRIS = 0; //configure 2nd led pin as output (red)
    LED2_TRIS = 0; //configure 3rd led pin as output (red)

    / Timer 0 /
    RCONbits.IPEN = 1;

    TMR0H = 0x00;
    TMR0L = 0x00;
    T0CONbits.TMR0ON = 0; //disable timer0
    T0CONbits.T08BIT = 0; //use timer0 16-bit counter
    T0CONbits.T0CS = 0; //use timer0 instruction cycle clock
    T0CONbits.PSA = 1; //disable timer0 prescaler
    INTCONbits.T0IF = 0; //clear timer0 overflow bit
    INTCONbits.T0IE = 1; //enable interrupt
    INTCON2bits.TMR0IP = 1; // set timer0 high priority
    T0CONbits.TMR0ON = 1; //enable timer0
    while(1){ }

    }

    Sent from sourceforge.net because you indicated interest in
    https://sourceforge.net/p/sdcc/support-requests/100/

    To unsubscribe from further messages, please visit
    https://sourceforge.net/auth/subscriptions/

     

    Related

    Support Requests: #100

  • Diego

    Diego - 2015-12-02

    Diego,

    Thanks for the Guide of SDCC. Very useful.

    However, it didn't solve my problem. Luckily I could ask today to the professor what was wrong. The error code has to do with the fact that I wrote an interrupt routine for interrupt 0, but somewhere else in the code (I couldn't detect where) there was already an interrupt routine defined for interrupt 0. That's what the "same adress" in the error message means. So I can't write an ISR for interrupt 0.

    Anyway, the correct interrupt is interrupt 1. It didn't work in my case because I forgot to enable a bit:

    INTCONbits.GIE = 1. // Enable high priority interrupts.

    Now it works. Also, don't forget to set timer0 to high priority in order to get an high priority interrupt when Timer0 overflows.

    I just add the explanation for people that in future might run against the same problem. I have searched on google for this error message but I couldn't find any reference. So I guess it is usefull for people that in future run against the same error message.

     

    Last edit: Diego 2015-12-02
  • Diego Herranz

    Diego Herranz - 2015-12-02

    0 is for reset vector, 1 for high priority interrupts and 2 for low priority interrupts.

    FYI, the interrupt 0 you mention somewhere else in the code, is used on the crt0 code which is run before anything else and that's why it's located on the reset vector:
    https://sourceforge.net/p/sdcc/code/HEAD/tree/trunk/sdcc/device/lib/pic16/startup/crt0iz.c#l67

     
  • Benedikt Freisen

    • status: open --> closed
    • Group: -->
     

Log in to post a comment.