Go Down

Topic: c:49: multiple definition of `__vector_23' (Read 84 times) previous topic - next topic

benzijn

Hi,
I get this error when i try to compile this program:

Code: [Select]

/*
  study of output of timer2
 timer2 set up as phase and freq correct wave pwm 
 i want to see if changing OCR2B changes the frequency or pulse width.
 My guess is the latter.
 When pulse width, OCR2B is set > 0 two compare matches are made and frequency of the 
 call to interrupt vector is COMPB is 61 hz. if TOIE2 is used the frequency is halved
 to  30 hz. it is also halved if OCR2B is set to 0.
 Changing OCR2B affects the pulse width. top is always FF or 255(not see note. 
 Had WGM22 bit set in the wrong register!!
 */

volatile uint8_t  elx = 100, ars = 0;

void setup() {
   // initialize digital pins 10(Com2a1), 6 as an output.
  pinMode(4, OUTPUT);
  pinMode(6, OUTPUT);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);

  TCCR0A = (1<<COM0B1) | (1<<WGM00); 
  TCCR2B = (1<<WGM02) | (1<<CS02) | (1<<CS01) | (1<<CS00);      //full wave 1/1024th of 16 mHz.
  TIMSK0 = (1<<TOIE0);   // allow the timer0 to throw an an interrupt
  OCR0A = 125;            // set so that one cycle is 1 ms.
  OCR0B = 60;               // changes pulse width
  interrupts ();
}

ISR(TIMER0_OVF_vect) {
// increment the time.
if(elx > 0) elx--;   // calc delay sequence.
}

void loop() {
  while(elx > 10) {
    Serial.println(elx);
  }
  // toggle output to pin 6
  ars ^= 1;
  digitalWrite(6, ars);   // turn the LED according to state of ars
  elx = 100;
}

the entire error message is

Arduino: 1.6.4 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\BenzigJN\AppData\Local\Temp\build8183585045145922005.tmp/core.a(wiring.c.o): In function `__vector_23':
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/wiring.c:49: multiple definition of `__vector_23'
timer0_jun06cb.cpp.o:C:\Program Files (x86)\Arduino/timer0_jun06cb.ino:30: first defined here
c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
collect2.exe: error: ld returned 1 exit status
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

Only does this on Timer0 but not for Timer2. I've read other posts with the similar error and it looks like a bug in the build of this board. Any suggestions to flash a newer version of bootloader?
Timer0 works fine with OCIE0A and COMPA. - Thanks, j

Tom Carpenter

#1
Jun 07, 2015, 10:09 pm Last Edit: Jun 07, 2015, 10:14 pm by Tom Carpenter
Code: [Select]
ISR(TIMER0_OVF_vect)

This is already being used by millis() in wiring.c and so by adding it to your code you are declaring the routine for that vector a second time which is not allowed.

In case you are wondering how I knew that was __vector_23, look at page 101 of the atmega2560 datasheet and you will see all of the interrupt vector names and there number. Subtract 1 from the number in the datasheet and you get the avr-libc __vector_n index (the -1 is because avr-libc uses zero indexing of the vectors whilst the datasheet uses one indexing).




On top of that, your code seems to be about timer 2, but all but one of the registers and bit defines you are changing are related to timer 0.

TCCR0A is timer 0. TCCR2A would be timer 2.
COM0B1 is timer 0. COM2B1 would be timer 2.
and so on...

Timer 0 is used for millis, so if you are planning on using the Arduino core, don't use Timer 0.
~Tom~

Nick Gammon

Code: [Select]

// increment the time.
if(elx > 0) elx--;   // calc delay sequence.


How does subtracting one increment the time?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up