Hello, I'm trying to design an audio down converter for a project. I'm getting an error message that it will not compile for the board (compile, not upload). I read that FreqCount can affect other PWM pins, but I wasn't expecting them to be unusable and I don't know how to trouble shoot this. The line that's giving my problems is the tone function. I think it's trying to say that there's an error with the timer and the tone function interrupting it.
#include <FreqCount.h>
void setup() {
Serial.begin(57600);
}
void loop() {
// put your main code here, to run repeatedly:
FreqCount.begin(1000);
long freq = 0.0;
if(FreqCount.available())
{
long freq = FreqCount.read();
Serial.print("Frequency: ");
Serial.println(freq);
FreqCount.end();
}
FreqCount.end();
long pitch = map(freq, 10000, 20000, 100, 1000);
Serial.print("New Pitch: ");
Serial.println(pitch);
tone(1, pitch, 10);
}
Here is the error message:
Tone.cpp.o (symbol from plugin): In function timer0_pin_port': (.text+0x0): multiple definition of __vector_7'
libraries/FreqCount-1.3.0/FreqCount.cpp.o (symbol from plugin): (.text+0x0): first defined here
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.
Yes, it looks like there is a conflict between the tone() library and FreqCount library. You might be able to modify one of the libraries but there may be more than one conflict, so if you were to fix that one another might 'pop-up'. Or, there could be a hardware conflict (both using the same timers/registers, etc.).
You might have to write your own tone or frequency function(s) or write your own libraries. That would probably involve using the chip's internal registers/timers, etc., and it would probably require assembly language (depending on the speed/frequency).
It's hard to know if it will can work at all since both things are timing-critical and everything has to be done by a shared processor... Doing two or more timing-critical things at once can get tricky.
There are frequency divider chips/circuits that don't require programming software, if that kind of thing will work in your application.
If you want to write your own code, you can adopt the Timer1 external clock source counting methods of freqCount.h but gate the count with a software timer, and then Timer2 will be free for tone().
You can try migrate to a Leonardo which uses the 32U4 instead of the AT328. Tone() uses Timer3, and freqCount uses Timer1 and Timer4.