Hi
I am using servo.h and FreqCount.h libraries.
What i want is to measure a frequency signal on pin 47 of arduino mega and also generate PWM signal for my ESC from PIN 9 of my arduino mega. The problem i am facing is when i both libraries together the PWM out on PIN9 is somehow disabled. what i am guessing is the servo and freqcount library are using the same timer. i need help regarding this issue.
Please post a link to the FreqCount library you are using.
Conflicts over 16 bit Timer1 are common. If that is the case here, you could use the servoTimer2 library, or modify the FreqCount library to use a different 16 bit timer on the Mega.
http://www.pjrc.com/teensy/td_libs_FreqCount.html
i am using this library.
currently, i am using PIN 9 on arduino mega and PIn46 for freqcount. if i am to use servoTImer2 library which PIN should i use?
According to the FreqCount documentation, you should be using pin 47 on the Mega, and pin 9 should still work for PWM.
You can attach any other pin to a servo, when using the servo libraries, but with servo.h, that will disable pins 9 and 10 for use with analogWrite().
I tried using PIN47. The problem is when i initialize FreqCount.begin(2000) my servo PWM becomes disable. I am not able to send PWM to my esc. Below is part of my code.
void setup() {
Serial.begin(19200);
Serial1.begin(19200);
Serial2.begin(19200);
Serial3.begin(19200);
thr.begin(A1, A0); // Initialize Thrust Load Cell
tor.begin(A3, A2); // Initialize Torque Load Cell
ESC.attach(9);
pinMode(3, INPUT);
pinMode(47, INPUT);
// digitalWrite(53, HIGH);
FreqCount.begin(2000);
//startTime = millis();
}
void loop() {
ESC_upper_motor(); // Serial 1
thrust_torque();
Serial_PWM();
Serial_print();
ESC.writeMicroseconds(Mapped_ESC_throttle);
//Serial.println(Mapped_ESC_throttle);
}
void Serial_PWM() {
if (Serial3.available()) {
throttle = Serial3.read();
Mapped_ESC_throttle = map(throttle, 0, 100, 1100, 1940);
}
}
Of course it does. The servo library documentation makes that clear. Assign some other pin to the servo.
I have also tried using servoTimer2 library but It does not support writemicrseconds(). servotimer2.write(int Pulsewidth) is used for PWM. However i want to scale or calibrate my different ESC using writemicrseconds(). what do you suggest?
I tried using PIN 2 and 3 but the problem was still there.
Sorry, I misread the FreqCount library description. It does say that pin 9 (Timer1) becomes unusable.
The servoTimer2 library claims to support servo.write(x);
where x is in microseconds.
It would not be difficult to modify the FreqCount library to use one of the other 16 bit timers on the Mega (3, 4 and 5).
Thanks. I will try servoTimer2 library.
I tried Servotimer2 and it seems to work fine. i forgot to reply on forum.
Thanks.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.