Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Timer Arduino伺服库冲突_Timer_Arduino_Avr - Fatal编程技术网

Timer Arduino伺服库冲突

Timer Arduino伺服库冲突,timer,arduino,avr,Timer,Arduino,Avr,在我的代码中,我只使用液晶库和伺服库。当我试图编译代码时,出现以下错误 Servo/Servo.cpp.o: In function `Servo::attached()': /usr/share/arduino/libraries/Servo/Servo.cpp:336: multiple definition of `__vector_42' robot_v2.cpp.o:/usr/share/arduino/robot_v2.ino:662: first defined here /usr

在我的代码中,我只使用液晶库和伺服库。当我试图编译代码时,出现以下错误

Servo/Servo.cpp.o: In function `Servo::attached()':
/usr/share/arduino/libraries/Servo/Servo.cpp:336: multiple definition of `__vector_42'
robot_v2.cpp.o:/usr/share/arduino/robot_v2.ino:662: first defined here
/usr/lib/gcc/avr/5.4.0/../../../avr/bin/ld: Disabling relaxation: it will not work with multiple definitions
Servo/Servo.cpp.o: In function `Servo::attached()':
/usr/share/arduino/libraries/Servo/Servo.cpp:336: multiple definition of `__vector_47'
robot_v2.cpp.o:/usr/share/arduino/robot_v2.ino:662: first defined here
collect2: error: ld returned 1 exit status
除了上面提到的库之外,我还使用一个16位计时器,如下所示

DDRC |= B01010101;
......
cli();

TCCR4A = 0;
TCCR4B = 0;
TCCR5A = 0;
TCCR5B = 0;

OCR4A = l_target;
OCR5A = l_target;

TCCR4B = _BV(WGM42) | _BV(CS41);
TCCR5B = _BV(WGM52) | _BV(CS51);

TIMSK4 |= (1 << OCIE4A);
TIMSK5 |= (1 << OCIE5A);

sei();

我从伺服库中找到了相关代码。根据这一点,它使用1、3、4和5个计时器。因此,我不能将它们用于任何其他目的。我将不得不使用定时器2或任何其他解决方案。我回答我自己的问题,作为任何其他面临类似情况的人的参考

// Say which 16 bit timers can be used and in what order
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define _useTimer5
#define _useTimer1
#define _useTimer3
#define _useTimer4

伺服库仅在需要时分配计时器。每个定时器最多支持12个伺服,因此在Mega上,1到12个伺服使用定时器5,13到24个也将使用定时器1等等。分配顺序在文件ServoTimers.h中定义如下:timer5、timer1、timer3、timer4


假设您使用的伺服系统不超过24个,则计时器3和4可用。如果将对计时器5 TCCR5x、OCR5x、TIMSK5的所有引用更改为对计时器3 TCCR3x、OCR3x、TIMSK3的所有引用,则不应存在冲突。

我认为,关于ISR,您是否可以检查代码是否未定义两次ISR?由编译器指向的就地搜索:@我已经添加了代码。请检查我是否做错了什么。伺服库是否使用计时器4和5?如果是,解决办法是什么?@shan您是否尝试将timer5更改为timer3?
// Say which 16 bit timers can be used and in what order
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define _useTimer5
#define _useTimer1
#define _useTimer3
#define _useTimer4