Hi everyone,
I am counting frequency with this library: (FreqCount Library, for Measuring Frequencies in the 1 kHz to 5 MHz Range). I have a serious problem when I want to use servo motor. Do you have some ideas ? Thank you a lot.
This is my basic code:
#include <FreqCount.h>
#include <Servo.h>
Servo myservo;
int pos = 0;
unsigned long count;
void setup() {
Serial.begin(57600);
FreqCount.begin(1000);
myservo.attach(9); //when I initialized attach.(); freq counting will crash
}
void loop() {
if (FreqCount.available()) {
count = FreqCount.read();
Serial.println(count);
}
if(count > 230000){
FreqCount.end();
for(pos = 0; pos <= 90; pos += 1)
myservo.write(pos);
delay(10);
}
for(pos = 90; pos >= 0; pos -= 1)
{
myservo.write(pos);
delay(10);
}
}
}
My first idea is to put your code into code tags. My next idea is to ask the question of what is your serious problem when you use a servo? My third question is that this guy did not follow the sites posted instructions will he be able to follow the instructions of the people who may lend-to?
What device are you running this on? There are limitations on what other pins can be used when FreqCount is included as described on the webpage for that library. My guess is the two libraries have a timer conflict.
Steve
slipstick:
What device are you running this on? There are limitations on what other pins can be used when FreqCount is included as described on the webpage for that library. My guess is the two libraries have a timer conflict.
Steve
I am using Arduino UNO. I think you are right about that timer conflict. But is there any chance to do it ?
You could try using ServoTimer2.h instead of Servo.h. Note you'll need to change the servo commands because ServoTimer2 write() takes microseconds e.g. 1000-2000 as the parameter not the angle (0-180) that Servo write() uses.
Steve
Hi Ludwig118. I've the same problem. I'm using an Arduino Mega. And in concordance with the page were I take the library, the limitations for my device are the pins 9, 10, 44, 45, 46 . I´ve tried to use other pins but the problem continue. Did you find a solution about it'?