timer and external interrupts together

Hello
there are many tutorials for timer interrupts and many for external interrupts, but both together? I want to use the QuadratureEncoder library, which in turn includes EnableInterrupt.h. And additionalh a timer0 overflow interrupt. But both collide, can someone confirm that or show me that it works?

Best regards
Pi

PiriRoter:
Hello
there are many tutorials for timer interrupts and many for external interrupts, but both together? I want to use the QuadratureEncoder library, which in turn includes EnableInterrupt.h. And additionalh a timer0 overflow interrupt. But both collide, can someone confirm that or show me that it works?

Best regards
Pi

Which Arduino are you using? What do you mean by "collide"? Timer0 is used for the timer functions, like delay(), millis(), and micros(). If you change timer0 registers, this will affect the Arduino timer functions.

There is no conflict AFAIK. The Timer0 overflow interrupt is used by micros. If you have tried to write a Timer0 overflow interrupt vector in your sketch you will see a multiple definition of `__vector_16' error.

first of all, thanks for your reply

ToddL1962:
Which Arduino are you using? What do you mean by “collide”?

I want to connect a quadrature encoder to an Arduino Mega 2560 and display its position and speed of rotation. And trigger switching processes depending on the angle of rotation. For this purpose, I included the QuadratureEncoder library at the beginning, which also works ALONE (uses int pins 2,3). But it doesn’t evaluate the Z signal, for that I need the ext interrupt of another pin. And additionally a timer interrupt for the time base, or millis …

ToddL1962:
Timer0 is used for the timer functions, like delay(), millis(), and micros(). If you change timer0 registers, this will affect the Arduino timer functions.

my code so far:

#include <QuadratureEncoder.h>          // must also have enableInterrupt.h library


int pin = 5;
volatile int state = LOW;
volatile int timerRPM = 0;


void setup()
{
    pinMode(pin, OUTPUT);
    attachInterrupt(digitalPinToInterrupt(2), blink, CHANGE);

    TCCR0A=(1<<WGM01);                  //Set the CTC mode, millis() funzt dann nicht mehr!
    OCR0A=0xF9;                         //Value for ORC0A for 1ms
    TIMSK0|=(1<<OCIE0A);                //Set the interrupt request
    TCCR0B|=(1<<CS01);                  //Set the prescale 1/64 clock
    TCCR0B|=(1<<CS00);
    sei();
}

void loop()
{
  digitalWrite(pin, state);

  // read and afterwards reset timerRPM here
}

void blink()
{
  state = !state;
}


SIGNAL(TIMER0_COMPA_vect){               //timer ISR
  timerRPM++;
}

and the compiler says:

Arduino: 1.8.13 (Linux), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

WInterrupts.c.o (symbol from plugin): In function `attachInterrupt':
(.text+0x0): multiple definition of `__vector_1'
libraries/QuadratureEncoder/QuadratureEncoder.cpp.o (symbol from plugin):(.text+0x0): first defined here
WInterrupts.c.o (symbol from plugin): In function `attachInterrupt':
(.text+0x0): multiple definition of `__vector_2'
libraries/QuadratureEncoder/QuadratureEncoder.cpp.o (symbol from plugin):(.text+0x0): first defined here
WInterrupts.c.o (symbol from plugin): In function `attachInterrupt':
(.text+0x0): multiple definition of `__vector_3'
libraries/QuadratureEncoder/QuadratureEncoder.cpp.o (symbol from plugin):(.text+0x0): first defined here
WInterrupts.c.o (symbol from plugin): In function `attachInterrupt':
(.text+0x0): multiple definition of `__vector_4'
libraries/QuadratureEncoder/QuadratureEncoder.cpp.o (symbol from plugin):(.text+0x0): first defined here
WInterrupts.c.o (symbol from plugin): In function `attachInterrupt':
(.text+0x0): multiple definition of `__vector_5'
libraries/QuadratureEncoder/QuadratureEncoder.cpp.o (symbol from plugin):(.text+0x0): first defined here
WInterrupts.c.o (symbol from plugin): In function `attachInterrupt':
(.text+0x0): multiple definition of `__vector_6'
libraries/QuadratureEncoder/QuadratureEncoder.cpp.o (symbol from plugin):(.text+0x0): first defined here
WInterrupts.c.o (symbol from plugin): In function `attachInterrupt':
(.text+0x0): multiple definition of `__vector_7'
libraries/QuadratureEncoder/QuadratureEncoder.cpp.o (symbol from plugin):(.text+0x0): first defined here
WInterrupts.c.o (symbol from plugin): In function `attachInterrupt':
(.text+0x0): multiple definition of `__vector_8'
libraries/QuadratureEncoder/QuadratureEncoder.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
exit status 1
Fehler beim Kompilieren für das Board Arduino Mega or Mega 2560.

Maybe you need to abandon the QuadratureEncoder library and just write your own code for everything?

...R

not the best solution, but it looks like it
but actually is the approach of the Arduino functionality to be packed in libraries so that it can then be easily used / combined?